diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-06 11:43:55 (GMT) |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-06 11:43:55 (GMT) |
commit | da7bfd5b1df98d93b20c8c354f0daf624ad8058a (patch) | |
tree | a3db843c58cfc305df6fbb818ab3351dde79afe4 | |
parent | 29ef5c9a375a5b0f29f409ca19a817b499d23905 (diff) | |
download | cpython-da7bfd5b1df98d93b20c8c354f0daf624ad8058a.zip cpython-da7bfd5b1df98d93b20c8c354f0daf624ad8058a.tar.gz cpython-da7bfd5b1df98d93b20c8c354f0daf624ad8058a.tar.bz2 |
Merged revisions 78719-78720 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78719 | florent.xicluna | 2010-03-06 09:07:44 +0100 (sam, 06 mar 2010) | 3 lines
Keep the test files in the ./build/ subdirectory, if Python is not installed.
Remove two hacks which are no longer needed after #7712, because all __file__ attributes are absolute.
........
r78720 | florent.xicluna | 2010-03-06 10:11:55 +0100 (sam, 06 mar 2010) | 2 lines
Print platform information to stdout, to help troubleshooting platform-specific failures.
........
-rwxr-xr-x | Lib/test/regrtest.py | 88 |
1 files changed, 42 insertions, 46 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 33a2248..c2a279f 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -159,6 +159,8 @@ import warnings import unittest from inspect import isabstract import tempfile +import platform +import sysconfig # Some times __path__ and __file__ are not absolute (e.g. while running from # Lib/) and, if we change the CWD to run the tests in a temporary dir, some @@ -386,6 +388,9 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, usage(2, "-T and -j don't go together!") if use_mp and findleaks: usage(2, "-l and -j don't go together!") + if use_mp and max(sys.flags): + # TODO: inherit the environment and the flags + print("Warning: flags and environment variables are ignored with -j option") good = [] bad = [] @@ -393,8 +398,11 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, resource_denieds = [] environment_changed = [] - if verbose: - print('The CWD is now', os.getcwd()) + if not quiet: + # Print basic platform information + print("==", platform.python_implementation(), *sys.version.split()) + print("== ", platform.platform(aliased=True)) + print("== ", os.getcwd()) if findleaks: try: @@ -429,10 +437,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, fp.close() # Strip .py extensions. - if args: - args = list(map(removepy, args)) - if tests: - tests = list(map(removepy, tests)) + removepy(args) + removepy(tests) stdtests = STDTESTS[:] nottests = NOTTESTS.copy() @@ -698,16 +704,15 @@ NOTTESTS = { def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS): """Return a list of all applicable test modules.""" - if not testdir: testdir = findtestdir() + testdir = findtestdir(testdir) names = os.listdir(testdir) tests = [] + others = set(stdtests) | nottests for name in names: - if name[:5] == "test_" and name[-3:] == ".py": - modname = name[:-3] - if modname not in stdtests and modname not in nottests: - tests.append(modname) - tests.sort() - return stdtests + tests + modname, ext = os.path.splitext(name) + if modname[:5] == "test_" and ext == ".py" and modname not in others: + tests.append(modname) + return stdtests + sorted(tests) def runtest(test, verbose, quiet, testdir=None, huntrleaks=False, debug=False, use_resources=None): @@ -865,8 +870,7 @@ class saved_test_environment: def runtest_inner(test, verbose, quiet, testdir=None, huntrleaks=False, debug=False): support.unload(test) - if not testdir: - testdir = findtestdir() + testdir = findtestdir(testdir) test_time = 0.0 refleak = False # True if the test leaked references. @@ -1087,18 +1091,16 @@ def warm_char_cache(): for i in range(256): s[i:i+1] -def findtestdir(): - if __name__ == '__main__': - file = sys.argv[0] - else: - file = __file__ - testdir = os.path.dirname(file) or os.curdir - return testdir +def findtestdir(path=None): + return path or os.path.dirname(__file__) or os.curdir -def removepy(name): - if name.endswith(".py"): - name = name[:-3] - return name +def removepy(names): + if not names: + return + for idx, name in enumerate(names): + basename, ext = os.path.splitext(name) + if ext == '.py': + names[idx] = basename def count(n, word): if n == 1: @@ -1116,7 +1118,7 @@ def printlist(x, width=70, indent=4): from textwrap import fill blanks = ' ' * indent - print(fill(' '.join(map(str, x)), width, + print(fill(' '.join(str(elt) for elt in x), width, initial_indent=blanks, subsequent_indent=blanks)) # Map sys.platform to a string containing the basenames of tests @@ -1432,31 +1434,25 @@ class _ExpectedSkips: return self.expected if __name__ == '__main__': - # Remove regrtest.py's own directory from the module search path. This - # prevents relative imports from working, and relative imports will screw - # up the testing framework. E.g. if both test.support and - # support are imported, they will not contain the same globals, and - # much of the testing framework relies on the globals in the - # test.support module. - mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0]))) - i = len(sys.path) - while i >= 0: - i -= 1 - if os.path.abspath(os.path.normpath(sys.path[i])) == mydir: - del sys.path[i] - - # findtestdir() gets the dirname out of sys.argv[0], so we have to make it - # absolute before changing the CWD. - if sys.argv[0]: - sys.argv[0] = os.path.abspath(sys.argv[0]) - + # Simplification for findtestdir(). + assert __file__ == os.path.abspath(sys.argv[0]) + + # When tests are run from the Python build directory, it is best practice + # to keep the test files in a subfolder. It eases the cleanup of leftover + # files using command "make distclean". + if sysconfig.is_python_build(): + parent_dir = os.path.join(sysconfig.get_config_var('srcdir'), 'build') + if not os.path.exists(parent_dir): + os.mkdir(parent_dir) + else: + parent_dir = os.path.abspath(tempfile.gettempdir()) # 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). TESTCWD = 'test_python_{}'.format(os.getpid()) - TESTCWD = os.path.abspath(os.path.join(tempfile.gettempdir(), TESTCWD)) + TESTCWD = os.path.join(parent_dir, TESTCWD) # Run the tests in a context manager that temporary changes the CWD to a # temporary and writable directory. If it's not possible to create or |