]> granicus.if.org Git - python/commitdiff
Issue #22173: Update lib2to3 tests to use unittest test discovery.
authorZachary Ware <zachary.ware@gmail.com>
Wed, 29 Oct 2014 17:24:59 +0000 (12:24 -0500)
committerZachary Ware <zachary.ware@gmail.com>
Wed, 29 Oct 2014 17:24:59 +0000 (12:24 -0500)
Lib/lib2to3/main.py
Lib/lib2to3/tests/__init__.py
Lib/lib2to3/tests/__main__.py [new file with mode: 0644]
Lib/lib2to3/tests/pytree_idempotency.py
Lib/lib2to3/tests/test_all_fixers.py
Lib/test/test_lib2to3.py
Misc/NEWS

index 93bae9021a4934d22fc451ac33ca0229005a0e1b..1a1df013ade3ea12806be22dec99785082ae1ccd 100644 (file)
@@ -2,7 +2,7 @@
 Main program for 2to3.
 """
 
-from __future__ import with_statement
+from __future__ import with_statement, print_function
 
 import sys
 import os
index cfaea0de747d87e6ca731597f4f1a4b4bb6cae93..c5166fc94c479311c7de6df86ffae33d24ee7f5a 100644 (file)
@@ -1,24 +1,9 @@
-"""Make tests/ into a package. This allows us to "import tests" and
-have tests.all_tests be a TestSuite representing all test cases
-from all test_*.py files in tests/."""
 # Author: Collin Winter
 
 import os
-import os.path
 import unittest
-import types
 
-from . import support
+from test.support import load_package_tests
 
-all_tests = unittest.TestSuite()
-
-tests_dir = os.path.join(os.path.dirname(__file__), '..', 'tests')
-tests = [t[0:-3] for t in os.listdir(tests_dir)
-                        if t.startswith('test_') and t.endswith('.py')]
-
-loader = unittest.TestLoader()
-
-for t in tests:
-    __import__("",globals(),locals(),[t],level=1)
-    mod = globals()[t]
-    all_tests.addTests(loader.loadTestsFromModule(mod))
+def load_tests(*args):
+    return load_package_tests(os.path.dirname(__file__), *args)
diff --git a/Lib/lib2to3/tests/__main__.py b/Lib/lib2to3/tests/__main__.py
new file mode 100644 (file)
index 0000000..40a23a2
--- /dev/null
@@ -0,0 +1,4 @@
+from . import load_tests
+import unittest
+
+unittest.main()
index 731c4031208f26b226180c96811effd02f25e0ce..c6359bf18a1b34df183954eef962f1b5c3473df0 100755 (executable)
@@ -4,6 +4,8 @@
 
 """Main program for testing the infrastructure."""
 
+from __future__ import print_function
+
 __author__ = "Guido van Rossum <guido@python.org>"
 
 # Support imports (need to be imported first)
index f64b3d942af2f91e3791247436e020c33c111e1b..15079fe0285c8bb7dec16f0e65d9b2bd9e0f3834 100644 (file)
@@ -7,12 +7,14 @@ running time.
 
 # Python imports
 import unittest
+import test.support
 
 # Local imports
 from lib2to3 import refactor
 from . import support
 
 
+@test.support.requires_resource('cpu')
 class Test_all(support.TestCase):
 
     def setUp(self):
@@ -21,3 +23,6 @@ class Test_all(support.TestCase):
     def test_all_project_files(self):
         for filepath in support.all_project_files():
             self.refactor.refactor_file(filepath)
+
+if __name__ == '__main__':
+    unittest.main()
index df4c37b2418d5758eadbf46a2b6f0ef3da88d63b..5eaa5164d490a7b0c9f3d3e8d0e3a48da21a8f50 100644 (file)
@@ -1,22 +1,5 @@
-# Skipping test_parser and test_all_fixers
-# because of running
-from lib2to3.tests import (test_fixers, test_pytree, test_util, test_refactor,
-                           test_parser,
-                           test_main as test_main_)
+from lib2to3.tests import load_tests
 import unittest
-from test.support import run_unittest
-
-def suite():
-    tests = unittest.TestSuite()
-    loader = unittest.TestLoader()
-    for m in (test_fixers, test_pytree, test_util, test_refactor, test_parser,
-              test_main_):
-        tests.addTests(loader.loadTestsFromModule(m))
-    return tests
-
-def test_main():
-    run_unittest(suite())
-
 
 if __name__ == '__main__':
-    test_main()
+    unittest.main()
index 2738699484a965ec55f8f1e5540ab2d2ecd7ac0a..20938600da88d4fbb5967fc068006874a90c89bc 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -87,6 +87,8 @@ Library
 Tests
 -----
 
+- Issue #22173: Update lib2to3 tests to use unittest test discovery.
+
 - Issue #16000: Convert test_curses to use unittest.
 
 - Issue #21456: Skip two tests in test_urllib2net.py if _ssl module not