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/test_venv.py | |
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/test_venv.py')
-rw-r--r-- | Lib/test/test_venv.py | 46 |
1 files changed, 39 insertions, 7 deletions
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 = ( |