]> granicus.if.org Git - python/commitdiff
Fix os.get_exec_path() (code and tests) for python -bb
authorVictor Stinner <victor.stinner@haypocalc.com>
Thu, 19 Aug 2010 17:10:18 +0000 (17:10 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Thu, 19 Aug 2010 17:10:18 +0000 (17:10 +0000)
Catch BytesWarning exceptions.

Lib/os.py
Lib/test/test_os.py

index 60dc12fcf2c222e2e23146423040caa9b9e9a0f1..02e8f14a1eb09d17fd35abb2ac352f8033d20552 100644 (file)
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -387,13 +387,13 @@ def get_exec_path(env=None):
 
     try:
         path_list = env.get('PATH')
-    except TypeError:
+    except (TypeError, BytesWarning):
         path_list = None
 
     if supports_bytes_environ:
         try:
             path_listb = env[b'PATH']
-        except (KeyError, TypeError):
+        except (KeyError, TypeError, BytesWarning):
             pass
         else:
             if path_list is not None:
index 4910b1e3a9885ea20f2325b6fc83b413a072a068..710a3f4e8edd7f4e599d4821776de2c72ea4ab1d 100644 (file)
@@ -450,8 +450,12 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
 
         if os.supports_bytes_environ:
             # env cannot contain 'PATH' and b'PATH' keys
-            self.assertRaises(ValueError,
-                os.get_exec_path, {'PATH': '1', b'PATH': b'2'})
+            try:
+                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
             self.assertSequenceEqual(os.get_exec_path({b'PATH': b'abc'}),
@@ -723,7 +727,10 @@ class ExecTests(unittest.TestCase):
         # os.get_exec_path() reads the 'PATH' variable
         with _execvpe_mockup() as calls:
             env_path = env.copy()
-            env_path['PATH'] = program_path
+            if test_type is bytes:
+                env_path[b'PATH'] = program_path
+            else:
+                env_path['PATH'] = program_path
             self.assertRaises(OSError,
                 os._execvpe, program, arguments, env=env_path)
             self.assertEqual(len(calls), 1)