]> granicus.if.org Git - python/commitdiff
DecimalContextTestCase: this permanently changed the
authorTim Peters <tim.peters@gmail.com>
Mon, 10 Apr 2006 20:25:47 +0000 (20:25 +0000)
committerTim Peters <tim.peters@gmail.com>
Mon, 10 Apr 2006 20:25:47 +0000 (20:25 +0000)
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.

Lib/test/test_contextlib.py

index 7d601fab46b3a1c340932e1a762175c6c050d3f3..97470c78fbe49b1ad45ed63ae7c3e82d8e3b2a96 100644 (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!