Fix os.get_exec_path() (code and tests) for python -bb
Catch BytesWarning exceptions.
This commit is contained in:
parent
9802b39c12
commit
38430e2dff
|
@ -387,13 +387,13 @@ def get_exec_path(env=None):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
path_list = env.get('PATH')
|
path_list = env.get('PATH')
|
||||||
except TypeError:
|
except (TypeError, BytesWarning):
|
||||||
path_list = None
|
path_list = None
|
||||||
|
|
||||||
if supports_bytes_environ:
|
if supports_bytes_environ:
|
||||||
try:
|
try:
|
||||||
path_listb = env[b'PATH']
|
path_listb = env[b'PATH']
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError, BytesWarning):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if path_list is not None:
|
if path_list is not None:
|
||||||
|
|
|
@ -450,8 +450,12 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
|
||||||
|
|
||||||
if os.supports_bytes_environ:
|
if os.supports_bytes_environ:
|
||||||
# env cannot contain 'PATH' and b'PATH' keys
|
# env cannot contain 'PATH' and b'PATH' keys
|
||||||
self.assertRaises(ValueError,
|
try:
|
||||||
os.get_exec_path, {'PATH': '1', b'PATH': b'2'})
|
mixed_env = {'PATH': '1', b'PATH': b'2'}
|
||||||
|
except BytesWarning:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.assertRaises(ValueError, os.get_exec_path, mixed_env)
|
||||||
|
|
||||||
# bytes key and/or value
|
# bytes key and/or value
|
||||||
self.assertSequenceEqual(os.get_exec_path({b'PATH': b'abc'}),
|
self.assertSequenceEqual(os.get_exec_path({b'PATH': b'abc'}),
|
||||||
|
@ -723,6 +727,9 @@ class ExecTests(unittest.TestCase):
|
||||||
# os.get_exec_path() reads the 'PATH' variable
|
# os.get_exec_path() reads the 'PATH' variable
|
||||||
with _execvpe_mockup() as calls:
|
with _execvpe_mockup() as calls:
|
||||||
env_path = env.copy()
|
env_path = env.copy()
|
||||||
|
if test_type is bytes:
|
||||||
|
env_path[b'PATH'] = program_path
|
||||||
|
else:
|
||||||
env_path['PATH'] = program_path
|
env_path['PATH'] = program_path
|
||||||
self.assertRaises(OSError,
|
self.assertRaises(OSError,
|
||||||
os._execvpe, program, arguments, env=env_path)
|
os._execvpe, program, arguments, env=env_path)
|
||||||
|
|
Loading…
Reference in New Issue