Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _test(input, expected_output, args=''):
with tempfile.NamedTemporaryFile('w') as finput:
# python2 needs additional utf8 encoding
if sys.version_info[0] == 2:
input = input.encode('utf8')
finput.write(input)
finput.seek(0)
with tempfile.NamedTemporaryFile('w+') as foutput:
opts = '{} -o {} {}'.format(finput.name, foutput.name, args)
sys.argv = ['foo'] + shlex.split(opts)
main.main()
output = foutput.read()
# python2 needs additional utf8 decoding
if sys.version_info[0] == 2:
output = output.decode('utf8')
if expected_output == '':
assert output == ''
else:
assert output == expected_output + '\n'
def test_help():
sys.argv = ['foo', '-h']
with pytest.raises(SystemExit):
main.main()
def test_version():
sys.argv = ['foo', '--version']
main.main()