Cleanup regrtest "main()" function
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 24 Mar 2016 16:53:20 +0000 (17:53 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 24 Mar 2016 16:53:20 +0000 (17:53 +0100)
* Rename libregrtest.main_in_temp_cwd() to libregrtest.main()
* Add regrtest.main_in_temp_cwd() alias to libregrtest.main()
* Move old main_in_temp_cwd() code into libregrtest.Regrtest.main()
* Update multiple scripts to call libregrtest.main()

Lib/test/__main__.py
Lib/test/autotest.py
Lib/test/libregrtest/__init__.py
Lib/test/libregrtest/main.py
Lib/test/regrtest.py
Lib/test/test_importlib/regrtest.py
PC/testpy.py

index d5fbe159d735b269e890355afab8a621319a35ea..19a6b2b8904526ace5ada89879ac66810676b321 100644 (file)
@@ -1,3 +1,2 @@
-from test import regrtest
-
-regrtest.main_in_temp_cwd()
+from test.libregrtest import main
+main()
index 41c2088727e8aad86d35368bd559fee7779ad0c8..fa85cc153a133aaac6a7bdeda496a92f4d2bcee1 100644 (file)
@@ -1,6 +1,5 @@
 # This should be equivalent to running regrtest.py from the cmdline.
 # It can be especially handy if you're in an interactive shell, e.g.,
 # from test import autotest.
-
-from test import regrtest
-regrtest.main()
+from test.libregrtest import main
+main()
index 9f7b1c1fe25f5d9897c46617ffbe2c0d23e47de3..7ba0e6e5356166134501a934efd6827b30e05272 100644 (file)
@@ -1,2 +1,5 @@
+# We import importlib *ASAP* in order to test #15386
+import importlib
+
 from test.libregrtest.cmdline import _parse_args, RESOURCE_NAMES
-from test.libregrtest.main import main, main_in_temp_cwd
+from test.libregrtest.main import main
index c6d9ad05bc9f95a21df9559651247ec0f3220d92..e1367da381652e5ec91b28edaee6f4f9f1ae335f 100644 (file)
@@ -415,6 +415,28 @@ class Regrtest:
             os.system("leaks %d" % os.getpid())
 
     def main(self, tests=None, **kwargs):
+        global TEMPDIR
+
+        if sysconfig.is_python_build():
+            try:
+                os.mkdir(TEMPDIR)
+            except FileExistsError:
+                pass
+
+        # Define a writable temp dir that will be used as cwd while running
+        # the tests. The name of the dir includes the pid to allow parallel
+        # testing (see the -j option).
+        test_cwd = 'test_python_{}'.format(os.getpid())
+        test_cwd = os.path.join(TEMPDIR, test_cwd)
+
+        # Run the tests in a context manager that temporarily changes the CWD to a
+        # temporary and writable directory.  If it's not possible to create or
+        # change the CWD, the original CWD will be used.  The original CWD is
+        # available from support.SAVEDCWD.
+        with support.temp_cwd(test_cwd, quiet=True):
+            self._main(tests, kwargs)
+
+    def _main(self, tests, kwargs):
         self.ns = self.parse_args(kwargs)
 
         if self.ns.slaveargs is not None:
@@ -473,26 +495,5 @@ def printlist(x, width=70, indent=4):
 
 
 def main(tests=None, **kwargs):
+    """Run the Python suite."""
     Regrtest().main(tests=tests, **kwargs)
-
-
-def main_in_temp_cwd():
-    """Run main() in a temporary working directory."""
-    if sysconfig.is_python_build():
-        try:
-            os.mkdir(TEMPDIR)
-        except FileExistsError:
-            pass
-
-    # Define a writable temp dir that will be used as cwd while running
-    # the tests. The name of the dir includes the pid to allow parallel
-    # testing (see the -j option).
-    test_cwd = 'test_python_{}'.format(os.getpid())
-    test_cwd = os.path.join(TEMPDIR, test_cwd)
-
-    # Run the tests in a context manager that temporarily changes the CWD to a
-    # temporary and writable directory.  If it's not possible to create or
-    # change the CWD, the original CWD will be used.  The original CWD is
-    # available from support.SAVEDCWD.
-    with support.temp_cwd(test_cwd, quiet=True):
-        main()
index 9cbb92610923191447ff02b39aca1e083c2243f9..21b0edfd073d6e3c3e218d2ef7629c0359e2089a 100644 (file)
@@ -11,11 +11,11 @@ import importlib
 
 import os
 import sys
-from test.libregrtest import main_in_temp_cwd
+from test.libregrtest import main
 
 
-# alias needed by other scripts
-main = main_in_temp_cwd
+# Alias for backward compatibility (just in case)
+main_in_temp_cwd = main
 
 
 def _main():
index a5be11fd4ee5ddd87ce36d90723b5a00338fb225..98c815c191f39178c0c17d37469a2e77266d7476 100644 (file)
@@ -8,10 +8,10 @@ this script.
 """
 import importlib
 import sys
-from test import regrtest
+from test import libregrtest
 
 if __name__ == '__main__':
     __builtins__.__import__ = importlib.__import__
     sys.path_importer_cache.clear()
 
-    regrtest.main(quiet=True, verbose2=True)
+    libregrtest.main(quiet=True, verbose2=True)
index 4ef3d4f793df202c0bbe593b3a5d0fc0d9027c63..709f35c4525877275269703f23974aa0727661aa 100644 (file)
@@ -26,5 +26,5 @@ for dir in sys.path:
             # Add the "test" directory to PYTHONPATH.
             sys.path = sys.path + [test]
 
-import regrtest # Standard Python tester.
-regrtest.main()
+import libregrtest # Standard Python tester.
+libregrtest.main()