From 616fa3465d99a262dc8948ff5e00e47fe92eaaba Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 21 Jun 2022 15:21:22 +0200 Subject: [PATCH] gh-54781: Move Lib/lib2to3/tests/ to Lib/test/test_lib2to3/ (#94049) * 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. --- Lib/test/test_lib2to3.py | 9 --- .../tests => test/test_lib2to3}/__init__.py | 0 .../tests => test/test_lib2to3}/__main__.py | 0 .../tests => test/test_lib2to3}/data/README | 0 .../tests => test/test_lib2to3}/data/bom.py | 0 .../tests => test/test_lib2to3}/data/crlf.py | 0 .../test_lib2to3}/data/different_encoding.py | 0 .../test_lib2to3}/data/false_encoding.py | 0 .../test_lib2to3}/data/fixers/bad_order.py | 0 .../data/fixers/myfixes/__init__.py | 0 .../data/fixers/myfixes/fix_explicit.py | 0 .../data/fixers/myfixes/fix_first.py | 0 .../data/fixers/myfixes/fix_last.py | 0 .../data/fixers/myfixes/fix_parrot.py | 0 .../data/fixers/myfixes/fix_preorder.py | 0 .../test_lib2to3}/data/fixers/no_fixer_cls.py | 0 .../data/fixers/parrot_example.py | 0 .../test_lib2to3}/data/infinite_recursion.py | 0 .../test_lib2to3}/data/py2_test_grammar.py | 0 .../test_lib2to3}/data/py3_test_grammar.py | 0 .../test_lib2to3}/pytree_idempotency.py | 6 +- .../tests => test/test_lib2to3}/support.py | 21 +++++-- .../test_lib2to3}/test_all_fixers.py | 0 .../test_lib2to3}/test_fixers.py | 12 ++-- .../tests => test/test_lib2to3}/test_main.py | 0 .../test_lib2to3}/test_parser.py | 2 +- .../test_lib2to3}/test_pytree.py | 0 .../test_lib2to3}/test_refactor.py | 0 .../tests => test/test_lib2to3}/test_util.py | 0 Mac/BuildScript/scripts/postflight.framework | 4 +- Makefile.pre.in | 14 ++--- PCbuild/lib.pyproj | 63 +++++++++---------- Tools/peg_generator/Makefile | 2 +- Tools/peg_generator/scripts/benchmark.py | 2 +- Tools/scripts/generate_stdlib_module_names.py | 1 - 35 files changed, 68 insertions(+), 68 deletions(-) delete mode 100644 Lib/test/test_lib2to3.py rename Lib/{lib2to3/tests => test/test_lib2to3}/__init__.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/__main__.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/README (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/bom.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/crlf.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/different_encoding.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/false_encoding.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/fixers/bad_order.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/fixers/myfixes/__init__.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/fixers/myfixes/fix_explicit.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/fixers/myfixes/fix_first.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/fixers/myfixes/fix_last.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/fixers/myfixes/fix_parrot.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/fixers/myfixes/fix_preorder.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/fixers/no_fixer_cls.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/fixers/parrot_example.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/infinite_recursion.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/py2_test_grammar.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/data/py3_test_grammar.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/pytree_idempotency.py (96%) rename Lib/{lib2to3/tests => test/test_lib2to3}/support.py (77%) rename Lib/{lib2to3/tests => test/test_lib2to3}/test_all_fixers.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/test_fixers.py (99%) rename Lib/{lib2to3/tests => test/test_lib2to3}/test_main.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/test_parser.py (99%) rename Lib/{lib2to3/tests => test/test_lib2to3}/test_pytree.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/test_refactor.py (100%) rename Lib/{lib2to3/tests => test/test_lib2to3}/test_util.py (100%) diff --git a/Lib/test/test_lib2to3.py b/Lib/test/test_lib2to3.py deleted file mode 100644 index 6ea8aa4a56e..00000000000 --- a/Lib/test/test_lib2to3.py +++ /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() diff --git a/Lib/lib2to3/tests/__init__.py b/Lib/test/test_lib2to3/__init__.py similarity index 100% rename from Lib/lib2to3/tests/__init__.py rename to Lib/test/test_lib2to3/__init__.py diff --git a/Lib/lib2to3/tests/__main__.py b/Lib/test/test_lib2to3/__main__.py similarity index 100% rename from Lib/lib2to3/tests/__main__.py rename to Lib/test/test_lib2to3/__main__.py diff --git a/Lib/lib2to3/tests/data/README b/Lib/test/test_lib2to3/data/README similarity index 100% rename from Lib/lib2to3/tests/data/README rename to Lib/test/test_lib2to3/data/README diff --git a/Lib/lib2to3/tests/data/bom.py b/Lib/test/test_lib2to3/data/bom.py similarity index 100% rename from Lib/lib2to3/tests/data/bom.py rename to Lib/test/test_lib2to3/data/bom.py diff --git a/Lib/lib2to3/tests/data/crlf.py b/Lib/test/test_lib2to3/data/crlf.py similarity index 100% rename from Lib/lib2to3/tests/data/crlf.py rename to Lib/test/test_lib2to3/data/crlf.py diff --git a/Lib/lib2to3/tests/data/different_encoding.py b/Lib/test/test_lib2to3/data/different_encoding.py similarity index 100% rename from Lib/lib2to3/tests/data/different_encoding.py rename to Lib/test/test_lib2to3/data/different_encoding.py diff --git a/Lib/lib2to3/tests/data/false_encoding.py b/Lib/test/test_lib2to3/data/false_encoding.py similarity index 100% rename from Lib/lib2to3/tests/data/false_encoding.py rename to Lib/test/test_lib2to3/data/false_encoding.py diff --git a/Lib/lib2to3/tests/data/fixers/bad_order.py b/Lib/test/test_lib2to3/data/fixers/bad_order.py similarity index 100% rename from Lib/lib2to3/tests/data/fixers/bad_order.py rename to Lib/test/test_lib2to3/data/fixers/bad_order.py diff --git a/Lib/lib2to3/tests/data/fixers/myfixes/__init__.py b/Lib/test/test_lib2to3/data/fixers/myfixes/__init__.py similarity index 100% rename from Lib/lib2to3/tests/data/fixers/myfixes/__init__.py rename to Lib/test/test_lib2to3/data/fixers/myfixes/__init__.py diff --git a/Lib/lib2to3/tests/data/fixers/myfixes/fix_explicit.py b/Lib/test/test_lib2to3/data/fixers/myfixes/fix_explicit.py similarity index 100% rename from Lib/lib2to3/tests/data/fixers/myfixes/fix_explicit.py rename to Lib/test/test_lib2to3/data/fixers/myfixes/fix_explicit.py diff --git a/Lib/lib2to3/tests/data/fixers/myfixes/fix_first.py b/Lib/test/test_lib2to3/data/fixers/myfixes/fix_first.py similarity index 100% rename from Lib/lib2to3/tests/data/fixers/myfixes/fix_first.py rename to Lib/test/test_lib2to3/data/fixers/myfixes/fix_first.py diff --git a/Lib/lib2to3/tests/data/fixers/myfixes/fix_last.py b/Lib/test/test_lib2to3/data/fixers/myfixes/fix_last.py similarity index 100% rename from Lib/lib2to3/tests/data/fixers/myfixes/fix_last.py rename to Lib/test/test_lib2to3/data/fixers/myfixes/fix_last.py diff --git a/Lib/lib2to3/tests/data/fixers/myfixes/fix_parrot.py b/Lib/test/test_lib2to3/data/fixers/myfixes/fix_parrot.py similarity index 100% rename from Lib/lib2to3/tests/data/fixers/myfixes/fix_parrot.py rename to Lib/test/test_lib2to3/data/fixers/myfixes/fix_parrot.py diff --git a/Lib/lib2to3/tests/data/fixers/myfixes/fix_preorder.py b/Lib/test/test_lib2to3/data/fixers/myfixes/fix_preorder.py similarity index 100% rename from Lib/lib2to3/tests/data/fixers/myfixes/fix_preorder.py rename to Lib/test/test_lib2to3/data/fixers/myfixes/fix_preorder.py diff --git a/Lib/lib2to3/tests/data/fixers/no_fixer_cls.py b/Lib/test/test_lib2to3/data/fixers/no_fixer_cls.py similarity index 100% rename from Lib/lib2to3/tests/data/fixers/no_fixer_cls.py rename to Lib/test/test_lib2to3/data/fixers/no_fixer_cls.py diff --git a/Lib/lib2to3/tests/data/fixers/parrot_example.py b/Lib/test/test_lib2to3/data/fixers/parrot_example.py similarity index 100% rename from Lib/lib2to3/tests/data/fixers/parrot_example.py rename to Lib/test/test_lib2to3/data/fixers/parrot_example.py diff --git a/Lib/lib2to3/tests/data/infinite_recursion.py b/Lib/test/test_lib2to3/data/infinite_recursion.py similarity index 100% rename from Lib/lib2to3/tests/data/infinite_recursion.py rename to Lib/test/test_lib2to3/data/infinite_recursion.py diff --git a/Lib/lib2to3/tests/data/py2_test_grammar.py b/Lib/test/test_lib2to3/data/py2_test_grammar.py similarity index 100% rename from Lib/lib2to3/tests/data/py2_test_grammar.py rename to Lib/test/test_lib2to3/data/py2_test_grammar.py diff --git a/Lib/lib2to3/tests/data/py3_test_grammar.py b/Lib/test/test_lib2to3/data/py3_test_grammar.py similarity index 100% rename from Lib/lib2to3/tests/data/py3_test_grammar.py rename to Lib/test/test_lib2to3/data/py3_test_grammar.py diff --git a/Lib/lib2to3/tests/pytree_idempotency.py b/Lib/test/test_lib2to3/pytree_idempotency.py similarity index 96% rename from Lib/lib2to3/tests/pytree_idempotency.py rename to Lib/test/test_lib2to3/pytree_idempotency.py index 2e7e9781d42..eb2e2aa02ae 100755 --- a/Lib/lib2to3/tests/pytree_idempotency.py +++ b/Lib/test/test_lib2to3/pytree_idempotency.py @@ -17,9 +17,9 @@ 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() diff --git a/Lib/lib2to3/tests/support.py b/Lib/test/test_lib2to3/support.py similarity index 77% rename from Lib/lib2to3/tests/support.py rename to Lib/test/test_lib2to3/support.py index fe084e8903f..9e56273e959 100644 --- a/Lib/lib2to3/tests/support.py +++ b/Lib/test/test_lib2to3/support.py @@ -8,12 +8,14 @@ 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 diff --git a/Lib/lib2to3/tests/test_all_fixers.py b/Lib/test/test_lib2to3/test_all_fixers.py similarity index 100% rename from Lib/lib2to3/tests/test_all_fixers.py rename to Lib/test/test_lib2to3/test_all_fixers.py diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/test/test_lib2to3/test_fixers.py similarity index 99% rename from Lib/lib2to3/tests/test_fixers.py rename to Lib/test/test_lib2to3/test_fixers.py index 121ebe68e54..68efeee7abb 100644 --- a/Lib/lib2to3/tests/test_fixers.py +++ b/Lib/test/test_lib2to3/test_fixers.py @@ -7,7 +7,7 @@ # 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 @@ def f(): 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 @@ def test_multiple_imports_as(self): 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 @@ def test_after_local_imports_refactoring(self): 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(): diff --git a/Lib/lib2to3/tests/test_main.py b/Lib/test/test_lib2to3/test_main.py similarity index 100% rename from Lib/lib2to3/tests/test_main.py rename to Lib/test/test_lib2to3/test_main.py diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/test/test_lib2to3/test_parser.py similarity index 99% rename from Lib/lib2to3/tests/test_parser.py rename to Lib/test/test_lib2to3/test_parser.py index 8e7773bcae1..2c798b181fd 100644 --- a/Lib/lib2to3/tests/test_parser.py +++ b/Lib/test/test_lib2to3/test_parser.py @@ -26,7 +26,7 @@ # 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 diff --git a/Lib/lib2to3/tests/test_pytree.py b/Lib/test/test_lib2to3/test_pytree.py similarity index 100% rename from Lib/lib2to3/tests/test_pytree.py rename to Lib/test/test_lib2to3/test_pytree.py diff --git a/Lib/lib2to3/tests/test_refactor.py b/Lib/test/test_lib2to3/test_refactor.py similarity index 100% rename from Lib/lib2to3/tests/test_refactor.py rename to Lib/test/test_lib2to3/test_refactor.py diff --git a/Lib/lib2to3/tests/test_util.py b/Lib/test/test_lib2to3/test_util.py similarity index 100% rename from Lib/lib2to3/tests/test_util.py rename to Lib/test/test_lib2to3/test_util.py diff --git a/Mac/BuildScript/scripts/postflight.framework b/Mac/BuildScript/scripts/postflight.framework index 0f2e52c4ca1..a63909358f1 100755 --- a/Mac/BuildScript/scripts/postflight.framework +++ b/Mac/BuildScript/scripts/postflight.framework @@ -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 \ diff --git a/Makefile.pre.in b/Makefile.pre.in index 95424da59db..6448785c280 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -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 \ diff --git a/PCbuild/lib.pyproj b/PCbuild/lib.pyproj index f3f44d1d8ff..2355eb5486f 100644 --- a/PCbuild/lib.pyproj +++ b/PCbuild/lib.pyproj @@ -561,33 +561,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1157,7 +1130,33 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1743,10 +1742,6 @@ - - - - @@ -1802,6 +1797,10 @@ + + + + diff --git a/Tools/peg_generator/Makefile b/Tools/peg_generator/Makefile index d010f19d588..084da154919 100644 --- a/Tools/peg_generator/Makefile +++ b/Tools/peg_generator/Makefile @@ -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 diff --git a/Tools/peg_generator/scripts/benchmark.py b/Tools/peg_generator/scripts/benchmark.py index 4a063bf1003..053f8ef06d4 100644 --- a/Tools/peg_generator/scripts/benchmark.py +++ b/Tools/peg_generator/scripts/benchmark.py @@ -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], diff --git a/Tools/scripts/generate_stdlib_module_names.py b/Tools/scripts/generate_stdlib_module_names.py index fe1e429ebce..6f864c317da 100644 --- a/Tools/scripts/generate_stdlib_module_names.py +++ b/Tools/scripts/generate_stdlib_module_names.py @@ -35,7 +35,6 @@ '_xxtestfuzz', 'distutils.tests', 'idlelib.idle_test', - 'lib2to3.tests', 'test', 'xxlimited', 'xxlimited_35',