Skip to content

Instantly share code, notes, and snippets.

@famousgarkin
Created April 12, 2016 20:32
Show Gist options
  • Save famousgarkin/d074809edc6c9551677bdc2da2a834cc to your computer and use it in GitHub Desktop.
Save famousgarkin/d074809edc6c9551677bdc2da2a834cc to your computer and use it in GitHub Desktop.
import os
def test_user_input(monkeypatch):
inputs = [10, 'y']
input_generator = (i for i in inputs)
monkeypatch.setattr('__builtin__.raw_input', lambda prompt: next(input_generator))
assert raw_input('how many?') == 10
assert raw_input('you sure?') == 'y'
def test_file_input(tmpdir):
fixture = tmpdir.join('fixture.txt')
fixture.write(os.linesep.join(['1', '2', '3']))
fixture_path = str(fixture.realpath())
with open(fixture_path) as f:
assert f.readline() == '1' + os.linesep
def test_environment_input(monkeypatch):
monkeypatch.setenv('STAGING', 1)
assert os.environ['STAGING'] == '1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment