summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Mukhin <artem.m.mukhin@gmail.com>2024-02-06 19:32:07 (GMT)
committerGitHub <noreply@github.com>2024-02-06 19:32:07 (GMT)
commit71239d50b54c90afd3fdde260848e0c6d73a5c27 (patch)
tree292b1703db3d348aa7ebdb92513b10552a4ba986
parent76108b8b05040fc49a6bc50eb2e990576595c57c (diff)
downloadcpython-71239d50b54c90afd3fdde260848e0c6d73a5c27.zip
cpython-71239d50b54c90afd3fdde260848e0c6d73a5c27.tar.gz
cpython-71239d50b54c90afd3fdde260848e0c6d73a5c27.tar.bz2
gh-103224: Resolve paths properly in test_sysconfig (GH-103292)
To pass tests when executed through a Python symlink. Co-authored-by: Miro HronĨok <miro@hroncok.cz>
-rw-r--r--Lib/test/test_sysconfig.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
index be609a0..bb87bf0 100644
--- a/Lib/test/test_sysconfig.py
+++ b/Lib/test/test_sysconfig.py
@@ -154,17 +154,21 @@ class TestSysConfig(unittest.TestCase):
'python%d.%d' % sys.version_info[:2],
'site-packages')
- # Resolve the paths in prefix
- binpath = os.path.join(sys.prefix, binpath)
- incpath = os.path.join(sys.prefix, incpath)
- libpath = os.path.join(sys.prefix, libpath)
+ # Resolve the paths in an imaginary venv/ directory
+ binpath = os.path.join('venv', binpath)
+ incpath = os.path.join('venv', incpath)
+ libpath = os.path.join('venv', libpath)
- self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='posix_venv'))
- self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='posix_venv'))
+ # Mimic the venv module, set all bases to the venv directory
+ bases = ('base', 'platbase', 'installed_base', 'installed_platbase')
+ vars = {base: 'venv' for base in bases}
+
+ self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='posix_venv', vars=vars))
+ self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='posix_venv', vars=vars))
# The include directory on POSIX isn't exactly the same as before,
# but it is "within"
- sysconfig_includedir = sysconfig.get_path('include', scheme='posix_venv')
+ sysconfig_includedir = sysconfig.get_path('include', scheme='posix_venv', vars=vars)
self.assertTrue(sysconfig_includedir.startswith(incpath + os.sep))
def test_nt_venv_scheme(self):
@@ -174,14 +178,19 @@ class TestSysConfig(unittest.TestCase):
incpath = 'Include'
libpath = os.path.join('Lib', 'site-packages')
- # Resolve the paths in prefix
- binpath = os.path.join(sys.prefix, binpath)
- incpath = os.path.join(sys.prefix, incpath)
- libpath = os.path.join(sys.prefix, libpath)
+ # Resolve the paths in an imaginary venv\ directory
+ venv = 'venv'
+ binpath = os.path.join(venv, binpath)
+ incpath = os.path.join(venv, incpath)
+ libpath = os.path.join(venv, libpath)
+
+ # Mimic the venv module, set all bases to the venv directory
+ bases = ('base', 'platbase', 'installed_base', 'installed_platbase')
+ vars = {base: 'venv' for base in bases}
- self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv'))
- self.assertEqual(incpath, sysconfig.get_path('include', scheme='nt_venv'))
- self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='nt_venv'))
+ self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv', vars=vars))
+ self.assertEqual(incpath, sysconfig.get_path('include', scheme='nt_venv', vars=vars))
+ self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='nt_venv', vars=vars))
def test_venv_scheme(self):
if sys.platform == 'win32':