diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2022-07-05 15:40:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-05 15:40:17 (GMT) |
commit | 49aeda989d9385eb4f0c41f7a7e4854037a7abfb (patch) | |
tree | f854825d1d3f3b518cdd575697c97a8518ddb850 /Lib/test/test_venv.py | |
parent | 7a3dae06eb6ff822b47ee8ed01dd840139cb994c (diff) | |
download | cpython-49aeda989d9385eb4f0c41f7a7e4854037a7abfb.zip cpython-49aeda989d9385eb4f0c41f7a7e4854037a7abfb.tar.gz cpython-49aeda989d9385eb4f0c41f7a7e4854037a7abfb.tar.bz2 |
[3.11] gh-92897: Ensure `venv --copies` respects source build property of the creating interpreter (GH-92899) (GH-94567)
(cherry picked from commit 067597522a9002f3b8aff7f46033f10acb2381e4)
Co-authored-by: Jeremy Kloth <jeremy.kloth@gmail.com>
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 4440fce..74039f5 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, requires_zlib, 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 = ( |