@@ -139,10 +139,32 @@ def contents(self):
139139 with open (self .location , 'r' , encoding = 'utf-8' ) as f :
140140 return f .read ()
141141
142+ def resolve (self , value ):
143+ """Resolve a path from the file, as a PEP 739 consumer would."""
144+ base_prefix = os .path .join (os .path .dirname (self .location ),
145+ self .key ('base_prefix' ))
146+ return os .path .normpath (os .path .join (base_prefix , value ))
147+
142148 @needs_installed_python
143149 def test_location (self ):
144150 self .assertTrue (os .path .isfile (self .location ))
145151
152+ @needs_installed_python
153+ def test_paths_are_relative (self ):
154+ self .assertFalse (os .path .isabs (self .key ('base_prefix' )))
155+ self .assertEqual (os .path .realpath (self .resolve ('.' )),
156+ os .path .realpath (sys .base_prefix ))
157+
158+ for name in ('base_interpreter' , 'libpython.dynamic' ,
159+ 'libpython.dynamic_stableabi' , 'libpython.static' ,
160+ 'c_api.headers' , 'c_api.pkgconfig_path' ):
161+ with self .subTest (key = name ):
162+ try :
163+ value = self .key (name )
164+ except KeyError :
165+ continue
166+ self .assertFalse (os .path .isabs (value ))
167+
146168 def test_abi (self ):
147169 self .assertEqual (self .key ('abi.flags' ), list (sys .abiflags ))
148170 self .assertEqual (self .key ('abi.extension_suffix' ),
@@ -162,11 +184,7 @@ def test_extension_suffixes(self):
162184 'Android and iOS run tests via a custom testbed method that changes sys.executable'
163185 )
164186 def test_base_interpreter (self ):
165- value = self .key ('base_interpreter' )
166-
167- # Skip check if installation is relocated
168- if sysconfig ._installation_is_relocated ():
169- self .skipTest ("Installation is relocated" )
187+ value = self .resolve (self .key ('base_interpreter' ))
170188
171189 self .assertEqual (os .path .realpath (value ), os .path .realpath (sys .executable ))
172190
@@ -178,13 +196,11 @@ def test_base_interpreter(self):
178196 def test_c_api (self ):
179197 value = self .key ('c_api' )
180198
181- # Skip check if installation is relocated
182- if sysconfig ._installation_is_relocated ():
183- self .skipTest ("Installation is relocated" )
184-
185- self .assertTrue (os .path .exists (os .path .join (value ['headers' ], 'Python.h' )))
199+ headers = self .resolve (value ['headers' ])
200+ self .assertTrue (os .path .exists (os .path .join (headers , 'Python.h' )))
186201 version = sysconfig .get_config_var ('VERSION' )
187- self .assertTrue (os .path .exists (os .path .join (value ['pkgconfig_path' ], f'python-{ version } .pc' )))
202+ pkgconfig_path = self .resolve (value ['pkgconfig_path' ])
203+ self .assertTrue (os .path .exists (os .path .join (pkgconfig_path , f'python-{ version } .pc' )))
188204
189205 @needs_installed_python
190206 @unittest .skipIf (
@@ -196,11 +212,8 @@ def test_libpython_static(self):
196212 if 'static' not in value :
197213 self .skipTest ("No static libpython" )
198214
199- if sysconfig ._installation_is_relocated ():
200- self .skipTest ("Installation is relocated" )
201-
202215 # The path must name an installed static library (an 'ar' archive).
203- with open (value ['static' ], 'rb' ) as f :
216+ with open (self . resolve ( value ['static' ]) , 'rb' ) as f :
204217 self .assertEqual (f .read (8 ), b'!<arch>\n ' )
205218
206219 @needs_installed_python
@@ -218,10 +231,7 @@ def test_libpython_dynamic(self):
218231 if 'dynamic' not in value :
219232 self .skipTest ("No dynamic libpython" )
220233
221- if sysconfig ._installation_is_relocated ():
222- self .skipTest ("Installation is relocated" )
223-
224- self .assertTrue (os .path .isfile (value ['dynamic' ]))
234+ self .assertTrue (os .path .isfile (self .resolve (value ['dynamic' ])))
225235
226236
227237@unittest .skipIf (
0 commit comments