diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-03-24 16:53:20 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-03-24 16:53:20 (GMT) |
commit | 3aac0adfe01b30fc58c638c5ab61844e80b3fd66 (patch) | |
tree | 5e3691904a971e3b305bc4d2e1b950e6ddef6570 /Lib | |
parent | 8c08e0db8fa47c0c8780607a0d803d4964fdffa6 (diff) | |
download | cpython-3aac0adfe01b30fc58c638c5ab61844e80b3fd66.zip cpython-3aac0adfe01b30fc58c638c5ab61844e80b3fd66.tar.gz cpython-3aac0adfe01b30fc58c638c5ab61844e80b3fd66.tar.bz2 |
Cleanup regrtest "main()" function
* 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()
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/__main__.py | 5 | ||||
-rw-r--r-- | Lib/test/autotest.py | 5 | ||||
-rw-r--r-- | Lib/test/libregrtest/__init__.py | 5 | ||||
-rw-r--r-- | Lib/test/libregrtest/main.py | 45 | ||||
-rw-r--r-- | Lib/test/regrtest.py | 6 | ||||
-rw-r--r-- | Lib/test/test_importlib/regrtest.py | 4 |
6 files changed, 36 insertions, 34 deletions
diff --git a/Lib/test/__main__.py b/Lib/test/__main__.py index d5fbe15..19a6b2b 100644 --- a/Lib/test/__main__.py +++ b/Lib/test/__main__.py @@ -1,3 +1,2 @@ -from test import regrtest - -regrtest.main_in_temp_cwd() +from test.libregrtest import main +main() diff --git a/Lib/test/autotest.py b/Lib/test/autotest.py index 41c2088..fa85cc1 100644 --- a/Lib/test/autotest.py +++ b/Lib/test/autotest.py @@ -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() diff --git a/Lib/test/libregrtest/__init__.py b/Lib/test/libregrtest/__init__.py index 9f7b1c1..7ba0e6e 100644 --- a/Lib/test/libregrtest/__init__.py +++ b/Lib/test/libregrtest/__init__.py @@ -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 diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index c6d9ad0..e1367da 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -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() diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 9cbb926..21b0edf 100644 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -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(): diff --git a/Lib/test/test_importlib/regrtest.py b/Lib/test/test_importlib/regrtest.py index a5be11f..98c815c 100644 --- a/Lib/test/test_importlib/regrtest.py +++ b/Lib/test/test_importlib/regrtest.py @@ -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) |