Kaydet (Commit) 4fde0c40 authored tarafından Benjamin Peterson's avatar Benjamin Peterson

Rolled back revisions 62038 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk
This was incorrectly merged.
üst 2a691a81
...@@ -10,7 +10,6 @@ Command line options: ...@@ -10,7 +10,6 @@ Command line options:
-v: verbose -- run tests in verbose mode with output to stdout -v: verbose -- run tests in verbose mode with output to stdout
-w: verbose2 -- re-run failed tests in verbose mode -w: verbose2 -- re-run failed tests in verbose mode
-d: debug -- print traceback for failed tests
-q: quiet -- don't print anything except if a test fails -q: quiet -- don't print anything except if a test fails
-x: exclude -- arguments are tests to *exclude* -x: exclude -- arguments are tests to *exclude*
-s: single -- run only a single test (see below) -s: single -- run only a single test (see below)
...@@ -27,7 +26,6 @@ Command line options: ...@@ -27,7 +26,6 @@ Command line options:
-L: runleaks -- run the leaks(1) command just before exit -L: runleaks -- run the leaks(1) command just before exit
-R: huntrleaks -- search for reference leaks (needs debug build, v. slow) -R: huntrleaks -- search for reference leaks (needs debug build, v. slow)
-M: memlimit -- run very large memory-consuming tests -M: memlimit -- run very large memory-consuming tests
-n: nowindows -- suppress error message boxes on Windows
If non-option arguments are present, they are names for tests to run, If non-option arguments are present, they are names for tests to run,
unless -x is given, in which case they are names for tests not to run. unless -x is given, in which case they are names for tests not to run.
...@@ -49,12 +47,6 @@ file is missing, the first test_*.py file in testdir or on the command ...@@ -49,12 +47,6 @@ file is missing, the first test_*.py file in testdir or on the command
line is used. (actually tempfile.gettempdir() is used instead of line is used. (actually tempfile.gettempdir() is used instead of
/tmp). /tmp).
-S is used to continue running tests after an aborted run. It will
maintain the order a standard run (ie, this assumes -r is not used).
This is useful after the tests have prematurely stopped for some external
reason and you want to start running from where you left off rather
than starting from the beginning.
-f reads the names of tests from the file given as f's argument, one -f reads the names of tests from the file given as f's argument, one
or more test names per line. Whitespace is ignored. Blank lines and or more test names per line. Whitespace is ignored. Blank lines and
lines beginning with '#' are ignored. This is especially useful for lines beginning with '#' are ignored. This is especially useful for
...@@ -70,7 +62,7 @@ be of the form stab:run:fname where 'stab' is the number of times the ...@@ -70,7 +62,7 @@ be of the form stab:run:fname where 'stab' is the number of times the
test is run to let gettotalrefcount settle down, 'run' is the number test is run to let gettotalrefcount settle down, 'run' is the number
of times further it is run and 'fname' is the name of the file the of times further it is run and 'fname' is the name of the file the
reports are written to. These parameters all have defaults (5, 4 and reports are written to. These parameters all have defaults (5, 4 and
"reflog.txt" respectively), and the minimal invocation is '-R :'. "reflog.txt" respectively), so the minimal invocation is '-R ::'.
-M runs tests that require an exorbitant amount of memory. These tests -M runs tests that require an exorbitant amount of memory. These tests
typically try to ascertain containers keep working when containing more than typically try to ascertain containers keep working when containing more than
...@@ -114,8 +106,11 @@ resources to test. Currently only the following are defined: ...@@ -114,8 +106,11 @@ resources to test. Currently only the following are defined:
decimal - Test the decimal module against a large suite that decimal - Test the decimal module against a large suite that
verifies compliance with standards. verifies compliance with standards.
compiler - Allow test_tokenize to verify round-trip lexing on compiler - Test the compiler package by compiling all the source
every file in the test library. in the standard library and test suite. This takes
a long time. Enabling this resource also allows
test_tokenize to verify round-trip lexing on every
file in the test library.
subprocess Run all tests for the subprocess module. subprocess Run all tests for the subprocess module.
...@@ -126,11 +121,11 @@ example, to run all the tests except for the bsddb tests, give the ...@@ -126,11 +121,11 @@ example, to run all the tests except for the bsddb tests, give the
option '-uall,-bsddb'. option '-uall,-bsddb'.
""" """
import cStringIO
import getopt import getopt
import os import os
import random import random
import re import re
import io
import sys import sys
import time import time
import traceback import traceback
...@@ -141,7 +136,7 @@ from inspect import isabstract ...@@ -141,7 +136,7 @@ from inspect import isabstract
# putting them in test_grammar.py has no effect: # putting them in test_grammar.py has no effect:
warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning, warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
".*test.test_grammar$") ".*test.test_grammar$")
if sys.maxsize > 0x7fffffff: if sys.maxint > 0x7fffffff:
# Also suppress them in <string>, because for 64-bit platforms, # Also suppress them in <string>, because for 64-bit platforms,
# that's where test_grammar.py hides them. # that's where test_grammar.py hides them.
warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning, warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
...@@ -177,10 +172,10 @@ RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb', ...@@ -177,10 +172,10 @@ RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb',
'decimal', 'compiler', 'subprocess', 'urlfetch') 'decimal', 'compiler', 'subprocess', 'urlfetch')
def usage(msg): def usage(code, msg=''):
print(msg, file=sys.stderr) print __doc__
print("Use --help for usage", file=sys.stderr) if msg: print msg
sys.exit(2) sys.exit(code)
def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False, def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
...@@ -211,39 +206,31 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False, ...@@ -211,39 +206,31 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
test_support.record_original_stdout(sys.stdout) test_support.record_original_stdout(sys.stdout)
try: try:
opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsSrf:lu:t:TD:NLR:wM:n', opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsSrf:lu:t:TD:NLR:wM:',
['help', 'verbose', 'quiet', 'exclude', ['help', 'verbose', 'quiet', 'exclude',
'single', 'slow', 'random', 'fromfile', 'single', 'slow', 'random', 'fromfile',
'findleaks', 'use=', 'threshold=', 'trace', 'findleaks', 'use=', 'threshold=', 'trace',
'coverdir=', 'nocoverdir', 'runleaks', 'coverdir=', 'nocoverdir', 'runleaks',
'huntrleaks=', 'verbose2', 'memlimit=', 'huntrleaks=', 'verbose2', 'memlimit=',
'debug', 'start=', "nowindows"
]) ])
except getopt.error as msg: except getopt.error, msg:
usage(msg) usage(2, msg)
# Defaults # Defaults
if use_resources is None: if use_resources is None:
use_resources = [] use_resources = []
debug = False
start = None
for o, a in opts: for o, a in opts:
if o in ('-h', '--help'): if o in ('-h', '--help'):
print(__doc__) usage(0)
return
elif o in ('-v', '--verbose'): elif o in ('-v', '--verbose'):
verbose += 1 verbose += 1
elif o in ('-w', '--verbose2'): elif o in ('-w', '--verbose2'):
verbose2 = True verbose2 = True
elif o in ('-d', '--debug'):
debug = True
elif o in ('-q', '--quiet'): elif o in ('-q', '--quiet'):
quiet = True; quiet = True;
verbose = 0 verbose = 0
elif o in ('-x', '--exclude'): elif o in ('-x', '--exclude'):
exclude = True exclude = True
elif o in ('-S', '--start'):
start = a
elif o in ('-s', '--single'): elif o in ('-s', '--single'):
single = True single = True
elif o in ('-S', '--slow'): elif o in ('-S', '--slow'):
...@@ -267,22 +254,19 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False, ...@@ -267,22 +254,19 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
coverdir = None coverdir = None
elif o in ('-R', '--huntrleaks'): elif o in ('-R', '--huntrleaks'):
huntrleaks = a.split(':') huntrleaks = a.split(':')
if len(huntrleaks) not in (2, 3): if len(huntrleaks) != 3:
print(a, huntrleaks) print a, huntrleaks
usage('-R takes 2 or 3 colon-separated arguments') usage(2, '-R takes three colon-separated arguments')
if not huntrleaks[0]: if len(huntrleaks[0]) == 0:
huntrleaks[0] = 5 huntrleaks[0] = 5
else: else:
huntrleaks[0] = int(huntrleaks[0]) huntrleaks[0] = int(huntrleaks[0])
if not huntrleaks[1]: if len(huntrleaks[1]) == 0:
huntrleaks[1] = 4 huntrleaks[1] = 4
else: else:
huntrleaks[1] = int(huntrleaks[1]) huntrleaks[1] = int(huntrleaks[1])
if len(huntrleaks) == 2 or not huntrleaks[2]: if len(huntrleaks[2]) == 0:
huntrleaks[2:] = ["reflog.txt"] huntrleaks[2] = "reflog.txt"
# Avoid false positives due to the character cache in
# stringobject.c filling slowly with random data
warm_char_cache()
elif o in ('-M', '--memlimit'): elif o in ('-M', '--memlimit'):
test_support.set_memlimit(a) test_support.set_memlimit(a)
elif o in ('-u', '--use'): elif o in ('-u', '--use'):
...@@ -296,31 +280,14 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False, ...@@ -296,31 +280,14 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
remove = True remove = True
r = r[1:] r = r[1:]
if r not in RESOURCE_NAMES: if r not in RESOURCE_NAMES:
usage('Invalid -u/--use option: ' + a) usage(1, 'Invalid -u/--use option: ' + a)
if remove: if remove:
if r in use_resources: if r in use_resources:
use_resources.remove(r) use_resources.remove(r)
elif r not in use_resources: elif r not in use_resources:
use_resources.append(r) use_resources.append(r)
elif o in ('-n', '--nowindows'):
import msvcrt
msvcrt.SetErrorMode(msvcrt.SEM_FAILCRITICALERRORS|
msvcrt.SEM_NOALIGNMENTFAULTEXCEPT|
msvcrt.SEM_NOGPFAULTERRORBOX|
msvcrt.SEM_NOOPENFILEERRORBOX)
try:
msvcrt.CrtSetReportMode
except AttributeError:
# release build
pass
else:
for m in [msvcrt.CRT_WARN, msvcrt.CRT_ERROR, msvcrt.CRT_ASSERT]:
msvcrt.CrtSetReportMode(m, msvcrt.CRTDBG_MODE_FILE)
msvcrt.CrtSetReportFile(m, msvcrt.CRTDBG_FILE_STDERR)
if generate and verbose:
usage("-g and -v don't go together!")
if single and fromfile: if single and fromfile:
usage("-s and -f don't go together!") usage(2, "-s and -f don't go together!")
good = [] good = []
bad = [] bad = []
...@@ -331,7 +298,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False, ...@@ -331,7 +298,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
try: try:
import gc import gc
except ImportError: except ImportError:
print('No GC available, disabling findleaks.') print 'No GC available, disabling findleaks.'
findleaks = False findleaks = False
else: else:
# Uncomment the line below to report garbage that is not # Uncomment the line below to report garbage that is not
...@@ -362,27 +329,21 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False, ...@@ -362,27 +329,21 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
# Strip .py extensions. # Strip .py extensions.
if args: if args:
args = list(map(removepy, args)) args = map(removepy, args)
if tests: if tests:
tests = list(map(removepy, tests)) tests = map(removepy, tests)
stdtests = STDTESTS[:] stdtests = STDTESTS[:]
nottests = NOTTESTS.copy() nottests = NOTTESTS[:]
if exclude: if exclude:
for arg in args: for arg in args:
if arg in stdtests: if arg in stdtests:
stdtests.remove(arg) stdtests.remove(arg)
nottests.add(arg) nottests[:0] = args
args = [] args = []
tests = tests or args or findtests(testdir, stdtests, nottests) tests = tests or args or findtests(testdir, stdtests, nottests)
if single: if single:
tests = tests[:1] tests = tests[:1]
# Remove all the tests that precede start if it's set.
if start:
try:
del tests[:tests.index(start)]
except ValueError:
print("Couldn't find starting test (%s), using all tests" % start)
if randomize: if randomize:
random.shuffle(tests) random.shuffle(tests)
if trace: if trace:
...@@ -395,7 +356,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False, ...@@ -395,7 +356,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
save_modules = sys.modules.keys() save_modules = sys.modules.keys()
for test in tests: for test in tests:
if not quiet: if not quiet:
print(test) print test
sys.stdout.flush() sys.stdout.flush()
if trace: if trace:
# If we're tracing code coverage, then we don't exit with status # If we're tracing code coverage, then we don't exit with status
...@@ -409,7 +370,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False, ...@@ -409,7 +370,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
testdir, huntrleaks) testdir, huntrleaks)
except KeyboardInterrupt: except KeyboardInterrupt:
# print a newline separate from the ^C # print a newline separate from the ^C
print() print
break break
except: except:
raise raise
...@@ -424,8 +385,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False, ...@@ -424,8 +385,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
if findleaks: if findleaks:
gc.collect() gc.collect()
if gc.garbage: if gc.garbage:
print("Warning: test created", len(gc.garbage), end=' ') print "Warning: test created", len(gc.garbage),
print("uncollectable object(s).") print "uncollectable object(s)."
# move the uncollectable objects somewhere so we don't see # move the uncollectable objects somewhere so we don't see
# them again # them again
found_garbage.extend(gc.garbage) found_garbage.extend(gc.garbage)
...@@ -442,21 +403,18 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False, ...@@ -442,21 +403,18 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
if good and not quiet: if good and not quiet:
if not bad and not skipped and len(good) > 1: if not bad and not skipped and len(good) > 1:
print("All", end=' ') print "All",
print(count(len(good), "test"), "OK.") print count(len(good), "test"), "OK."
if verbose:
print("CAUTION: stdout isn't compared in verbose mode:")
print("a test that passes in verbose mode may fail without it.")
if print_slow: if print_slow:
test_times.sort(reverse=True) test_times.sort(reverse=True)
print("10 slowest tests:") print "10 slowest tests:"
for time, test in test_times[:10]: for time, test in test_times[:10]:
print("%s: %.1fs" % (test, time)) print "%s: %.1fs" % (test, time)
if bad: if bad:
print(count(len(bad), "test"), "failed:") print count(len(bad), "test"), "failed:"
printlist(bad) printlist(bad)
if skipped and not quiet: if skipped and not quiet:
print(count(len(skipped), "test"), "skipped:") print count(len(skipped), "test"), "skipped:"
printlist(skipped) printlist(skipped)
e = _ExpectedSkips() e = _ExpectedSkips()
...@@ -464,27 +422,27 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False, ...@@ -464,27 +422,27 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
if e.isvalid(): if e.isvalid():
surprise = set(skipped) - e.getexpected() - set(resource_denieds) surprise = set(skipped) - e.getexpected() - set(resource_denieds)
if surprise: if surprise:
print(count(len(surprise), "skip"), \ print count(len(surprise), "skip"), \
"unexpected on", plat + ":") "unexpected on", plat + ":"
printlist(surprise) printlist(surprise)
else: else:
print("Those skips are all expected on", plat + ".") print "Those skips are all expected on", plat + "."
else: else:
print("Ask someone to teach regrtest.py about which tests are") print "Ask someone to teach regrtest.py about which tests are"
print("expected to get skipped on", plat + ".") print "expected to get skipped on", plat + "."
if verbose2 and bad: if verbose2 and bad:
print("Re-running failed tests in verbose mode") print "Re-running failed tests in verbose mode"
for test in bad: for test in bad:
print("Re-running test %r in verbose mode" % test) print "Re-running test %r in verbose mode" % test
sys.stdout.flush() sys.stdout.flush()
try: try:
test_support.verbose = True test_support.verbose = True
ok = runtest(test, generate, True, quiet, test_times, testdir, ok = runtest(test, generate, True, quiet, test_times, testdir,
huntrleaks, debug) huntrleaks)
except KeyboardInterrupt: except KeyboardInterrupt:
# print a newline separate from the ^C # print a newline separate from the ^C
print() print
break break
except: except:
raise raise
...@@ -523,13 +481,13 @@ STDTESTS = [ ...@@ -523,13 +481,13 @@ STDTESTS = [
'test_unittest', 'test_unittest',
'test_doctest', 'test_doctest',
'test_doctest2', 'test_doctest2',
] ]
NOTTESTS = { NOTTESTS = [
'test_support', 'test_support',
'test_future1', 'test_future1',
'test_future2', 'test_future2',
} ]
def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS): def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
"""Return a list of all applicable test modules.""" """Return a list of all applicable test modules."""
...@@ -537,7 +495,7 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS): ...@@ -537,7 +495,7 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
names = os.listdir(testdir) names = os.listdir(testdir)
tests = [] tests = []
for name in names: for name in names:
if name[:5] == "test_" and name[-3:] == ".py": if name[:5] == "test_" and name[-3:] == os.extsep+"py":
modname = name[:-3] modname = name[:-3]
if modname not in stdtests and modname not in nottests: if modname not in stdtests and modname not in nottests:
tests.append(modname) tests.append(modname)
...@@ -545,7 +503,7 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS): ...@@ -545,7 +503,7 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
return stdtests + tests return stdtests + tests
def runtest(test, generate, verbose, quiet, test_times, def runtest(test, generate, verbose, quiet, test_times,
testdir=None, huntrleaks=False, debug=False): testdir=None, huntrleaks=False):
"""Run a single test. """Run a single test.
test -- the name of the test test -- the name of the test
...@@ -555,8 +513,6 @@ def runtest(test, generate, verbose, quiet, test_times, ...@@ -555,8 +513,6 @@ def runtest(test, generate, verbose, quiet, test_times,
testdir -- test directory testdir -- test directory
huntrleaks -- run multiple times to test for leaks; requires a debug huntrleaks -- run multiple times to test for leaks; requires a debug
build; a triple corresponding to -R's three arguments build; a triple corresponding to -R's three arguments
debug -- if true, print tracebacks for failed tests regardless of
verbose setting
Return: Return:
-2 test skipped because resource denied -2 test skipped because resource denied
-1 test skipped for some other reason -1 test skipped for some other reason
...@@ -571,21 +527,21 @@ def runtest(test, generate, verbose, quiet, test_times, ...@@ -571,21 +527,21 @@ def runtest(test, generate, verbose, quiet, test_times,
cleanup_test_droppings(test, verbose) cleanup_test_droppings(test, verbose)
def runtest_inner(test, generate, verbose, quiet, test_times, def runtest_inner(test, generate, verbose, quiet, test_times,
testdir=None, huntrleaks=False, debug=False): testdir=None, huntrleaks=False):
test_support.unload(test) test_support.unload(test)
if not testdir: if not testdir:
testdir = findtestdir() testdir = findtestdir()
if verbose: if verbose:
cfp = None cfp = None
else: else:
cfp = io.StringIO() # XXX Should use io.StringIO() cfp = cStringIO.StringIO()
try: try:
save_stdout = sys.stdout save_stdout = sys.stdout
try: try:
if cfp: if cfp:
sys.stdout = cfp sys.stdout = cfp
print(test) # Output file starts with test name print test # Output file starts with test name
if test.startswith('test.'): if test.startswith('test.'):
abstest = test abstest = test
else: else:
...@@ -606,27 +562,27 @@ def runtest_inner(test, generate, verbose, quiet, test_times, ...@@ -606,27 +562,27 @@ def runtest_inner(test, generate, verbose, quiet, test_times,
test_times.append((test_time, test)) test_times.append((test_time, test))
finally: finally:
sys.stdout = save_stdout sys.stdout = save_stdout
except test_support.ResourceDenied as msg: except test_support.ResourceDenied, msg:
if not quiet: if not quiet:
print(test, "skipped --", msg) print test, "skipped --", msg
sys.stdout.flush() sys.stdout.flush()
return -2 return -2
except (ImportError, test_support.TestSkipped) as msg: except (ImportError, test_support.TestSkipped), msg:
if not quiet: if not quiet:
print(test, "skipped --", msg) print test, "skipped --", msg
sys.stdout.flush() sys.stdout.flush()
return -1 return -1
except KeyboardInterrupt: except KeyboardInterrupt:
raise raise
except test_support.TestFailed as msg: except test_support.TestFailed, msg:
print("test", test, "failed --", msg) print "test", test, "failed --", msg
sys.stdout.flush() sys.stdout.flush()
return 0 return 0
except: except:
type, value = sys.exc_info()[:2] type, value = sys.exc_info()[:2]
print("test", test, "crashed --", str(type) + ":", value) print "test", test, "crashed --", str(type) + ":", value
sys.stdout.flush() sys.stdout.flush()
if verbose or debug: if verbose:
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
sys.stdout.flush() sys.stdout.flush()
return 0 return 0
...@@ -637,7 +593,7 @@ def runtest_inner(test, generate, verbose, quiet, test_times, ...@@ -637,7 +593,7 @@ def runtest_inner(test, generate, verbose, quiet, test_times,
expected = test + "\n" expected = test + "\n"
if output == expected or huntrleaks: if output == expected or huntrleaks:
return 1 return 1
print("test", test, "produced unexpected output:") print "test", test, "produced unexpected output:"
sys.stdout.flush() sys.stdout.flush()
reportdiff(expected, output) reportdiff(expected, output)
sys.stdout.flush() sys.stdout.flush()
...@@ -667,12 +623,12 @@ def cleanup_test_droppings(testname, verbose): ...@@ -667,12 +623,12 @@ def cleanup_test_droppings(testname, verbose):
"directory nor file" % name) "directory nor file" % name)
if verbose: if verbose:
print("%r left behind %s %r" % (testname, kind, name)) print "%r left behind %s %r" % (testname, kind, name)
try: try:
nuker(name) nuker(name)
except Exception as msg: except Exception, msg:
print(("%r left behind %s %r and it couldn't be " print >> sys.stderr, ("%r left behind %s %r and it couldn't be "
"removed: %s" % (testname, kind, name, msg)), file=sys.stderr) "removed: %s" % (testname, kind, name, msg))
def dash_R(the_module, test, indirect_test, huntrleaks): def dash_R(the_module, test, indirect_test, huntrleaks):
# This code is hackish and inelegant, but it seems to do the job. # This code is hackish and inelegant, but it seems to do the job.
...@@ -698,29 +654,27 @@ def dash_R(the_module, test, indirect_test, huntrleaks): ...@@ -698,29 +654,27 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
indirect_test() indirect_test()
else: else:
def run_the_test(): def run_the_test():
del sys.modules[the_module.__name__] reload(the_module)
exec('import ' + the_module.__name__)
deltas = [] deltas = []
nwarmup, ntracked, fname = huntrleaks nwarmup, ntracked, fname = huntrleaks
repcount = nwarmup + ntracked repcount = nwarmup + ntracked
print("beginning", repcount, "repetitions", file=sys.stderr) print >> sys.stderr, "beginning", repcount, "repetitions"
print(("1234567890"*(repcount//10 + 1))[:repcount], file=sys.stderr) print >> sys.stderr, ("1234567890"*(repcount//10 + 1))[:repcount]
dash_R_cleanup(fs, ps, pic, abcs) dash_R_cleanup(fs, ps, pic, abcs)
for i in range(repcount): for i in range(repcount):
rc = sys.gettotalrefcount() rc = sys.gettotalrefcount()
run_the_test() run_the_test()
sys.stderr.write('.') sys.stderr.write('.')
sys.stderr.flush()
dash_R_cleanup(fs, ps, pic, abcs) dash_R_cleanup(fs, ps, pic, abcs)
if i >= nwarmup: if i >= nwarmup:
deltas.append(sys.gettotalrefcount() - rc - 2) deltas.append(sys.gettotalrefcount() - rc - 2)
print(file=sys.stderr) print >> sys.stderr
if any(deltas): if any(deltas):
msg = '%s leaked %s references, sum=%s' % (test, deltas, sum(deltas)) msg = '%s leaked %s references, sum=%s' % (test, deltas, sum(deltas))
print(msg, file=sys.stderr) print >> sys.stderr, msg
refrep = open(fname, "a") refrep = open(fname, "a")
print(msg, file=refrep) print >> refrep, msg
refrep.close() refrep.close()
def dash_R_cleanup(fs, ps, pic, abcs): def dash_R_cleanup(fs, ps, pic, abcs):
...@@ -729,7 +683,6 @@ def dash_R_cleanup(fs, ps, pic, abcs): ...@@ -729,7 +683,6 @@ def dash_R_cleanup(fs, ps, pic, abcs):
import urlparse, urllib, urllib2, mimetypes, doctest import urlparse, urllib, urllib2, mimetypes, doctest
import struct, filecmp, _abcoll import struct, filecmp, _abcoll
from distutils.dir_util import _path_created from distutils.dir_util import _path_created
from weakref import WeakSet
# Restore some original values. # Restore some original values.
warnings.filters[:] = fs warnings.filters[:] = fs
...@@ -746,7 +699,7 @@ def dash_R_cleanup(fs, ps, pic, abcs): ...@@ -746,7 +699,7 @@ def dash_R_cleanup(fs, ps, pic, abcs):
if not isabstract(abc): if not isabstract(abc):
continue continue
for obj in abc.__subclasses__() + [abc]: for obj in abc.__subclasses__() + [abc]:
obj._abc_registry = abcs.get(obj, WeakSet()).copy() obj._abc_registry = abcs.get(obj, {}).copy()
obj._abc_cache.clear() obj._abc_cache.clear()
obj._abc_negative_cache.clear() obj._abc_negative_cache.clear()
...@@ -767,14 +720,9 @@ def dash_R_cleanup(fs, ps, pic, abcs): ...@@ -767,14 +720,9 @@ def dash_R_cleanup(fs, ps, pic, abcs):
# Collect cyclic trash. # Collect cyclic trash.
gc.collect() gc.collect()
def warm_char_cache():
s = bytes(range(256))
for i in range(256):
s[i:i+1]
def reportdiff(expected, output): def reportdiff(expected, output):
import difflib import difflib
print("*" * 70) print "*" * 70
a = expected.splitlines(1) a = expected.splitlines(1)
b = output.splitlines(1) b = output.splitlines(1)
sm = difflib.SequenceMatcher(a=a, b=b) sm = difflib.SequenceMatcher(a=a, b=b)
...@@ -793,26 +741,26 @@ def reportdiff(expected, output): ...@@ -793,26 +741,26 @@ def reportdiff(expected, output):
pass pass
elif op == 'delete': elif op == 'delete':
print("***", pair(a0, a1), "of expected output missing:") print "***", pair(a0, a1), "of expected output missing:"
for line in a[a0:a1]: for line in a[a0:a1]:
print("-", line, end='') print "-", line,
elif op == 'replace': elif op == 'replace':
print("*** mismatch between", pair(a0, a1), "of expected", \ print "*** mismatch between", pair(a0, a1), "of expected", \
"output and", pair(b0, b1), "of actual output:") "output and", pair(b0, b1), "of actual output:"
for line in difflib.ndiff(a[a0:a1], b[b0:b1]): for line in difflib.ndiff(a[a0:a1], b[b0:b1]):
print(line, end='') print line,
elif op == 'insert': elif op == 'insert':
print("***", pair(b0, b1), "of actual output doesn't appear", \ print "***", pair(b0, b1), "of actual output doesn't appear", \
"in expected output after line", str(a1)+":") "in expected output after line", str(a1)+":"
for line in b[b0:b1]: for line in b[b0:b1]:
print("+", line, end='') print "+", line,
else: else:
print("get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)) print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
print("*" * 70) print "*" * 70
def findtestdir(): def findtestdir():
if __name__ == '__main__': if __name__ == '__main__':
...@@ -823,7 +771,7 @@ def findtestdir(): ...@@ -823,7 +771,7 @@ def findtestdir():
return testdir return testdir
def removepy(name): def removepy(name):
if name.endswith(".py"): if name.endswith(os.extsep + "py"):
name = name[:-3] name = name[:-3]
return name return name
...@@ -843,8 +791,8 @@ def printlist(x, width=70, indent=4): ...@@ -843,8 +791,8 @@ def printlist(x, width=70, indent=4):
from textwrap import fill from textwrap import fill
blanks = ' ' * indent blanks = ' ' * indent
print(fill(' '.join(map(str, x)), width, print fill(' '.join(map(str, x)), width,
initial_indent=blanks, subsequent_indent=blanks)) initial_indent=blanks, subsequent_indent=blanks)
# Map sys.platform to a string containing the basenames of tests # Map sys.platform to a string containing the basenames of tests
# expected to be skipped on that platform. # expected to be skipped on that platform.
...@@ -853,6 +801,9 @@ def printlist(x, width=70, indent=4): ...@@ -853,6 +801,9 @@ def printlist(x, width=70, indent=4):
# test_pep277 # test_pep277
# The _ExpectedSkips constructor adds this to the set of expected # The _ExpectedSkips constructor adds this to the set of expected
# skips if not os.path.supports_unicode_filenames. # skips if not os.path.supports_unicode_filenames.
# test_socket_ssl
# Controlled by test_socket_ssl.skip_expected. Requires the network
# resource, and a socket module with ssl support.
# test_timeout # test_timeout
# Controlled by test_timeout.skip_expected. Requires the network # Controlled by test_timeout.skip_expected. Requires the network
# resource and a socket module. # resource and a socket module.
...@@ -864,6 +815,7 @@ _expectations = { ...@@ -864,6 +815,7 @@ _expectations = {
'win32': 'win32':
""" """
test__locale test__locale
test_bsddb185
test_bsddb3 test_bsddb3
test_commands test_commands
test_crypt test_crypt
...@@ -888,13 +840,14 @@ _expectations = { ...@@ -888,13 +840,14 @@ _expectations = {
test_pwd test_pwd
test_resource test_resource
test_signal test_signal
test_syslog
test_threadsignals test_threadsignals
test_timing
test_wait3 test_wait3
test_wait4 test_wait4
""", """,
'linux2': 'linux2':
""" """
test_bsddb185
test_curses test_curses
test_dl test_dl
test_largefile test_largefile
...@@ -905,6 +858,7 @@ _expectations = { ...@@ -905,6 +858,7 @@ _expectations = {
""" """
test_atexit test_atexit
test_bsddb test_bsddb
test_bsddb185
test_bsddb3 test_bsddb3
test_bz2 test_bz2
test_commands test_commands
...@@ -925,6 +879,7 @@ _expectations = { ...@@ -925,6 +879,7 @@ _expectations = {
test_ossaudiodev test_ossaudiodev
test_poll test_poll
test_popen test_popen
test_popen2
test_posix test_posix
test_pty test_pty
test_pwd test_pwd
...@@ -932,10 +887,12 @@ _expectations = { ...@@ -932,10 +887,12 @@ _expectations = {
test_signal test_signal
test_sundry test_sundry
test_tarfile test_tarfile
test_timing
""", """,
'unixware7': 'unixware7':
""" """
test_bsddb test_bsddb
test_bsddb185
test_dl test_dl
test_epoll test_epoll
test_largefile test_largefile
...@@ -949,6 +906,7 @@ _expectations = { ...@@ -949,6 +906,7 @@ _expectations = {
'openunix8': 'openunix8':
""" """
test_bsddb test_bsddb
test_bsddb185
test_dl test_dl
test_epoll test_epoll
test_largefile test_largefile
...@@ -963,6 +921,7 @@ _expectations = { ...@@ -963,6 +921,7 @@ _expectations = {
""" """
test_asynchat test_asynchat
test_bsddb test_bsddb
test_bsddb185
test_dl test_dl
test_fork1 test_fork1
test_epoll test_epoll
...@@ -981,6 +940,39 @@ _expectations = { ...@@ -981,6 +940,39 @@ _expectations = {
test_threadedtempfile test_threadedtempfile
test_threading test_threading
""", """,
'riscos':
"""
test_asynchat
test_atexit
test_bsddb
test_bsddb185
test_bsddb3
test_commands
test_crypt
test_dbm
test_dl
test_fcntl
test_fork1
test_epoll
test_gdbm
test_grp
test_largefile
test_locale
test_kqueue
test_mmap
test_openpty
test_poll
test_popen2
test_pty
test_pwd
test_strop
test_sundry
test_thread
test_threaded_import
test_threadedtempfile
test_threading
test_timing
""",
'darwin': 'darwin':
""" """
test__locale test__locale
...@@ -991,6 +983,7 @@ _expectations = { ...@@ -991,6 +983,7 @@ _expectations = {
test_gdbm test_gdbm
test_largefile test_largefile
test_locale test_locale
test_kqueue
test_minidom test_minidom
test_ossaudiodev test_ossaudiodev
test_poll test_poll
...@@ -998,6 +991,7 @@ _expectations = { ...@@ -998,6 +991,7 @@ _expectations = {
'sunos5': 'sunos5':
""" """
test_bsddb test_bsddb
test_bsddb185
test_curses test_curses
test_dbm test_dbm
test_epoll test_epoll
...@@ -1011,6 +1005,7 @@ _expectations = { ...@@ -1011,6 +1005,7 @@ _expectations = {
'hp-ux11': 'hp-ux11':
""" """
test_bsddb test_bsddb
test_bsddb185
test_curses test_curses
test_dl test_dl
test_epoll test_epoll
...@@ -1028,6 +1023,7 @@ _expectations = { ...@@ -1028,6 +1023,7 @@ _expectations = {
""", """,
'atheos': 'atheos':
""" """
test_bsddb185
test_curses test_curses
test_dl test_dl
test_gdbm test_gdbm
...@@ -1038,10 +1034,12 @@ _expectations = { ...@@ -1038,10 +1034,12 @@ _expectations = {
test_mhlib test_mhlib
test_mmap test_mmap
test_poll test_poll
test_popen2
test_resource test_resource
""", """,
'cygwin': 'cygwin':
""" """
test_bsddb185
test_bsddb3 test_bsddb3
test_curses test_curses
test_dbm test_dbm
...@@ -1056,6 +1054,7 @@ _expectations = { ...@@ -1056,6 +1054,7 @@ _expectations = {
'os2emx': 'os2emx':
""" """
test_audioop test_audioop
test_bsddb185
test_bsddb3 test_bsddb3
test_commands test_commands
test_curses test_curses
...@@ -1081,6 +1080,7 @@ _expectations = { ...@@ -1081,6 +1080,7 @@ _expectations = {
test_ossaudiodev test_ossaudiodev
test_pep277 test_pep277
test_pty test_pty
test_socket_ssl
test_socketserver test_socketserver
test_tcl test_tcl
test_timeout test_timeout
...@@ -1089,6 +1089,7 @@ _expectations = { ...@@ -1089,6 +1089,7 @@ _expectations = {
'aix5': 'aix5':
""" """
test_bsddb test_bsddb
test_bsddb185
test_bsddb3 test_bsddb3
test_bz2 test_bz2
test_dl test_dl
...@@ -1118,6 +1119,7 @@ _expectations = { ...@@ -1118,6 +1119,7 @@ _expectations = {
'netbsd3': 'netbsd3':
""" """
test_bsddb test_bsddb
test_bsddb185
test_bsddb3 test_bsddb3
test_ctypes test_ctypes
test_curses test_curses
...@@ -1145,26 +1147,26 @@ class _ExpectedSkips: ...@@ -1145,26 +1147,26 @@ class _ExpectedSkips:
s = _expectations[sys.platform] s = _expectations[sys.platform]
self.expected = set(s.split()) self.expected = set(s.split())
# These are broken tests, for now skipped on every platform.
# XXX Fix these!
self.expected.add('test_cProfile')
# expected to be skipped on every platform, even Linux # expected to be skipped on every platform, even Linux
self.expected.add('test_linuxaudiodev')
if not os.path.supports_unicode_filenames: if not os.path.supports_unicode_filenames:
self.expected.add('test_pep277') self.expected.add('test_pep277')
# doctest, profile and cProfile tests fail when the codec for the try:
# fs encoding isn't built in because PyUnicode_Decode() adds two from test import test_socket_ssl
# calls into Python. except ImportError:
encs = ("utf-8", "latin-1", "ascii", "mbcs", "utf-16", "utf-32") pass
if sys.getfilesystemencoding().lower() not in encs: else:
self.expected.add('test_profile') if test_socket_ssl.skip_expected:
self.expected.add('test_cProfile') self.expected.add('test_socket_ssl')
self.expected.add('test_doctest')
if test_timeout.skip_expected: if test_timeout.skip_expected:
self.expected.add('test_timeout') self.expected.add('test_timeout')
if sys.maxint == 9223372036854775807L:
self.expected.add('test_imageop')
if not sys.platform in ("mac", "darwin"): if not sys.platform in ("mac", "darwin"):
MAC_ONLY = ["test_macostools", "test_aepack", MAC_ONLY = ["test_macostools", "test_aepack",
"test_plistlib", "test_scriptpackages", "test_plistlib", "test_scriptpackages",
...@@ -1181,9 +1183,19 @@ class _ExpectedSkips: ...@@ -1181,9 +1183,19 @@ class _ExpectedSkips:
for skip in WIN_ONLY: for skip in WIN_ONLY:
self.expected.add(skip) self.expected.add(skip)
if sys.platform != 'irix':
IRIX_ONLY = ["test_imageop", "test_al", "test_cd", "test_cl",
"test_gl", "test_imgfile"]
for skip in IRIX_ONLY:
self.expected.add(skip)
if sys.platform != 'sunos5': if sys.platform != 'sunos5':
self.expected.add('test_sunaudiodev')
self.expected.add('test_nis') self.expected.add('test_nis')
if not sys.py3kwarning:
self.expected.add('test_py3kwarn')
self.valid = True self.valid = True
def isvalid(self): def isvalid(self):
...@@ -1213,5 +1225,5 @@ if __name__ == '__main__': ...@@ -1213,5 +1225,5 @@ if __name__ == '__main__':
if os.path.abspath(os.path.normpath(sys.path[i])) == mydir: if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
del sys.path[i] del sys.path[i]
if len(sys.path) == pathlen: if len(sys.path) == pathlen:
print('Could not find %r in sys.path to remove it' % mydir) print 'Could not find %r in sys.path to remove it' % mydir
main() main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment