Issue #8513: os.get_exec_path() supports b'PATH' key and bytes value.

subprocess.Popen() and os._execvpe() support bytes program name. Add
os.supports_bytes_environ flag: True if the native OS type of the environment
is bytes (eg. False on Windows).
This commit is contained in:
Victor Stinner 2010-05-18 17:17:23 +00:00
parent 04b5684d00
commit b745a74c99
6 changed files with 129 additions and 22 deletions

View file

@ -825,6 +825,27 @@ class POSIXProcessTestCase(BaseTestCase):
stdout = stdout.rstrip(b'\n\r')
self.assertEquals(stdout.decode('ascii'), repr(value))
def test_bytes_program(self):
abs_program = os.fsencode(sys.executable)
path, program = os.path.split(sys.executable)
program = os.fsencode(program)
# absolute bytes path
exitcode = subprocess.call([abs_program, "-c", "pass"])
self.assertEquals(exitcode, 0)
# bytes program, unicode PATH
env = os.environ.copy()
env["PATH"] = path
exitcode = subprocess.call([program, "-c", "pass"], env=env)
self.assertEquals(exitcode, 0)
# bytes program, bytes PATH
envb = os.environb.copy()
envb[b"PATH"] = os.fsencode(path)
exitcode = subprocess.call([program, "-c", "pass"], env=envb)
self.assertEquals(exitcode, 0)
@unittest.skipUnless(mswindows, "Windows specific tests")
class Win32ProcessTestCase(BaseTestCase):