[3.11] gh-103224: Resolve paths properly in test_sysconfig (GH-103292) (GH-115101)

To pass tests when executed through a Python symlink.

(cherry picked from commit 71239d50b5)

Co-authored-by: Artem Mukhin <artem.m.mukhin@gmail.com>
Co-authored-by: Miro Hrončok <miro@hroncok.cz>
This commit is contained in:
Miss Islington (bot) 2024-02-07 10:36:27 +01:00 committed by GitHub
parent 6bc531610f
commit 3aa4418c5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 14 deletions

View File

@ -150,17 +150,21 @@ def test_posix_venv_scheme(self):
'python%d.%d' % sys.version_info[:2], 'python%d.%d' % sys.version_info[:2],
'site-packages') 'site-packages')
# Resolve the paths in prefix # Resolve the paths in an imaginary venv/ directory
binpath = os.path.join(sys.prefix, binpath) binpath = os.path.join('venv', binpath)
incpath = os.path.join(sys.prefix, incpath) incpath = os.path.join('venv', incpath)
libpath = os.path.join(sys.prefix, libpath) libpath = os.path.join('venv', libpath)
self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='posix_venv')) # Mimic the venv module, set all bases to the venv directory
self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='posix_venv')) 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, # The include directory on POSIX isn't exactly the same as before,
# but it is "within" # 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)) self.assertTrue(sysconfig_includedir.startswith(incpath + os.sep))
def test_nt_venv_scheme(self): def test_nt_venv_scheme(self):
@ -170,14 +174,19 @@ def test_nt_venv_scheme(self):
incpath = 'Include' incpath = 'Include'
libpath = os.path.join('Lib', 'site-packages') libpath = os.path.join('Lib', 'site-packages')
# Resolve the paths in prefix # Resolve the paths in an imaginary venv\ directory
binpath = os.path.join(sys.prefix, binpath) venv = 'venv'
incpath = os.path.join(sys.prefix, incpath) binpath = os.path.join(venv, binpath)
libpath = os.path.join(sys.prefix, libpath) incpath = os.path.join(venv, incpath)
libpath = os.path.join(venv, libpath)
self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv')) # Mimic the venv module, set all bases to the venv directory
self.assertEqual(incpath, sysconfig.get_path('include', scheme='nt_venv')) bases = ('base', 'platbase', 'installed_base', 'installed_platbase')
self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='nt_venv')) vars = {base: 'venv' for base in bases}
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): def test_venv_scheme(self):
if sys.platform == 'win32': if sys.platform == 'win32':