DecimalContextTestCase: this permanently changed the

default decimal context, causing test_tokenize to fail
if it ran after test_contextlib.  Changed to restore
the decimal context in effect at the test's start.
This commit is contained in:
Tim Peters 2006-04-10 20:25:47 +00:00
parent bd0c10f7c9
commit a19dc0beb1
1 changed files with 13 additions and 9 deletions

View File

@ -313,20 +313,24 @@ class DecimalContextTestCase(unittest.TestCase):
def testBasic(self):
ctx = decimal.getcontext()
ctx.prec = save_prec = decimal.ExtendedContext.prec + 5
with decimal.ExtendedContext:
self.assertEqual(decimal.getcontext().prec,
decimal.ExtendedContext.prec)
self.assertEqual(decimal.getcontext().prec, save_prec)
orig_context = ctx.copy()
try:
ctx.prec = save_prec = decimal.ExtendedContext.prec + 5
with decimal.ExtendedContext:
self.assertEqual(decimal.getcontext().prec,
decimal.ExtendedContext.prec)
1/0
except ZeroDivisionError:
self.assertEqual(decimal.getcontext().prec, save_prec)
else:
self.fail("Didn't raise ZeroDivisionError")
try:
with decimal.ExtendedContext:
self.assertEqual(decimal.getcontext().prec,
decimal.ExtendedContext.prec)
1/0
except ZeroDivisionError:
self.assertEqual(decimal.getcontext().prec, save_prec)
else:
self.fail("Didn't raise ZeroDivisionError")
finally:
decimal.setcontext(orig_context)
# This is needed to make the test actually run under regrtest.py!