summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_contextlib.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2006-04-10 20:25:47 (GMT)
committerTim Peters <tim.peters@gmail.com>2006-04-10 20:25:47 (GMT)
commita19dc0beb1d2e499b86f56a992e78e7e3d767ee3 (patch)
tree3d3044fa4164848df14d14bb9ece29c2fdecf3e0 /Lib/test/test_contextlib.py
parentbd0c10f7c99db3272b5db2b1f21ed43b96d260c0 (diff)
downloadcpython-a19dc0beb1d2e499b86f56a992e78e7e3d767ee3.zip
cpython-a19dc0beb1d2e499b86f56a992e78e7e3d767ee3.tar.gz
cpython-a19dc0beb1d2e499b86f56a992e78e7e3d767ee3.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_contextlib.py')
-rw-r--r--Lib/test/test_contextlib.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
index 7d601fa..97470c7 100644
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -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!