gh-109615: Fix support test_copy_python_src_ignore() (#109958) · python/cpython@b89ed9d · GitHub
Skip to content

Commit b89ed9d

Browse files
authored
gh-109615: Fix support test_copy_python_src_ignore() (#109958)
Fix the test when run on an installed Python: use "abs_srcdir" of sysconfig, and skip the test if the Python source code cannot be found. * Tools/patchcheck/patchcheck.py, Tools/freeze/test/freeze.py and Lib/test/libregrtest/utils.py now first try to get "abs_srcdir" from sysconfig, before getting "srcdir" from sysconfig. * test.pythoninfo logs sysconfig "abs_srcdir".
1 parent 91fb8da commit b89ed9d

5 files changed

Lines changed: 30 additions & 8 deletions

File tree

‎Lib/test/libregrtest/utils.py‎

Lines changed: 7 additions & 5 deletions

‎Lib/test/pythoninfo.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ def collect_sysconfig(info_add):
520520
'SHELL',
521521
'SOABI',
522522
'abs_builddir',
523+
'abs_srcdir',
523524
'prefix',
524525
'srcdir',
525526
):

‎Lib/test/test_support.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,13 @@ def test_set_memlimit(self):
802802
support.real_max_memuse = old_real_max_memuse
803803

804804
def test_copy_python_src_ignore(self):
805-
src_dir = sysconfig.get_config_var('srcdir')
805+
src_dir = sysconfig.get_config_var('abs_srcdir')
806+
if not src_dir:
807+
src_dir = sysconfig.get_config_var('srcdir')
806808
src_dir = os.path.abspath(src_dir)
809+
if not os.path.exists(src_dir):
810+
self.skipTest(f"cannot access Python source code directory:"
811+
f" {src_dir!r}")
807812

808813
ignored = {'.git', '__pycache__'}
809814

‎Tools/freeze/test/freeze.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@
77
from test import support
88

99

10+
def get_python_source_dir():
11+
src_dir = sysconfig.get_config_var('abs_srcdir')
12+
if not src_dir:
13+
src_dir = sysconfig.get_config_var('srcdir')
14+
return os.path.abspath(src_dir)
15+
16+
1017
TESTS_DIR = os.path.dirname(__file__)
1118
TOOL_ROOT = os.path.dirname(TESTS_DIR)
12-
SRCDIR = os.path.abspath(sysconfig.get_config_var('srcdir'))
19+
SRCDIR = get_python_source_dir()
1320

1421
MAKE = shutil.which('make')
1522
FREEZE = os.path.join(TOOL_ROOT, 'freeze.py')

‎Tools/patchcheck/patchcheck.py‎

Lines changed: 8 additions & 1 deletion

0 commit comments

Comments
 (0)