diff options
| author | Steve Dower <steve.dower@microsoft.com> | 2018-09-20 20:38:34 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-09-20 20:38:34 (GMT) |
| commit | f14c28f39766855420dd58d209da4ad847f3030e (patch) | |
| tree | 79b95924f711b99388b2899c119ae31f31ad2ce5 /Lib/test/test_platform.py | |
| parent | bc854750589d4de0fd55693963964e0558b5c8ac (diff) | |
| download | cpython-f14c28f39766855420dd58d209da4ad847f3030e.zip cpython-f14c28f39766855420dd58d209da4ad847f3030e.tar.gz cpython-f14c28f39766855420dd58d209da4ad847f3030e.tar.bz2 | |
bpo-34011: Fixes missing venv files and other tests (GH-9458)
Diffstat (limited to 'Lib/test/test_platform.py')
| -rw-r--r-- | Lib/test/test_platform.py | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index fd6da31..c26e193 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -3,6 +3,7 @@ import os import platform import subprocess import sys +import sysconfig import tempfile import unittest import warnings @@ -16,29 +17,34 @@ class PlatformTest(unittest.TestCase): @support.skip_unless_symlink def test_architecture_via_symlink(self): # issue3762 # On Windows, the EXE needs to know where pythonXY.dll and *.pyd is at - # so we add the directory to the path and PYTHONPATH. + # so we add the directory to the path, PYTHONHOME and PYTHONPATH. + env = None if sys.platform == "win32": - def restore_environ(old_env): - os.environ.clear() - os.environ.update(old_env) - - self.addCleanup(restore_environ, dict(os.environ)) - - os.environ["Path"] = "{};{}".format( - os.path.dirname(sys.executable), os.environ["Path"]) - os.environ["PYTHONPATH"] = os.path.dirname(sys.executable) - - def get(python): + env = {k.upper(): os.environ[k] for k in os.environ} + env["PATH"] = "{};{}".format( + os.path.dirname(sys.executable), env.get("PATH", "")) + env["PYTHONHOME"] = os.path.dirname(sys.executable) + if sysconfig.is_python_build(True): + env["PYTHONPATH"] = os.path.dirname(os.__file__) + + def get(python, env=None): cmd = [python, '-c', 'import platform; print(platform.architecture())'] - p = subprocess.Popen(cmd, stdout=subprocess.PIPE) - return p.communicate() + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, env=env) + r = p.communicate() + if p.returncode: + print(repr(r[0])) + print(repr(r[1]), file=sys.stderr) + self.fail('unexpected return code: {0} (0x{0:08X})' + .format(p.returncode)) + return r real = os.path.realpath(sys.executable) link = os.path.abspath(support.TESTFN) os.symlink(real, link) try: - self.assertEqual(get(real), get(link)) + self.assertEqual(get(real), get(link, env=env)) finally: os.remove(link) |
