From ce4a9c901905624216bc5ae7ae631ecb94c2d66e Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sun, 9 Apr 2006 08:36:46 +0000 Subject: Fix tests so they pass in -R mode --- Lib/test/test_decimal.py | 13 ++++++++----- Lib/test/test_difflib.py | 8 ++++++-- Lib/test/test_warnings.py | 4 ++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 844cee0..f3f9215 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -42,11 +42,13 @@ Signals = getcontext().flags.keys() # Tests are built around these assumed context defaults. # test_main() restores the original context. -ORIGINAL_CONTEXT = getcontext().copy() -DefaultContext.prec = 9 -DefaultContext.rounding = ROUND_HALF_EVEN -DefaultContext.traps = dict.fromkeys(Signals, 0) -setcontext(DefaultContext) +def init(): + global ORIGINAL_CONTEXT + ORIGINAL_CONTEXT = getcontext().copy() + DefaultContext.prec = 9 + DefaultContext.rounding = ROUND_HALF_EVEN + DefaultContext.traps = dict.fromkeys(Signals, 0) + setcontext(DefaultContext) TESTDATADIR = 'decimaltestdata' if __name__ == '__main__': @@ -1069,6 +1071,7 @@ def test_main(arith=False, verbose=None): is enabled in regrtest.py """ + init() global TEST_ALL TEST_ALL = arith or is_resource_enabled('decimal') diff --git a/Lib/test/test_difflib.py b/Lib/test/test_difflib.py index 52feef0..83fad15 100644 --- a/Lib/test/test_difflib.py +++ b/Lib/test/test_difflib.py @@ -152,6 +152,10 @@ class TestSFpatches(unittest.TestCase): difflib.SequenceMatcher(None, old, new).get_opcodes() -Doctests = doctest.DocTestSuite(difflib) +def test_main(): + difflib.HtmlDiff._default_prefix = 0 + Doctests = doctest.DocTestSuite(difflib) + run_unittest(TestSFpatches, TestSFbugs, Doctests) -run_unittest(TestSFpatches, TestSFbugs, Doctests) +if __name__ == '__main__': + test_main() diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py index b7061c1..5a3f521 100644 --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -84,5 +84,9 @@ class TestModule(unittest.TestCase): def test_main(verbose=None): test_support.run_unittest(TestModule) +# Obscure hack so that this test passes after reloads (regrtest -R). +if '__warningregistry__' in globals(): + del globals()['__warningregistry__'] + if __name__ == "__main__": test_main(verbose=True) -- cgit v0.12