summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-09-27 08:18:39 (GMT)
committerGitHub <noreply@github.com>2023-09-27 08:18:39 (GMT)
commit1512d6c6ee2a770afb339bbb74c1b990116f7f89 (patch)
treec06112bc117488f73830e3f739a522020eec8fea /Lib/test
parent0e28d0f7a1bc3776cc07e0f8b91bc43fcdbb4206 (diff)
downloadcpython-1512d6c6ee2a770afb339bbb74c1b990116f7f89.zip
cpython-1512d6c6ee2a770afb339bbb74c1b990116f7f89.tar.gz
cpython-1512d6c6ee2a770afb339bbb74c1b990116f7f89.tar.bz2
gh-109615: Fix test_tools.test_freeze SRCDIR (#109935)
Fix copy_source_tree() function of test_tools.test_freeze: * Don't copy SRC_DIR/build/ anymore. This directory is modified by other tests running in parallel. * Add test.support.copy_python_src_ignore(). * Use sysconfig to get the source directory. * Use sysconfig.get_config_var() to get CONFIG_ARGS variable.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/libregrtest/utils.py2
-rw-r--r--Lib/test/support/__init__.py27
-rw-r--r--Lib/test/test_support.py22
-rw-r--r--Lib/test/test_venv.py10
4 files changed, 52 insertions, 9 deletions
diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py
index acf3572..7692217 100644
--- a/Lib/test/libregrtest/utils.py
+++ b/Lib/test/libregrtest/utils.py
@@ -355,7 +355,7 @@ def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath:
if not support.is_wasi:
tmp_dir = sysconfig.get_config_var('abs_builddir')
if tmp_dir is None:
- # bpo-30284: On Windows, only srcdir is available. Using
+ # gh-74470: On Windows, only srcdir is available. Using
# abs_builddir mostly matters on UNIX when building Python
# out of the source tree, especially when the source tree
# is read only.
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 8a4555c..4fcb899 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2565,3 +2565,30 @@ def without_optimizer(func):
finally:
_testinternalcapi.set_optimizer(save_opt)
return wrapper
+
+
+_BASE_COPY_SRC_DIR_IGNORED_NAMES = frozenset({
+ # SRC_DIR/.git
+ '.git',
+ # ignore all __pycache__/ sub-directories
+ '__pycache__',
+})
+
+# Ignore function for shutil.copytree() to copy the Python source code.
+def copy_python_src_ignore(path, names):
+ ignored = _BASE_COPY_SRC_DIR_IGNORED_NAMES
+ if os.path.basename(path) == 'Doc':
+ ignored |= {
+ # SRC_DIR/Doc/build/
+ 'build',
+ # SRC_DIR/Doc/venv/
+ 'venv',
+ }
+
+ # check if we are at the root of the source code
+ elif 'Modules' in names:
+ ignored |= {
+ # SRC_DIR/build/
+ 'build',
+ }
+ return ignored
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 5b57c5f..af38db5 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -7,6 +7,7 @@ import socket
import stat
import subprocess
import sys
+import sysconfig
import tempfile
import textwrap
import unittest
@@ -800,6 +801,27 @@ class TestSupport(unittest.TestCase):
support.max_memuse = old_max_memuse
support.real_max_memuse = old_real_max_memuse
+ def test_copy_python_src_ignore(self):
+ src_dir = sysconfig.get_config_var('srcdir')
+ src_dir = os.path.abspath(src_dir)
+
+ ignored = {'.git', '__pycache__'}
+
+ # Source code directory
+ names = os.listdir(src_dir)
+ self.assertEqual(support.copy_python_src_ignore(src_dir, names),
+ ignored | {'build'})
+
+ # Doc/ directory
+ path = os.path.join(src_dir, 'Doc')
+ self.assertEqual(support.copy_python_src_ignore(path, os.listdir(path)),
+ ignored | {'build', 'venv'})
+
+ # An other directory
+ path = os.path.join(src_dir, 'Objects')
+ self.assertEqual(support.copy_python_src_ignore(path, os.listdir(path)),
+ ignored)
+
# XXX -follows a list of untested API
# make_legacy_pyc
# is_resource_enabled
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
index eb83aa3..0ffe3e1 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -21,7 +21,7 @@ from test.support import (captured_stdout, captured_stderr,
skip_if_broken_multiprocessing_synchronize, verbose,
requires_subprocess, is_emscripten, is_wasi,
requires_venv_with_pip, TEST_HOME_DIR,
- requires_resource)
+ requires_resource, copy_python_src_ignore)
from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree)
import unittest
import venv
@@ -560,12 +560,6 @@ class BasicTest(BaseTest):
stdlib_zip)
additional_pythonpath_for_non_installed = []
- # gh-109748: Don't copy __pycache__/ sub-directories, because they can
- # be modified by other Python tests running in parallel.
- ignored_names = {'__pycache__'}
- def ignore_pycache(src, names):
- return ignored_names
-
# Copy stdlib files to the non-installed python so venv can
# correctly calculate the prefix.
for eachpath in sys.path:
@@ -583,7 +577,7 @@ class BasicTest(BaseTest):
shutil.copy(fn, libdir)
elif os.path.isdir(fn):
shutil.copytree(fn, os.path.join(libdir, name),
- ignore=ignore_pycache)
+ ignore=copy_python_src_ignore)
else:
additional_pythonpath_for_non_installed.append(
eachpath)