mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Fix test_undecodable_env of test_subproces for non-ASCII directory
This test was introduced by r80421 (issue #8391). The fix: copy the environment variables instead of starting Python in an empty environement. In an empty environment, the locale is C and Python uses ASCII for the default file system encoding. The non-ASCII directory will be encoded using surrogates, but Python3 is unable to load a module or package with a filename using surrogates. See issue #8242 for more information about running Python3 with a non-ascii directory in an empty environement.
This commit is contained in:
parent
13bb71c38f
commit
ce2d24d549
1 changed files with 6 additions and 2 deletions
|
@ -807,9 +807,11 @@ class POSIXProcessTestCase(BaseTestCase):
|
||||||
|
|
||||||
# test str with surrogates
|
# test str with surrogates
|
||||||
script = "import os; print(repr(os.getenv(%s)))" % repr(key)
|
script = "import os; print(repr(os.getenv(%s)))" % repr(key)
|
||||||
|
env = os.environ.copy()
|
||||||
|
env[key] = value
|
||||||
stdout = subprocess.check_output(
|
stdout = subprocess.check_output(
|
||||||
[sys.executable, "-c", script],
|
[sys.executable, "-c", script],
|
||||||
env={key: value})
|
env=env)
|
||||||
stdout = stdout.rstrip(b'\n\r')
|
stdout = stdout.rstrip(b'\n\r')
|
||||||
self.assertEquals(stdout, value_repr)
|
self.assertEquals(stdout, value_repr)
|
||||||
|
|
||||||
|
@ -817,9 +819,11 @@ class POSIXProcessTestCase(BaseTestCase):
|
||||||
key = key.encode("ascii", "surrogateescape")
|
key = key.encode("ascii", "surrogateescape")
|
||||||
value = value.encode("ascii", "surrogateescape")
|
value = value.encode("ascii", "surrogateescape")
|
||||||
script = "import os; print(repr(os.getenv(%s)))" % repr(key)
|
script = "import os; print(repr(os.getenv(%s)))" % repr(key)
|
||||||
|
env = os.environ.copy()
|
||||||
|
env[key] = value
|
||||||
stdout = subprocess.check_output(
|
stdout = subprocess.check_output(
|
||||||
[sys.executable, "-c", script],
|
[sys.executable, "-c", script],
|
||||||
env={key: value})
|
env=env)
|
||||||
stdout = stdout.rstrip(b'\n\r')
|
stdout = stdout.rstrip(b'\n\r')
|
||||||
self.assertEquals(stdout, value_repr)
|
self.assertEquals(stdout, value_repr)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue