]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-54781: Move Lib/lib2to3/tests/ to Lib/test/test_lib2to3/ (#94049)
authorVictor Stinner <vstinner@python.org>
Tue, 21 Jun 2022 13:21:22 +0000 (15:21 +0200)
committerGitHub <noreply@github.com>
Tue, 21 Jun 2022 13:21:22 +0000 (15:21 +0200)
* Move Lib/lib2to3/tests/ to Lib/test/test_lib2to3/.
* Remove Lib/test/test_lib2to3.py.
* Update imports.
* all_project_files(): use different paths and sort files
  to make the tests more reproducible.
* Update references to tests.

35 files changed:
Lib/test/test_lib2to3.py [deleted file]
Lib/test/test_lib2to3/__init__.py [moved from Lib/lib2to3/tests/__init__.py with 100% similarity]
Lib/test/test_lib2to3/__main__.py [moved from Lib/lib2to3/tests/__main__.py with 100% similarity]
Lib/test/test_lib2to3/data/README [moved from Lib/lib2to3/tests/data/README with 100% similarity]
Lib/test/test_lib2to3/data/bom.py [moved from Lib/lib2to3/tests/data/bom.py with 100% similarity]
Lib/test/test_lib2to3/data/crlf.py [moved from Lib/lib2to3/tests/data/crlf.py with 100% similarity]
Lib/test/test_lib2to3/data/different_encoding.py [moved from Lib/lib2to3/tests/data/different_encoding.py with 100% similarity]
Lib/test/test_lib2to3/data/false_encoding.py [moved from Lib/lib2to3/tests/data/false_encoding.py with 100% similarity]
Lib/test/test_lib2to3/data/fixers/bad_order.py [moved from Lib/lib2to3/tests/data/fixers/bad_order.py with 100% similarity]
Lib/test/test_lib2to3/data/fixers/myfixes/__init__.py [moved from Lib/lib2to3/tests/data/fixers/myfixes/__init__.py with 100% similarity]
Lib/test/test_lib2to3/data/fixers/myfixes/fix_explicit.py [moved from Lib/lib2to3/tests/data/fixers/myfixes/fix_explicit.py with 100% similarity]
Lib/test/test_lib2to3/data/fixers/myfixes/fix_first.py [moved from Lib/lib2to3/tests/data/fixers/myfixes/fix_first.py with 100% similarity]
Lib/test/test_lib2to3/data/fixers/myfixes/fix_last.py [moved from Lib/lib2to3/tests/data/fixers/myfixes/fix_last.py with 100% similarity]
Lib/test/test_lib2to3/data/fixers/myfixes/fix_parrot.py [moved from Lib/lib2to3/tests/data/fixers/myfixes/fix_parrot.py with 100% similarity]
Lib/test/test_lib2to3/data/fixers/myfixes/fix_preorder.py [moved from Lib/lib2to3/tests/data/fixers/myfixes/fix_preorder.py with 100% similarity]
Lib/test/test_lib2to3/data/fixers/no_fixer_cls.py [moved from Lib/lib2to3/tests/data/fixers/no_fixer_cls.py with 100% similarity]
Lib/test/test_lib2to3/data/fixers/parrot_example.py [moved from Lib/lib2to3/tests/data/fixers/parrot_example.py with 100% similarity]
Lib/test/test_lib2to3/data/infinite_recursion.py [moved from Lib/lib2to3/tests/data/infinite_recursion.py with 100% similarity]
Lib/test/test_lib2to3/data/py2_test_grammar.py [moved from Lib/lib2to3/tests/data/py2_test_grammar.py with 100% similarity]
Lib/test/test_lib2to3/data/py3_test_grammar.py [moved from Lib/lib2to3/tests/data/py3_test_grammar.py with 100% similarity]
Lib/test/test_lib2to3/pytree_idempotency.py [moved from Lib/lib2to3/tests/pytree_idempotency.py with 96% similarity]
Lib/test/test_lib2to3/support.py [moved from Lib/lib2to3/tests/support.py with 77% similarity]
Lib/test/test_lib2to3/test_all_fixers.py [moved from Lib/lib2to3/tests/test_all_fixers.py with 100% similarity]
Lib/test/test_lib2to3/test_fixers.py [moved from Lib/lib2to3/tests/test_fixers.py with 99% similarity]
Lib/test/test_lib2to3/test_main.py [moved from Lib/lib2to3/tests/test_main.py with 100% similarity]
Lib/test/test_lib2to3/test_parser.py [moved from Lib/lib2to3/tests/test_parser.py with 99% similarity]
Lib/test/test_lib2to3/test_pytree.py [moved from Lib/lib2to3/tests/test_pytree.py with 100% similarity]
Lib/test/test_lib2to3/test_refactor.py [moved from Lib/lib2to3/tests/test_refactor.py with 100% similarity]
Lib/test/test_lib2to3/test_util.py [moved from Lib/lib2to3/tests/test_util.py with 100% similarity]
Mac/BuildScript/scripts/postflight.framework
Makefile.pre.in
PCbuild/lib.pyproj
Tools/peg_generator/Makefile
Tools/peg_generator/scripts/benchmark.py
Tools/scripts/generate_stdlib_module_names.py

diff --git a/Lib/test/test_lib2to3.py b/Lib/test/test_lib2to3.py
deleted file mode 100644 (file)
index 6ea8aa4..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-import unittest
-from test.support.import_helper import import_fresh_module
-from test.support.warnings_helper import check_warnings
-
-with check_warnings(("", DeprecationWarning)):
-    load_tests = import_fresh_module('lib2to3.tests', fresh=['lib2to3']).load_tests
-
-if __name__ == '__main__':
-    unittest.main()
similarity index 96%
rename from Lib/lib2to3/tests/pytree_idempotency.py
rename to Lib/test/test_lib2to3/pytree_idempotency.py
index 2e7e9781d42995e4708b0c9248ab8835fff1f80f..eb2e2aa02ae0ed0e93e28ca342d34c759e2e2b80 100755 (executable)
@@ -17,9 +17,9 @@ import sys
 import logging
 
 # Local imports
-from .. import pytree
-from .. import pgen2
-from ..pgen2 import driver
+from lib2to3 import pytree
+from lib2to3 import pgen2
+from lib2to3.pgen2 import driver
 
 logging.basicConfig()
 
similarity index 77%
rename from Lib/lib2to3/tests/support.py
rename to Lib/test/test_lib2to3/support.py
index fe084e8903fc86fe43f58ade317e7c785b024b23..9e56273e95992b53ba30435e0fe8a0b95b306c6d 100644 (file)
@@ -8,12 +8,14 @@ import os.path
 from textwrap import dedent
 
 # Local imports
+import lib2to3
 from lib2to3 import pytree, refactor
 from lib2to3.pgen2 import driver as pgen2_driver
 
+lib2to3_dir = os.path.dirname(lib2to3.__file__)
 test_dir = os.path.dirname(__file__)
 proj_dir = os.path.normpath(os.path.join(test_dir, ".."))
-grammar_path = os.path.join(test_dir, "..", "Grammar.txt")
+grammar_path = os.path.join(lib2to3_dir, "Grammar.txt")
 grammar = pgen2_driver.load_grammar(grammar_path)
 grammar_no_print_statement = pgen2_driver.load_grammar(grammar_path)
 del grammar_no_print_statement.keywords["print"]
@@ -49,10 +51,19 @@ def get_refactorer(fixer_pkg="lib2to3", fixers=None, options=None):
     options = options or {}
     return refactor.RefactoringTool(fixers, options, explicit=True)
 
-def all_project_files():
-    for dirpath, dirnames, filenames in os.walk(proj_dir):
+def _all_project_files(root, files):
+    for dirpath, dirnames, filenames in os.walk(root):
         for filename in filenames:
-            if filename.endswith(".py"):
-                yield os.path.join(dirpath, filename)
+            if not filename.endswith(".py"):
+                continue
+            files.append(os.path.join(dirpath, filename))
+
+def all_project_files():
+    files = []
+    _all_project_files(lib2to3_dir, files)
+    _all_project_files(test_dir, files)
+    # Sort to get more reproducible tests
+    files.sort()
+    return files
 
 TestCase = unittest.TestCase
similarity index 99%
rename from Lib/lib2to3/tests/test_fixers.py
rename to Lib/test/test_lib2to3/test_fixers.py
index 121ebe68e5402ba29b94a2ca122eb272a6cac3e3..68efeee7abb4d5f99203bf543cea794472b55e6a 100644 (file)
@@ -7,7 +7,7 @@ from operator import itemgetter
 
 # Local imports
 from lib2to3 import pygram, fixer_util
-from lib2to3.tests import support
+from test.test_lib2to3 import support
 
 
 class FixerTestCase(support.TestCase):
@@ -1791,7 +1791,7 @@ class ImportsFixerTests:
 
 class Test_imports(FixerTestCase, ImportsFixerTests):
     fixer = "imports"
-    from ..fixes.fix_imports import MAPPING as modules
+    from lib2to3.fixes.fix_imports import MAPPING as modules
 
     def test_multiple_imports(self):
         b = """import urlparse, cStringIO"""
@@ -1812,16 +1812,16 @@ class Test_imports(FixerTestCase, ImportsFixerTests):
 
 class Test_imports2(FixerTestCase, ImportsFixerTests):
     fixer = "imports2"
-    from ..fixes.fix_imports2 import MAPPING as modules
+    from lib2to3.fixes.fix_imports2 import MAPPING as modules
 
 
 class Test_imports_fixer_order(FixerTestCase, ImportsFixerTests):
 
     def setUp(self):
         super(Test_imports_fixer_order, self).setUp(['imports', 'imports2'])
-        from ..fixes.fix_imports2 import MAPPING as mapping2
+        from lib2to3.fixes.fix_imports2 import MAPPING as mapping2
         self.modules = mapping2.copy()
-        from ..fixes.fix_imports import MAPPING as mapping1
+        from lib2to3.fixes.fix_imports import MAPPING as mapping1
         for key in ('dbhash', 'dumbdbm', 'dbm', 'gdbm'):
             self.modules[key] = mapping1[key]
 
@@ -1833,7 +1833,7 @@ class Test_imports_fixer_order(FixerTestCase, ImportsFixerTests):
 
 class Test_urllib(FixerTestCase):
     fixer = "urllib"
-    from ..fixes.fix_urllib import MAPPING as modules
+    from lib2to3.fixes.fix_urllib import MAPPING as modules
 
     def test_import_module(self):
         for old, changes in self.modules.items():
similarity index 99%
rename from Lib/lib2to3/tests/test_parser.py
rename to Lib/test/test_lib2to3/test_parser.py
index 8e7773bcae13ed85ea600166af8ccf062e921d2d..2c798b181fdbda08eb2d667ff6dbc4216d56aaf9 100644 (file)
@@ -26,7 +26,7 @@ import unittest
 # Local imports
 from lib2to3.pgen2 import driver as pgen2_driver
 from lib2to3.pgen2 import tokenize
-from ..pgen2.parse import ParseError
+from lib2to3.pgen2.parse import ParseError
 from lib2to3.pygram import python_symbols as syms
 
 
index 0f2e52c4ca1926c22eade8964d08eeb9f76f45ae..a63909358f1719605585912e6e34e8e3f778db30 100755 (executable)
@@ -8,12 +8,12 @@ FWK="/Library/Frameworks/Python.framework/Versions/@PYVER@"
 
 "${FWK}/bin/python@PYVER@" -E -s -Wi \
     "${FWK}/lib/python${PYVER}/compileall.py" -q -j0 \
-    -f -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
+    -f -x 'bad_coding|badsyntax|site-packages|test/test_lib2to3/data' \
     "${FWK}/lib/python${PYVER}"
 
 "${FWK}/bin/python@PYVER@" -E -s -Wi -O \
     "${FWK}/lib/python${PYVER}/compileall.py" -q -j0 \
-    -f -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
+    -f -x 'bad_coding|badsyntax|site-packages|test/test_lib2to3/data' \
     "${FWK}/lib/python${PYVER}"
 
 "${FWK}/bin/python@PYVER@" -E -s -Wi \
index 95424da59db0bacfe2f74c082cf9fb109138aaf6..6448785c28070eff3aee02d633a2c3827e3892b5 100644 (file)
@@ -1921,10 +1921,6 @@ LIBSUBDIRS=      asyncio \
                __phello__
 TESTSUBDIRS=   distutils/tests \
                idlelib/idle_test \
-               lib2to3/tests \
-               lib2to3/tests/data \
-               lib2to3/tests/data/fixers \
-               lib2to3/tests/data/fixers/myfixes \
                test test/audiodata \
                test/capath test/cjkencodings \
                test/data test/decimaltestdata \
@@ -1986,6 +1982,10 @@ TESTSUBDIRS=     distutils/tests \
                test/test_importlib/zipdata01 \
                test/test_importlib/zipdata02 \
                test/test_json \
+               test/test_lib2to3 \
+               test/test_lib2to3/data \
+               test/test_lib2to3/data/fixers \
+               test/test_lib2to3/data/fixers/myfixes \
                test/test_peg_generator \
                test/test_tools \
                test/test_warnings test/test_warnings/data \
@@ -2073,17 +2073,17 @@ libinstall:     all $(srcdir)/Modules/xxmodule.c
        -PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
                $(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
                -j0 -d $(LIBDEST) -f \
-               -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
+               -x 'bad_coding|badsyntax|site-packages|test/test_lib2to3/data' \
                $(DESTDIR)$(LIBDEST)
        -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
                $(PYTHON_FOR_BUILD) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \
                -j0 -d $(LIBDEST) -f \
-               -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
+               -x 'bad_coding|badsyntax|site-packages|test/test_lib2to3/data' \
                $(DESTDIR)$(LIBDEST)
        -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
                $(PYTHON_FOR_BUILD) -Wi -OO $(DESTDIR)$(LIBDEST)/compileall.py \
                -j0 -d $(LIBDEST) -f \
-               -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
+               -x 'bad_coding|badsyntax|site-packages|test/test_lib2to3/data' \
                $(DESTDIR)$(LIBDEST)
        -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
                $(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
index f3f44d1d8ff3d46fb75e4d9503e592e8bc191f2e..2355eb5486fd7e36fb69649bd844e97c7dd3efac 100644 (file)
     <Compile Include="lib2to3\pygram.py" />
     <Compile Include="lib2to3\pytree.py" />
     <Compile Include="lib2to3\refactor.py" />
-    <Compile Include="lib2to3\tests\data\bom.py" />
-    <Compile Include="lib2to3\tests\data\crlf.py" />
-    <Compile Include="lib2to3\tests\data\different_encoding.py" />
-    <Compile Include="lib2to3\tests\data\false_encoding.py" />
-    <Compile Include="lib2to3\tests\data\fixers\bad_order.py" />
-    <Compile Include="lib2to3\tests\data\fixers\myfixes\fix_explicit.py" />
-    <Compile Include="lib2to3\tests\data\fixers\myfixes\fix_first.py" />
-    <Compile Include="lib2to3\tests\data\fixers\myfixes\fix_last.py" />
-    <Compile Include="lib2to3\tests\data\fixers\myfixes\fix_parrot.py" />
-    <Compile Include="lib2to3\tests\data\fixers\myfixes\fix_preorder.py" />
-    <Compile Include="lib2to3\tests\data\fixers\myfixes\__init__.py" />
-    <Compile Include="lib2to3\tests\data\fixers\no_fixer_cls.py" />
-    <Compile Include="lib2to3\tests\data\fixers\parrot_example.py" />
-    <Compile Include="lib2to3\tests\data\infinite_recursion.py" />
-    <Compile Include="lib2to3\tests\data\py2_test_grammar.py" />
-    <Compile Include="lib2to3\tests\data\py3_test_grammar.py" />
-    <Compile Include="lib2to3\tests\pytree_idempotency.py" />
-    <Compile Include="lib2to3\tests\support.py" />
-    <Compile Include="lib2to3\tests\test_all_fixers.py" />
-    <Compile Include="lib2to3\tests\test_fixers.py" />
-    <Compile Include="lib2to3\tests\test_main.py" />
-    <Compile Include="lib2to3\tests\test_parser.py" />
-    <Compile Include="lib2to3\tests\test_pytree.py" />
-    <Compile Include="lib2to3\tests\test_refactor.py" />
-    <Compile Include="lib2to3\tests\test_util.py" />
-    <Compile Include="lib2to3\tests\__init__.py" />
-    <Compile Include="lib2to3\tests\__main__.py" />
     <Compile Include="lib2to3\__init__.py" />
     <Compile Include="lib2to3\__main__.py" />
     <Compile Include="linecache.py" />
     <Compile Include="test\test_keywordonlyarg.py" />
     <Compile Include="test\test_kqueue.py" />
     <Compile Include="test\test_largefile.py" />
-    <Compile Include="test\test_lib2to3.py" />
+    <Compile Include="test\test_lib2to3\data\bom.py" />
+    <Compile Include="test\test_lib2to3\data\crlf.py" />
+    <Compile Include="test\test_lib2to3\data\different_encoding.py" />
+    <Compile Include="test\test_lib2to3\data\false_encoding.py" />
+    <Compile Include="test\test_lib2to3\data\fixers\bad_order.py" />
+    <Compile Include="test\test_lib2to3\data\fixers\myfixes\fix_explicit.py" />
+    <Compile Include="test\test_lib2to3\data\fixers\myfixes\fix_first.py" />
+    <Compile Include="test\test_lib2to3\data\fixers\myfixes\fix_last.py" />
+    <Compile Include="test\test_lib2to3\data\fixers\myfixes\fix_parrot.py" />
+    <Compile Include="test\test_lib2to3\data\fixers\myfixes\fix_preorder.py" />
+    <Compile Include="test\test_lib2to3\data\fixers\myfixes\__init__.py" />
+    <Compile Include="test\test_lib2to3\data\fixers\no_fixer_cls.py" />
+    <Compile Include="test\test_lib2to3\data\fixers\parrot_example.py" />
+    <Compile Include="test\test_lib2to3\data\infinite_recursion.py" />
+    <Compile Include="test\test_lib2to3\data\py2_test_grammar.py" />
+    <Compile Include="test\test_lib2to3\data\py3_test_grammar.py" />
+    <Compile Include="test\test_lib2to3\pytree_idempotency.py" />
+    <Compile Include="test\test_lib2to3\support.py" />
+    <Compile Include="test\test_lib2to3\test_all_fixers.py" />
+    <Compile Include="test\test_lib2to3\test_fixers.py" />
+    <Compile Include="test\test_lib2to3\test_main.py" />
+    <Compile Include="test\test_lib2to3\test_parser.py" />
+    <Compile Include="test\test_lib2to3\test_pytree.py" />
+    <Compile Include="test\test_lib2to3\test_refactor.py" />
+    <Compile Include="test\test_lib2to3\test_util.py" />
+    <Compile Include="test\test_lib2to3\__init__.py" />
+    <Compile Include="test\test_lib2to3\__main__.py" />
     <Compile Include="test\test_linecache.py" />
     <Compile Include="test\test_list.py" />
     <Compile Include="test\test_listcomps.py" />
     <Folder Include="lib2to3" />
     <Folder Include="lib2to3\fixes" />
     <Folder Include="lib2to3\pgen2" />
-    <Folder Include="lib2to3\tests" />
-    <Folder Include="lib2to3\tests\data" />
-    <Folder Include="lib2to3\tests\data\fixers" />
-    <Folder Include="lib2to3\tests\data\fixers\myfixes" />
     <Folder Include="logging" />
     <Folder Include="msilib" />
     <Folder Include="multiprocessing" />
     <Folder Include="test\test_import\data\package" />
     <Folder Include="test\test_import\data\package2" />
     <Folder Include="test\test_json" />
+    <Folder Include="test\test_lib2to3" />
+    <Folder Include="test\test_lib2to3\data" />
+    <Folder Include="test\test_lib2to3\data\fixers" />
+    <Folder Include="test\test_lib2to3\data\fixers\myfixes" />
     <Folder Include="test\test_peg_generator" />
     <Folder Include="test\test_tools" />
     <Folder Include="test\test_unittest" />
index d010f19d58892ca28d6d9c376e9bb9a4f10a4461..084da154919e3e88eec11e511936bfa41dd8e489 100644 (file)
@@ -88,7 +88,7 @@ time_stdlib: $(CPYTHON) venv
                -d $(CPYTHON) \
                $(TESTFLAGS) \
                --exclude "*/bad*" \
-               --exclude "*/lib2to3/tests/data/*"
+               --exclude "*/test/test_lib2to3/data/*"
 
 mypy: regen-metaparser
        $(MYPY)  # For list of files, see mypy.ini
index 4a063bf10034c89d16ab77e6291a5de96a2693b8..053f8ef06d42c5fcf9bb47a242b9ca2c4ab32ca9 100644 (file)
@@ -78,7 +78,7 @@ def run_benchmark_stdlib(subcommand):
             verbose=False,
             excluded_files=[
                 "*/bad*",
-                "*/lib2to3/tests/data/*",
+                "*/test/test_lib2to3/data/*",
             ],
             short=True,
             mode=modes[subcommand],
index fe1e429ebce17581ad6786778d3c2c7871a74ab8..6f864c317da6c8f60c02e075550ed44e40159f34 100644 (file)
@@ -35,7 +35,6 @@ IGNORE = {
     '_xxtestfuzz',
     'distutils.tests',
     'idlelib.idle_test',
-    'lib2to3.tests',
     'test',
     'xxlimited',
     'xxlimited_35',