diff options
author | Jeremy Kloth <jeremy.kloth@gmail.com> | 2022-07-05 15:08:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-05 15:08:20 (GMT) |
commit | 067597522a9002f3b8aff7f46033f10acb2381e4 (patch) | |
tree | 68ae8f1c01ed530c8603c6da3064c6782e65de29 /Lib/test | |
parent | e6ec6f5b50e8793172e83a9afbb05fe01f236b37 (diff) | |
download | cpython-067597522a9002f3b8aff7f46033f10acb2381e4.zip cpython-067597522a9002f3b8aff7f46033f10acb2381e4.tar.gz cpython-067597522a9002f3b8aff7f46033f10acb2381e4.tar.bz2 |
gh-92897: Ensure `venv --copies` respects source build property of the creating interpreter (GH-92899)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_sysconfig.py | 6 | ||||
-rw-r--r-- | Lib/test/test_venv.py | 46 |
2 files changed, 44 insertions, 8 deletions
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py index 27722fbe..114e144 100644 --- a/Lib/test/test_sysconfig.py +++ b/Lib/test/test_sysconfig.py @@ -450,7 +450,11 @@ class TestSysConfig(unittest.TestCase): # should be a full source checkout. Python_h = os.path.join(srcdir, 'Include', 'Python.h') self.assertTrue(os.path.exists(Python_h), Python_h) - self.assertTrue(sysconfig._is_python_source_dir(srcdir)) + # <srcdir>/PC/pyconfig.h always exists even if unused on POSIX. + pyconfig_h = os.path.join(srcdir, 'PC', 'pyconfig.h') + self.assertTrue(os.path.exists(pyconfig_h), pyconfig_h) + pyconfig_h_in = os.path.join(srcdir, 'pyconfig.h.in') + self.assertTrue(os.path.exists(pyconfig_h_in), pyconfig_h_in) elif os.name == 'posix': makefile_dir = os.path.dirname(sysconfig.get_makefile_filename()) # Issue #19340: srcdir has been realpath'ed already diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 1545a94..4359a4e 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -15,6 +15,7 @@ import shutil import struct import subprocess import sys +import sysconfig import tempfile from test.support import (captured_stdout, captured_stderr, skip_if_broken_multiprocessing_synchronize, verbose, @@ -254,18 +255,49 @@ class BasicTest(BaseTest): self.assertEqual(out.strip(), expected.encode(), prefix) @requireVenvCreate - def test_sysconfig_preferred_and_default_scheme(self): + def test_sysconfig(self): """ - Test that the sysconfig preferred(prefix) and default scheme is venv. + Test that the sysconfig functions work in a virtual environment. """ rmtree(self.env_dir) - self.run_with_capture(venv.create, self.env_dir) + self.run_with_capture(venv.create, self.env_dir, symlinks=False) envpy = os.path.join(self.env_dir, self.bindir, self.exe) cmd = [envpy, '-c', None] - for call in ('get_preferred_scheme("prefix")', 'get_default_scheme()'): - cmd[2] = 'import sysconfig; print(sysconfig.%s)' % call - out, err = check_output(cmd) - self.assertEqual(out.strip(), b'venv', err) + for call, expected in ( + # installation scheme + ('get_preferred_scheme("prefix")', 'venv'), + ('get_default_scheme()', 'venv'), + # build environment + ('is_python_build()', str(sysconfig.is_python_build())), + ('get_makefile_filename()', sysconfig.get_makefile_filename()), + ('get_config_h_filename()', sysconfig.get_config_h_filename())): + with self.subTest(call): + cmd[2] = 'import sysconfig; print(sysconfig.%s)' % call + out, err = check_output(cmd) + self.assertEqual(out.strip(), expected.encode(), err) + + @requireVenvCreate + @unittest.skipUnless(can_symlink(), 'Needs symlinks') + def test_sysconfig_symlinks(self): + """ + Test that the sysconfig functions work in a virtual environment. + """ + rmtree(self.env_dir) + self.run_with_capture(venv.create, self.env_dir, symlinks=True) + envpy = os.path.join(self.env_dir, self.bindir, self.exe) + cmd = [envpy, '-c', None] + for call, expected in ( + # installation scheme + ('get_preferred_scheme("prefix")', 'venv'), + ('get_default_scheme()', 'venv'), + # build environment + ('is_python_build()', str(sysconfig.is_python_build())), + ('get_makefile_filename()', sysconfig.get_makefile_filename()), + ('get_config_h_filename()', sysconfig.get_config_h_filename())): + with self.subTest(call): + cmd[2] = 'import sysconfig; print(sysconfig.%s)' % call + out, err = check_output(cmd) + self.assertEqual(out.strip(), expected.encode(), err) if sys.platform == 'win32': ENV_SUBDIRS = ( |