Skip to content

Commit 616fa34

Browse files
authoredJun 21, 2022
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.
1 parent 50ebd72 commit 616fa34

35 files changed

+68
-68
lines changed
 

‎Lib/test/test_lib2to3.py

-9
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎Lib/lib2to3/tests/pytree_idempotency.py ‎Lib/test/test_lib2to3/pytree_idempotency.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import logging
1818

1919
# Local imports
20-
from .. import pytree
21-
from .. import pgen2
22-
from ..pgen2 import driver
20+
from lib2to3 import pytree
21+
from lib2to3 import pgen2
22+
from lib2to3.pgen2 import driver
2323

2424
logging.basicConfig()
2525

‎Lib/lib2to3/tests/support.py ‎Lib/test/test_lib2to3/support.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
from textwrap import dedent
99

1010
# Local imports
11+
import lib2to3
1112
from lib2to3 import pytree, refactor
1213
from lib2to3.pgen2 import driver as pgen2_driver
1314

15+
lib2to3_dir = os.path.dirname(lib2to3.__file__)
1416
test_dir = os.path.dirname(__file__)
1517
proj_dir = os.path.normpath(os.path.join(test_dir, ".."))
16-
grammar_path = os.path.join(test_dir, "..", "Grammar.txt")
Has a conversation. Original line has a conversation.
18+
grammar_path = os.path.join(lib2to3_dir, "Grammar.txt")
1719
grammar = pgen2_driver.load_grammar(grammar_path)
1820
grammar_no_print_statement = pgen2_driver.load_grammar(grammar_path)
1921
del grammar_no_print_statement.keywords["print"]
@@ -49,10 +51,19 @@ def get_refactorer(fixer_pkg="lib2to3", fixers=None, options=None):
4951
options = options or {}
5052
return refactor.RefactoringTool(fixers, options, explicit=True)
5153

52-
def all_project_files():
53-
for dirpath, dirnames, filenames in os.walk(proj_dir):
54+
def _all_project_files(root, files):
55+
for dirpath, dirnames, filenames in os.walk(root):
5456
for filename in filenames:
55-
if filename.endswith(".py"):
56-
yield os.path.join(dirpath, filename)
57+
if not filename.endswith(".py"):
58+
continue
59+
files.append(os.path.join(dirpath, filename))
60+
61+
def all_project_files():
62+
files = []
63+
_all_project_files(lib2to3_dir, files)
64+
_all_project_files(test_dir, files)
65+
# Sort to get more reproducible tests
66+
files.sort()
67+
return files
5768

5869
TestCase = unittest.TestCase
File renamed without changes.

‎Lib/lib2to3/tests/test_fixers.py ‎Lib/test/test_lib2to3/test_fixers.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# Local imports
99
from lib2to3 import pygram, fixer_util
10-
from lib2to3.tests import support
10+
from test.test_lib2to3 import support
1111

1212

1313
class FixerTestCase(support.TestCase):
@@ -1791,7 +1791,7 @@ def f():
17911791

17921792
class Test_imports(FixerTestCase, ImportsFixerTests):
17931793
fixer = "imports"
1794-
from ..fixes.fix_imports import MAPPING as modules
1794+
from lib2to3.fixes.fix_imports import MAPPING as modules
17951795

17961796
def test_multiple_imports(self):
17971797
b = """import urlparse, cStringIO"""
@@ -1812,16 +1812,16 @@ def test_multiple_imports_as(self):
18121812

18131813
class Test_imports2(FixerTestCase, ImportsFixerTests):
18141814
fixer = "imports2"
1815-
from ..fixes.fix_imports2 import MAPPING as modules
1815+
from lib2to3.fixes.fix_imports2 import MAPPING as modules
18161816

18171817

18181818
class Test_imports_fixer_order(FixerTestCase, ImportsFixerTests):
18191819

18201820
def setUp(self):
18211821
super(Test_imports_fixer_order, self).setUp(['imports', 'imports2'])
1822-
from ..fixes.fix_imports2 import MAPPING as mapping2
1822+
from lib2to3.fixes.fix_imports2 import MAPPING as mapping2
18231823
self.modules = mapping2.copy()
1824-
from ..fixes.fix_imports import MAPPING as mapping1
1824+
from lib2to3.fixes.fix_imports import MAPPING as mapping1
18251825
for key in ('dbhash', 'dumbdbm', 'dbm', 'gdbm'):
18261826
self.modules[key] = mapping1[key]
18271827

@@ -1833,7 +1833,7 @@ def test_after_local_imports_refactoring(self):
18331833

18341834
class Test_urllib(FixerTestCase):
18351835
fixer = "urllib"
1836-
from ..fixes.fix_urllib import MAPPING as modules
1836+
from lib2to3.fixes.fix_urllib import MAPPING as modules
18371837

18381838
def test_import_module(self):
18391839
for old, changes in self.modules.items():
File renamed without changes.

‎Lib/lib2to3/tests/test_parser.py ‎Lib/test/test_lib2to3/test_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# Local imports
2727
from lib2to3.pgen2 import driver as pgen2_driver
2828
from lib2to3.pgen2 import tokenize
29-
from ..pgen2.parse import ParseError
29+
from lib2to3.pgen2.parse import ParseError
3030
from lib2to3.pygram import python_symbols as syms
3131

3232

File renamed without changes.
File renamed without changes.
File renamed without changes.

‎Mac/BuildScript/scripts/postflight.framework

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ FWK="/Library/Frameworks/Python.framework/Versions/@PYVER@"
88

99
"${FWK}/bin/python@PYVER@" -E -s -Wi \
1010
"${FWK}/lib/python${PYVER}/compileall.py" -q -j0 \
11-
-f -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
11+
-f -x 'bad_coding|badsyntax|site-packages|test/test_lib2to3/data' \
1212
"${FWK}/lib/python${PYVER}"
1313

1414
"${FWK}/bin/python@PYVER@" -E -s -Wi -O \
1515
"${FWK}/lib/python${PYVER}/compileall.py" -q -j0 \
16-
-f -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
16+
-f -x 'bad_coding|badsyntax|site-packages|test/test_lib2to3/data' \
1717
"${FWK}/lib/python${PYVER}"
1818

1919
"${FWK}/bin/python@PYVER@" -E -s -Wi \

‎Makefile.pre.in

+7-7
Original file line numberDiff line numberDiff line change
@@ -1921,10 +1921,6 @@ LIBSUBDIRS= asyncio \
19211921
__phello__
19221922
TESTSUBDIRS= distutils/tests \
19231923
idlelib/idle_test \
1924-
lib2to3/tests \
1925-
lib2to3/tests/data \
1926-
lib2to3/tests/data/fixers \
1927-
lib2to3/tests/data/fixers/myfixes \
19281924
test test/audiodata \
19291925
test/capath test/cjkencodings \
19301926
test/data test/decimaltestdata \
@@ -1986,6 +1982,10 @@ TESTSUBDIRS= distutils/tests \
19861982
test/test_importlib/zipdata01 \
19871983
test/test_importlib/zipdata02 \
19881984
test/test_json \
1985+
test/test_lib2to3 \
1986+
test/test_lib2to3/data \
1987+
test/test_lib2to3/data/fixers \
1988+
test/test_lib2to3/data/fixers/myfixes \
19891989
test/test_peg_generator \
19901990
test/test_tools \
19911991
test/test_warnings test/test_warnings/data \
@@ -2073,17 +2073,17 @@ libinstall: all $(srcdir)/Modules/xxmodule.c
20732073
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
20742074
$(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
20752075
-j0 -d $(LIBDEST) -f \
2076-
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
2076+
-x 'bad_coding|badsyntax|site-packages|test/test_lib2to3/data' \
20772077
$(DESTDIR)$(LIBDEST)
20782078
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
20792079
$(PYTHON_FOR_BUILD) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \
20802080
-j0 -d $(LIBDEST) -f \
2081-
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
2081+
-x 'bad_coding|badsyntax|site-packages|test/test_lib2to3/data' \
20822082
$(DESTDIR)$(LIBDEST)
20832083
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
20842084
$(PYTHON_FOR_BUILD) -Wi -OO $(DESTDIR)$(LIBDEST)/compileall.py \
20852085
-j0 -d $(LIBDEST) -f \
2086-
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
2086+
-x 'bad_coding|badsyntax|site-packages|test/test_lib2to3/data' \
20872087
$(DESTDIR)$(LIBDEST)
20882088
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
20892089
$(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \

‎PCbuild/lib.pyproj

+31-32
Original file line numberDiff line numberDiff line change
@@ -561,33 +561,6 @@
561561
<Compile Include="lib2to3\pygram.py" />
562562
<Compile Include="lib2to3\pytree.py" />
563563
<Compile Include="lib2to3\refactor.py" />
564-
<Compile Include="lib2to3\tests\data\bom.py" />
565-
<Compile Include="lib2to3\tests\data\crlf.py" />
566-
<Compile Include="lib2to3\tests\data\different_encoding.py" />
567-
<Compile Include="lib2to3\tests\data\false_encoding.py" />
568-
<Compile Include="lib2to3\tests\data\fixers\bad_order.py" />
569-
<Compile Include="lib2to3\tests\data\fixers\myfixes\fix_explicit.py" />
570-
<Compile Include="lib2to3\tests\data\fixers\myfixes\fix_first.py" />
571-
<Compile Include="lib2to3\tests\data\fixers\myfixes\fix_last.py" />
572-
<Compile Include="lib2to3\tests\data\fixers\myfixes\fix_parrot.py" />
573-
<Compile Include="lib2to3\tests\data\fixers\myfixes\fix_preorder.py" />
574-
<Compile Include="lib2to3\tests\data\fixers\myfixes\__init__.py" />
575-
<Compile Include="lib2to3\tests\data\fixers\no_fixer_cls.py" />
576-
<Compile Include="lib2to3\tests\data\fixers\parrot_example.py" />
577-
<Compile Include="lib2to3\tests\data\infinite_recursion.py" />
578-
<Compile Include="lib2to3\tests\data\py2_test_grammar.py" />
579-
<Compile Include="lib2to3\tests\data\py3_test_grammar.py" />
580-
<Compile Include="lib2to3\tests\pytree_idempotency.py" />
581-
<Compile Include="lib2to3\tests\support.py" />
582-
<Compile Include="lib2to3\tests\test_all_fixers.py" />
583-
<Compile Include="lib2to3\tests\test_fixers.py" />
584-
<Compile Include="lib2to3\tests\test_main.py" />
585-
<Compile Include="lib2to3\tests\test_parser.py" />
586-
<Compile Include="lib2to3\tests\test_pytree.py" />
587-
<Compile Include="lib2to3\tests\test_refactor.py" />
588-
<Compile Include="lib2to3\tests\test_util.py" />
589-
<Compile Include="lib2to3\tests\__init__.py" />
590-
<Compile Include="lib2to3\tests\__main__.py" />
591564
<Compile Include="lib2to3\__init__.py" />
592565
<Compile Include="lib2to3\__main__.py" />
593566
<Compile Include="linecache.py" />
@@ -1157,7 +1130,33 @@
11571130
<Compile Include="test\test_keywordonlyarg.py" />
11581131
<Compile Include="test\test_kqueue.py" />
11591132
<Compile Include="test\test_largefile.py" />
1160-
<Compile Include="test\test_lib2to3.py" />
1133+
<Compile Include="test\test_lib2to3\data\bom.py" />
1134+
<Compile Include="test\test_lib2to3\data\crlf.py" />
1135+
<Compile Include="test\test_lib2to3\data\different_encoding.py" />
1136+
<Compile Include="test\test_lib2to3\data\false_encoding.py" />
1137+
<Compile Include="test\test_lib2to3\data\fixers\bad_order.py" />
1138+
<Compile Include="test\test_lib2to3\data\fixers\myfixes\fix_explicit.py" />
1139+
<Compile Include="test\test_lib2to3\data\fixers\myfixes\fix_first.py" />
1140+
<Compile Include="test\test_lib2to3\data\fixers\myfixes\fix_last.py" />
1141+
<Compile Include="test\test_lib2to3\data\fixers\myfixes\fix_parrot.py" />
1142+
<Compile Include="test\test_lib2to3\data\fixers\myfixes\fix_preorder.py" />
1143+
<Compile Include="test\test_lib2to3\data\fixers\myfixes\__init__.py" />
1144+
<Compile Include="test\test_lib2to3\data\fixers\no_fixer_cls.py" />
1145+
<Compile Include="test\test_lib2to3\data\fixers\parrot_example.py" />
1146+
<Compile Include="test\test_lib2to3\data\infinite_recursion.py" />
1147+
<Compile Include="test\test_lib2to3\data\py2_test_grammar.py" />
1148+
<Compile Include="test\test_lib2to3\data\py3_test_grammar.py" />
1149+
<Compile Include="test\test_lib2to3\pytree_idempotency.py" />
1150+
<Compile Include="test\test_lib2to3\support.py" />
1151+
<Compile Include="test\test_lib2to3\test_all_fixers.py" />
1152+
<Compile Include="test\test_lib2to3\test_fixers.py" />
1153+
<Compile Include="test\test_lib2to3\test_main.py" />
1154+
<Compile Include="test\test_lib2to3\test_parser.py" />
1155+
<Compile Include="test\test_lib2to3\test_pytree.py" />
1156+
<Compile Include="test\test_lib2to3\test_refactor.py" />
1157+
<Compile Include="test\test_lib2to3\test_util.py" />
1158+
<Compile Include="test\test_lib2to3\__init__.py" />
1159+
<Compile Include="test\test_lib2to3\__main__.py" />
11611160
<Compile Include="test\test_linecache.py" />
11621161
<Compile Include="test\test_list.py" />
11631162
<Compile Include="test\test_listcomps.py" />
@@ -1743,10 +1742,6 @@
17431742
<Folder Include="lib2to3" />
17441743
<Folder Include="lib2to3\fixes" />
17451744
<Folder Include="lib2to3\pgen2" />
1746-
<Folder Include="lib2to3\tests" />
1747-
<Folder Include="lib2to3\tests\data" />
1748-
<Folder Include="lib2to3\tests\data\fixers" />
1749-
<Folder Include="lib2to3\tests\data\fixers\myfixes" />
17501745
<Folder Include="logging" />
17511746
<Folder Include="msilib" />
17521747
<Folder Include="multiprocessing" />
@@ -1802,6 +1797,10 @@
18021797
<Folder Include="test\test_import\data\package" />
18031798
<Folder Include="test\test_import\data\package2" />
18041799
<Folder Include="test\test_json" />
1800+
<Folder Include="test\test_lib2to3" />
1801+
<Folder Include="test\test_lib2to3\data" />
1802+
<Folder Include="test\test_lib2to3\data\fixers" />
1803+
<Folder Include="test\test_lib2to3\data\fixers\myfixes" />
18051804
<Folder Include="test\test_peg_generator" />
18061805
<Folder Include="test\test_tools" />
18071806
<Folder Include="test\test_unittest" />

‎Tools/peg_generator/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ time_stdlib: $(CPYTHON) venv
8888
-d $(CPYTHON) \
8989
$(TESTFLAGS) \
9090
--exclude "*/bad*" \
91-
--exclude "*/lib2to3/tests/data/*"
91+
--exclude "*/test/test_lib2to3/data/*"
9292

9393
mypy: regen-metaparser
9494
$(MYPY) # For list of files, see mypy.ini

‎Tools/peg_generator/scripts/benchmark.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def run_benchmark_stdlib(subcommand):
7878
verbose=False,
7979
excluded_files=[
8080
"*/bad*",
81-
"*/lib2to3/tests/data/*",
81+
"*/test/test_lib2to3/data/*",
8282
],
8383
short=True,
8484
mode=modes[subcommand],

‎Tools/scripts/generate_stdlib_module_names.py

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
'_xxtestfuzz',
3636
'distutils.tests',
3737
'idlelib.idle_test',
38-
'lib2to3.tests',
3938
'test',
4039
'xxlimited',
4140
'xxlimited_35',

0 commit comments

Comments
 (0)
Please sign in to comment.