summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_platform.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2019-06-29 17:34:11 (GMT)
committerGitHub <noreply@github.com>2019-06-29 17:34:11 (GMT)
commit9048c49322a5229ff99610aba35913ffa295ebb7 (patch)
treecaad6f4a3b44e547208ac70cc1746c4df349ac8f /Lib/test/test_platform.py
parent80097e089ba22a42d804e65fbbcf35e5e49eed00 (diff)
downloadcpython-9048c49322a5229ff99610aba35913ffa295ebb7.zip
cpython-9048c49322a5229ff99610aba35913ffa295ebb7.tar.gz
cpython-9048c49322a5229ff99610aba35913ffa295ebb7.tar.bz2
bpo-37369: Fix initialization of sys members when launched via an app container (GH-14428)
sys._base_executable is now always defined on all platforms, and can be overridden through configuration. Also adds test.support.PythonSymlink to encapsulate platform-specific logic for symlinking sys.executable
Diffstat (limited to 'Lib/test/test_platform.py')
-rw-r--r--Lib/test/test_platform.py39
1 files changed, 8 insertions, 31 deletions
diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py
index 9cf1772..8b64923 100644
--- a/Lib/test/test_platform.py
+++ b/Lib/test/test_platform.py
@@ -20,37 +20,9 @@ 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, PYTHONHOME and PYTHONPATH.
- env = None
- if sys.platform == "win32":
- 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,
- 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, env=env))
- finally:
- os.remove(link)
+ with support.PythonSymlink() as py:
+ cmd = "-c", "import platform; print(platform.architecture())"
+ self.assertEqual(py.call_real(*cmd), py.call_link(*cmd))
def test_platform(self):
for aliased in (False, True):
@@ -275,6 +247,11 @@ class PlatformTest(unittest.TestCase):
os.path.exists(sys.executable+'.exe'):
# Cygwin horror
executable = sys.executable + '.exe'
+ elif sys.platform == "win32" and not os.path.exists(sys.executable):
+ # App symlink appears to not exist, but we want the
+ # real executable here anyway
+ import _winapi
+ executable = _winapi.GetModuleFileName(0)
else:
executable = sys.executable
platform.libc_ver(executable)