Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2acbae8

Browse files
committed
Issue #22173: Update lib2to3 tests to use unittest test discovery.
1 parent b7354a6 commit 2acbae8

7 files changed

Lines changed: 19 additions & 38 deletions

File tree

Lib/lib2to3/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Main program for 2to3.
33
"""
44

5-
from __future__ import with_statement
5+
from __future__ import with_statement, print_function
66

77
import sys
88
import os

Lib/lib2to3/tests/__init__.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
"""Make tests/ into a package. This allows us to "import tests" and
2-
have tests.all_tests be a TestSuite representing all test cases
3-
from all test_*.py files in tests/."""
41
# Author: Collin Winter
52

63
import os
7-
import os.path
84
import unittest
9-
import types
105

11-
from . import support
6+
from test.support import load_package_tests
127

13-
all_tests = unittest.TestSuite()
14-
15-
tests_dir = os.path.join(os.path.dirname(__file__), '..', 'tests')
16-
tests = [t[0:-3] for t in os.listdir(tests_dir)
17-
if t.startswith('test_') and t.endswith('.py')]
18-
19-
loader = unittest.TestLoader()
20-
21-
for t in tests:
22-
__import__("",globals(),locals(),[t],level=1)
23-
mod = globals()[t]
24-
all_tests.addTests(loader.loadTestsFromModule(mod))
8+
def load_tests(*args):
9+
return load_package_tests(os.path.dirname(__file__), *args)

Lib/lib2to3/tests/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from . import load_tests
2+
import unittest
3+
4+
unittest.main()

Lib/lib2to3/tests/pytree_idempotency.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
"""Main program for testing the infrastructure."""
66

7+
from __future__ import print_function
8+
79
__author__ = "Guido van Rossum <[email protected]>"
810

911
# Support imports (need to be imported first)

Lib/lib2to3/tests/test_all_fixers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
# Python imports
99
import unittest
10+
import test.support
1011

1112
# Local imports
1213
from lib2to3 import refactor
1314
from . import support
1415

1516

17+
@test.support.requires_resource('cpu')
1618
class Test_all(support.TestCase):
1719

1820
def setUp(self):
@@ -21,3 +23,6 @@ def setUp(self):
2123
def test_all_project_files(self):
2224
for filepath in support.all_project_files():
2325
self.refactor.refactor_file(filepath)
26+
27+
if __name__ == '__main__':
28+
unittest.main()

Lib/test/test_lib2to3.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
# Skipping test_parser and test_all_fixers
2-
# because of running
3-
from lib2to3.tests import (test_fixers, test_pytree, test_util, test_refactor,
4-
test_parser,
5-
test_main as test_main_)
1+
from lib2to3.tests import load_tests
62
import unittest
7-
from test.support import run_unittest
8-
9-
def suite():
10-
tests = unittest.TestSuite()
11-
loader = unittest.TestLoader()
12-
for m in (test_fixers, test_pytree, test_util, test_refactor, test_parser,
13-
test_main_):
14-
tests.addTests(loader.loadTestsFromModule(m))
15-
return tests
16-
17-
def test_main():
18-
run_unittest(suite())
19-
203

214
if __name__ == '__main__':
22-
test_main()
5+
unittest.main()

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ Library
8787
Tests
8888
-----
8989

90+
- Issue #22173: Update lib2to3 tests to use unittest test discovery.
91+
9092
- Issue #16000: Convert test_curses to use unittest.
9193

9294
- Issue #21456: Skip two tests in test_urllib2net.py if _ssl module not

0 commit comments

Comments
 (0)