Skip to content

Commit 71239d5

Browse files
artemmukhinhroncok
andauthored
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 <[email protected]>
1 parent 76108b8 commit 71239d5

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
@@ -154,17 +154,21 @@ def test_posix_venv_scheme(self):
154154
'python%d.%d' % sys.version_info[:2],
155155
'site-packages')
156156

157-
# Resolve the paths in prefix
158-
binpath = os.path.join(sys.prefix, binpath)
159-
incpath = os.path.join(sys.prefix, incpath)
160-
libpath = os.path.join(sys.prefix, libpath)
157+
# Resolve the paths in an imaginary venv/ directory
158+
binpath = os.path.join('venv', binpath)
159+
incpath = os.path.join('venv', incpath)
160+
libpath = os.path.join('venv', libpath)
161161

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

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

170174
def test_nt_venv_scheme(self):
@@ -174,14 +178,19 @@ def test_nt_venv_scheme(self):
174178
incpath = 'Include'
175179
libpath = os.path.join('Lib', 'site-packages')
176180

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

182-
self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv'))
183-
self.assertEqual(incpath, sysconfig.get_path('include', scheme='nt_venv'))
184-
self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='nt_venv'))
191+
self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv', vars=vars))
192+
self.assertEqual(incpath, sysconfig.get_path('include', scheme='nt_venv', vars=vars))
193+
self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='nt_venv', vars=vars))
185194

186195
def test_venv_scheme(self):
187196
if sys.platform == 'win32':

0 commit comments

Comments
 (0)