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_pex_sys_exit_prints_objects():
_test_sys_exit('Exception("derp")', to_bytes('derp\n'), 1)
def test_to_bytes():
assert isinstance(to_bytes(''), bytes)
assert isinstance(to_bytes('abc'), bytes)
assert isinstance(to_bytes(b'abc'), bytes)
assert isinstance(to_bytes(u'abc'), bytes)
assert isinstance(to_bytes(b'abc'.decode('latin-1'), encoding='utf-8'), bytes)
for bad_value in (123, None):
with pytest.raises(ValueError):
to_bytes(bad_value)
def write_source(path, valid=True):
with safe_open(path, 'wb') as fp:
fp.write(to_bytes('basename = %r\n' % os.path.basename(path)))
if not valid:
fp.write(to_bytes('invalid!\n'))
'--python={}'.format(py27_interpreter),
'--python={}'.format(py36_interpreter),
'-o', pex])
results.assert_success()
pex_program = [pex, '-c']
py2_only_program = pex_program + ['import functools32']
both_program = pex_program + [
'import jsonschema, os, sys; print(os.path.realpath(sys.executable))'
]
py27_env = make_env(PATH=os.path.dirname(py27_interpreter))
subprocess.check_call(py2_only_program, env=py27_env)
stdout = subprocess.check_output(both_program, env=py27_env)
assert to_bytes(os.path.realpath(py27_interpreter)) == stdout.strip()
py36_env = make_env(PATH=os.path.dirname(py36_interpreter))
with pytest.raises(subprocess.CalledProcessError):
subprocess.check_call(py2_only_program, env=py36_env)
stdout = subprocess.check_output(both_program, env=py36_env)
assert to_bytes(os.path.realpath(py36_interpreter)) == stdout.strip()
def test_clp_preamble_file():
with NamedTemporaryFile() as tmpfile:
tmpfile.write(to_bytes('print "foo!"'))
tmpfile.flush()
parser = configure_clp()
options, reqs = parser.parse_args(args=['--preamble-file', tmpfile.name])
assert options.preamble_file == tmpfile.name
pex_builder = build_pex(reqs, options)
assert pex_builder._preamble == 'print "foo!"'
def test_to_bytes():
assert isinstance(to_bytes(''), bytes)
assert isinstance(to_bytes('abc'), bytes)
assert isinstance(to_bytes(b'abc'), bytes)
assert isinstance(to_bytes(u'abc'), bytes)
assert isinstance(to_bytes(b'abc'.decode('latin-1'), encoding='utf-8'), bytes)
for bad_value in (123, None):
with pytest.raises(ValueError):
to_bytes(bad_value)
def convert(input):
if isinstance(input, dict):
out = dict()
for key, value in input.items():
out[convert(key)] = convert(value)
return out
elif isinstance(input, list):
return [convert(element) for element in input]
elif isinstance(input, string):
return to_bytes(input)
else:
return input
def convert(input):
if isinstance(input, dict):
out = dict()
for key, value in input.items():
out[convert(key)] = convert(value)
return out
elif isinstance(input, list):
return [convert(element) for element in input]
elif isinstance(input, string):
return to_bytes(input)
else:
return input
def convert(input):
if isinstance(input, dict):
out = dict()
for key, value in input.items():
out[convert(key)] = convert(value)
return out
elif isinstance(input, list):
return [convert(element) for element in input]
elif isinstance(input, string):
return to_bytes(input)
else:
return input