Skip to content

Commit 3aa4418

Browse files
miss-islingtonartemmukhinhroncok
authored
[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 71239d5) Co-authored-by: Artem Mukhin <[email protected]> Co-authored-by: Miro Hrončok <[email protected]>
1 parent 6bc5316 commit 3aa4418

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

Lib/test/test_sysconfig.py

+23-14
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,21 @@ def test_posix_venv_scheme(self):
150150
'python%d.%d' % sys.version_info[:2],
151151
'site-packages')
152152

153-
# Resolve the paths in prefix
154-
binpath = os.path.join(sys.prefix, binpath)
155-
incpath = os.path.join(sys.prefix, incpath)
156-
libpath = os.path.join(sys.prefix, libpath)
153+
# Resolve the paths in an imaginary venv/ directory
154+
binpath = os.path.join('venv', binpath)
155+
incpath = os.path.join('venv', incpath)
156+
libpath = os.path.join('venv', libpath)
157157

158-
self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='posix_venv'))
159-
self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='posix_venv'))
158+
# Mimic the venv module, set all bases to the venv directory
159+
bases = ('base', 'platbase', 'installed_base', 'installed_platbase')
160+
vars = {base: 'venv' for base in bases}
161+
162+
self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='posix_venv', vars=vars))
163+
self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='posix_venv', vars=vars))
160164

161165
# The include directory on POSIX isn't exactly the same as before,
162166
# but it is "within"
163-
sysconfig_includedir = sysconfig.get_path('include', scheme='posix_venv')
167+
sysconfig_includedir = sysconfig.get_path('include', scheme='posix_venv', vars=vars)
164168
self.assertTrue(sysconfig_includedir.startswith(incpath + os.sep))
165169

166170
def test_nt_venv_scheme(self):
@@ -170,14 +174,19 @@ def test_nt_venv_scheme(self):
170174
incpath = 'Include'
171175
libpath = os.path.join('Lib', 'site-packages')
172176

173-
# Resolve the paths in prefix
174-
binpath = os.path.join(sys.prefix, binpath)
175-
incpath = os.path.join(sys.prefix, incpath)
176-
libpath = os.path.join(sys.prefix, libpath)
177+
# Resolve the paths in an imaginary venv\ directory
178+
venv = 'venv'
179+
binpath = os.path.join(venv, binpath)
180+
incpath = os.path.join(venv, incpath)
181+
libpath = os.path.join(venv, libpath)
182+
183+
# Mimic the venv module, set all bases to the venv directory
184+
bases = ('base', 'platbase', 'installed_base', 'installed_platbase')
185+
vars = {base: 'venv' for base in bases}
177186

178-
self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv'))
179-
self.assertEqual(incpath, sysconfig.get_path('include', scheme='nt_venv'))
180-
self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='nt_venv'))
187+
self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv', vars=vars))
188+
self.assertEqual(incpath, sysconfig.get_path('include', scheme='nt_venv', vars=vars))
189+
self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='nt_venv', vars=vars))
181190

182191
def test_venv_scheme(self):
183192
if sys.platform == 'win32':

0 commit comments

Comments
 (0)