Merge heads

This commit is contained in:
Kurt B. Kaiser 2011-03-24 15:10:28 -04:00
commit e88893ccc6
5 changed files with 28 additions and 38 deletions

View File

@ -42,6 +42,9 @@ Selecting tests
-- specify which special resource intensive tests to run -- specify which special resource intensive tests to run
-M/--memlimit LIMIT -M/--memlimit LIMIT
-- run very large memory-consuming tests -- run very large memory-consuming tests
--testdir DIR
-- execute test files in the specified directory (instead
of the Python stdlib test suite)
Special runs Special runs
@ -265,7 +268,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir', 'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir',
'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=', 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=',
'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug', 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug',
'start=', 'nowindows', 'header']) 'start=', 'nowindows', 'header', 'testdir='])
except getopt.error as msg: except getopt.error as msg:
usage(msg) usage(msg)
@ -315,7 +318,9 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
elif o in ('-T', '--coverage'): elif o in ('-T', '--coverage'):
trace = True trace = True
elif o in ('-D', '--coverdir'): elif o in ('-D', '--coverdir'):
coverdir = os.path.join(os.getcwd(), a) # CWD is replaced with a temporary dir before calling main(), so we
# need join it with the saved CWD so it goes where the user expects.
coverdir = os.path.join(support.SAVEDCWD, a)
elif o in ('-N', '--nocoverdir'): elif o in ('-N', '--nocoverdir'):
coverdir = None coverdir = None
elif o in ('-R', '--huntrleaks'): elif o in ('-R', '--huntrleaks'):
@ -393,6 +398,10 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
print() # Force a newline (just in case) print() # Force a newline (just in case)
print(json.dumps(result)) print(json.dumps(result))
sys.exit(0) sys.exit(0)
elif o == '--testdir':
# CWD is replaced with a temporary dir before calling main(), so we
# join it with the saved CWD so it ends up where the user expects.
testdir = os.path.join(support.SAVEDCWD, a)
else: else:
print(("No handler for option {}. Please report this as a bug " print(("No handler for option {}. Please report this as a bug "
"at http://bugs.python.org.").format(o), file=sys.stderr) "at http://bugs.python.org.").format(o), file=sys.stderr)
@ -467,7 +476,13 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
print("== ", os.getcwd()) print("== ", os.getcwd())
print("Testing with flags:", sys.flags) print("Testing with flags:", sys.flags)
alltests = findtests(testdir, stdtests, nottests) # if testdir is set, then we are not running the python tests suite, so
# don't add default tests to be executed or skipped (pass empty values)
if testdir:
alltests = findtests(testdir, list(), set())
else:
alltests = findtests(testdir, stdtests, nottests)
selected = tests or args or alltests selected = tests or args or alltests
if single: if single:
selected = selected[:1] selected = selected[:1]
@ -713,6 +728,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
sys.exit(len(bad) > 0 or interrupted) sys.exit(len(bad) > 0 or interrupted)
# small set of tests to determine if we have a basically functioning interpreter
# (i.e. if any of these fail, then anything else is likely to follow)
STDTESTS = [ STDTESTS = [
'test_grammar', 'test_grammar',
'test_opcodes', 'test_opcodes',
@ -725,10 +742,8 @@ STDTESTS = [
'test_doctest2', 'test_doctest2',
] ]
NOTTESTS = { # set of tests that we don't want to be executed when using regrtest
'test_future1', NOTTESTS = set()
'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."""

View File

@ -332,37 +332,12 @@ class TestNamedTuple(unittest.TestCase):
# verify that _source can be run through exec() # verify that _source can be run through exec()
tmp = namedtuple('NTColor', 'red green blue') tmp = namedtuple('NTColor', 'red green blue')
globals().pop('NTColor', None) # remove artifacts from other tests globals().pop('NTColor', None) # remove artifacts from other tests
self.assertNotIn('NTColor', globals())
exec(tmp._source, globals()) exec(tmp._source, globals())
self.assertIn('NTColor', globals()) self.assertIn('NTColor', globals())
c = NTColor(10, 20, 30) c = NTColor(10, 20, 30)
self.assertEqual((c.red, c.green, c.blue), (10, 20, 30)) self.assertEqual((c.red, c.green, c.blue), (10, 20, 30))
self.assertEqual(NTColor._fields, ('red', 'green', 'blue')) self.assertEqual(NTColor._fields, ('red', 'green', 'blue'))
globals().pop('NTColor', None) # clean-up after this test globals().pop('NTColor', None) # clean-up after this test
self.assertNotIn('NTColor', globals())
def test_source_importable(self):
tmp = namedtuple('Color', 'hue sat val')
compiled = None
source = TESTFN + '.py'
with open(source, 'w') as f:
print(tmp._source, file=f)
if TESTFN in sys.modules:
del sys.modules[TESTFN]
try:
mod = __import__(TESTFN)
compiled = mod.__file__
Color = mod.Color
c = Color(10, 20, 30)
self.assertEqual((c.hue, c.sat, c.val), (10, 20, 30))
self.assertEqual(Color._fields, ('hue', 'sat', 'val'))
finally:
forget(TESTFN)
if compiled:
unlink(compiled)
unlink(source)
################################################################################ ################################################################################

View File

@ -13,14 +13,14 @@ def get_error_location(msg):
class FutureTest(unittest.TestCase): class FutureTest(unittest.TestCase):
def test_future1(self): def test_future1(self):
support.unload('test_future1') support.unload('future_test1')
from test import test_future1 from test import future_test1
self.assertEqual(test_future1.result, 6) self.assertEqual(future_test1.result, 6)
def test_future2(self): def test_future2(self):
support.unload('test_future2') support.unload('future_test2')
from test import test_future2 from test import future_test2
self.assertEqual(test_future2.result, 6) self.assertEqual(future_test2.result, 6)
def test_future3(self): def test_future3(self):
support.unload('test_future3') support.unload('test_future3')