diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2010-02-27 07:22:22 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2010-02-27 07:22:22 (GMT) |
commit | b6e8c7e8fb750e44b387557ad19afe2ccfe69f7c (patch) | |
tree | 25e5b445c8d511dc4c18f3c40196f69674577cdf /Lib/test/test_os.py | |
parent | 9a816974942a170a082bcef01a11aca806e854fe (diff) | |
download | cpython-b6e8c7e8fb750e44b387557ad19afe2ccfe69f7c.zip cpython-b6e8c7e8fb750e44b387557ad19afe2ccfe69f7c.tar.gz cpython-b6e8c7e8fb750e44b387557ad19afe2ccfe69f7c.tar.bz2 |
Add an os.get_exec_path() function to return the list of directories
that launching a subprocess will search for the executable.
Refactors some code in os._execvpe().
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r-- | Lib/test/test_os.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 1ff356c..9846d92 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -407,6 +407,27 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol): self.assertTrue(isinstance(env.data, dict)) self.assertEqual(repr(env), 'environ({!r})'.format(env.data)) + def test_get_exec_path(self): + defpath_list = os.defpath.split(os.pathsep) + test_path = ['/monty', '/python', '', '/flying/circus'] + test_env = {'PATH': os.pathsep.join(test_path)} + + saved_environ = os.environ + try: + os.environ = dict(test_env) + # Test that defaulting to os.environ works. + self.assertSequenceEqual(test_path, os.get_exec_path()) + self.assertSequenceEqual(test_path, os.get_exec_path(env=None)) + finally: + os.environ = saved_environ + + # No PATH environment variable + self.assertSequenceEqual(defpath_list, os.get_exec_path({})) + # Empty PATH environment variable + self.assertSequenceEqual(('',), os.get_exec_path({'PATH':''})) + # Supplied PATH environment variable + self.assertSequenceEqual(test_path, os.get_exec_path(test_env)) + class WalkTests(unittest.TestCase): """Tests for os.walk().""" |