Added a -s option which is useful for narrowing down memory leaks.

With -s only a single test is run.  The next test run is chosen
sequentially from the list of all tests.
This commit is contained in:
Barry Warsaw 1999-01-28 19:51:51 +00:00
parent ab11f60bb3
commit e11e3dee3e
1 changed files with 42 additions and 4 deletions

View File

@ -12,12 +12,20 @@ Command line options:
-q: quiet -- don't print anything except if a test fails -q: quiet -- don't print anything except if a test fails
-g: generate -- write the output file for a test instead of comparing it -g: generate -- write the output file for a test instead of comparing it
-x: exclude -- arguments are tests to *exclude* -x: exclude -- arguments are tests to *exclude*
-s: single -- run only a single test (see below)
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.
If no test names are given, all tests are run. If no test names are given, all tests are run.
-v is incompatible with -g and does not compare test output files. -v is incompatible with -g and does not compare test output files.
-s means to run only a single test and exit. This is useful when Purifying
the Python interpreter. The file /tmp/pynexttest is read to find the next
test to run. If this file is missing, the first test_*.py file in testdir or
on the command line is used. (actually tempfile.gettempdir() is used instead
of /tmp).
""" """
import sys import sys
@ -48,7 +56,7 @@ def main(tests=None, testdir=None):
""" """
try: try:
opts, args = getopt.getopt(sys.argv[1:], 'vgqx') opts, args = getopt.getopt(sys.argv[1:], 'vgqxs')
except getopt.error, msg: except getopt.error, msg:
print msg print msg
print __doc__ print __doc__
@ -57,17 +65,30 @@ def main(tests=None, testdir=None):
quiet = 0 quiet = 0
generate = 0 generate = 0
exclude = 0 exclude = 0
single = 0
for o, a in opts: for o, a in opts:
if o == '-v': verbose = verbose+1 if o == '-v': verbose = verbose+1
if o == '-q': quiet = 1; verbose = 0 if o == '-q': quiet = 1; verbose = 0
if o == '-g': generate = 1 if o == '-g': generate = 1
if o == '-x': exclude = 1 if o == '-x': exclude = 1
if o == '-s': single = 1
if generate and verbose: if generate and verbose:
print "-g and -v don't go together!" print "-g and -v don't go together!"
return 2 return 2
good = [] good = []
bad = [] bad = []
skipped = [] skipped = []
if single:
from tempfile import gettempdir
filename = os.path.join(gettempdir(), 'pynexttest')
try:
fp = open(filename, 'r')
next = string.strip(fp.read())
tests = [next]
fp.close()
except IOError:
pass
for i in range(len(args)): for i in range(len(args)):
# Strip trailing ".py" from arguments # Strip trailing ".py" from arguments
if args[i][-3:] == '.py': if args[i][-3:] == '.py':
@ -81,6 +102,8 @@ def main(tests=None, testdir=None):
nottests[:0] = args 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:
tests = tests[:1]
test_support.verbose = verbose # Tell tests to be moderately quiet test_support.verbose = verbose # Tell tests to be moderately quiet
for test in tests: for test in tests:
if not quiet: if not quiet:
@ -105,6 +128,21 @@ def main(tests=None, testdir=None):
if skipped and not quiet: if skipped and not quiet:
print count(len(skipped), "test"), "skipped:", print count(len(skipped), "test"), "skipped:",
print string.join(skipped) print string.join(skipped)
if single:
alltests = findtests(testdir, stdtests, nottests)
for i in range(len(alltests)):
if tests[0] == alltests[i]:
if i == len(alltests) - 1:
os.unlink(filename)
else:
fp = open(filename, 'w')
fp.write(alltests[i+1] + '\n')
fp.close()
break
else:
os.unlink(filename)
return len(bad) > 0 return len(bad) > 0
STDTESTS = [ STDTESTS = [