Kaydet (Commit) ed20ad84 authored tarafından Raymond Hettinger's avatar Raymond Hettinger

Change the strategy for coping with time intensive tests from

"all or none" to "all or some".

This provides much greater test coverage without eating much time.
It also makes it more likely that routine regression testing will
unearth bugs.
üst 1fbf9c5e
...@@ -2,6 +2,7 @@ import compiler ...@@ -2,6 +2,7 @@ import compiler
import os import os
import test.test_support import test.test_support
import unittest import unittest
from random import random
class CompilerTest(unittest.TestCase): class CompilerTest(unittest.TestCase):
...@@ -18,6 +19,8 @@ class CompilerTest(unittest.TestCase): ...@@ -18,6 +19,8 @@ class CompilerTest(unittest.TestCase):
for basename in os.listdir(dir): for basename in os.listdir(dir):
if not basename.endswith(".py"): if not basename.endswith(".py"):
continue continue
if not TEST_ALL and random() < 0.98:
continue
path = os.path.join(dir, basename) path = os.path.join(dir, basename)
if test.test_support.verbose: if test.test_support.verbose:
print "compiling", path print "compiling", path
...@@ -31,7 +34,8 @@ class CompilerTest(unittest.TestCase): ...@@ -31,7 +34,8 @@ class CompilerTest(unittest.TestCase):
compiler.compile(buf, basename, "exec") compiler.compile(buf, basename, "exec")
def test_main(): def test_main():
test.test_support.requires("compiler") global TEST_ALL
TEST_ALL = test.test_support.is_resource_enabled("compiler")
test.test_support.run_unittest(CompilerTest) test.test_support.run_unittest(CompilerTest)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -181,6 +181,10 @@ class DecimalTest(unittest.TestCase): ...@@ -181,6 +181,10 @@ class DecimalTest(unittest.TestCase):
def eval_equation(self, s): def eval_equation(self, s):
#global DEFAULT_PRECISION #global DEFAULT_PRECISION
#print DEFAULT_PRECISION #print DEFAULT_PRECISION
if not TEST_ALL and random.random() < 0.90:
return
try: try:
Sides = s.split('->') Sides = s.split('->')
L = Sides[0].strip().split() L = Sides[0].strip().split()
...@@ -997,9 +1001,13 @@ class ContextAPItests(unittest.TestCase): ...@@ -997,9 +1001,13 @@ class ContextAPItests(unittest.TestCase):
def test_main(arith=False, verbose=None): def test_main(arith=False, verbose=None):
""" Execute the tests. """ Execute the tests.
Runs arithmetic tests if arith is True or if the "decimal" resource Runs all arithmetic tests if arith is True or if the "decimal" resource
is enables in regrtest.py is enabled in regrtest.py
""" """
global TEST_ALL
TEST_ALL = arith or is_resource_enabled('decimal')
test_classes = [ test_classes = [
DecimalExplicitConstructionTest, DecimalExplicitConstructionTest,
DecimalImplicitConstructionTest, DecimalImplicitConstructionTest,
...@@ -1008,20 +1016,17 @@ def test_main(arith=False, verbose=None): ...@@ -1008,20 +1016,17 @@ def test_main(arith=False, verbose=None):
DecimalUsabilityTest, DecimalUsabilityTest,
DecimalPythonAPItests, DecimalPythonAPItests,
ContextAPItests, ContextAPItests,
DecimalTest,
] ]
if arith or is_resource_enabled('decimal'):
test_classes.extend([DecimalTest])
run_unittest(*test_classes) run_unittest(*test_classes)
import decimal as DecimalModule import decimal as DecimalModule
run_doctest(DecimalModule, verbose) run_doctest(DecimalModule, verbose)
return
if __name__ == '__main__': if __name__ == '__main__':
# Calling with no arguments runs all tests. # Calling with no arguments runs all tests.
# Calling with "Skip" will skipover the arithmetic tests. # Calling with "Skip" will skip over 90% of the arithmetic tests.
if len(sys.argv) == 1: if len(sys.argv) == 1:
test_main(arith=True, verbose=True) test_main(arith=True, verbose=True)
elif len(sys.argv) == 2: elif len(sys.argv) == 2:
......
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