[Python-checkins] bpo-33750: Reset thread-local context precision in test_round(). (GH-7355) (#7356)

Stefan Krah webhook-mailer at python.org
Sun Jun 3 13:30:15 EDT 2018


https://github.com/python/cpython/commit/7f1bcda9bc3c04100cb047373732db0eba00e581
commit: 7f1bcda9bc3c04100cb047373732db0eba00e581
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Stefan Krah <skrah at bytereef.org>
date: 2018-06-03T19:30:12+02:00
summary:

bpo-33750: Reset thread-local context precision in test_round(). (GH-7355) (#7356)

(cherry picked from commit e95dfc5006d19e59c7871faa9973356844ddb3ae)

Co-authored-by: Stefan Krah <skrah at bytereef.org>

files:
M Lib/test/test_decimal.py

diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 57094ad66952..45d80cec810f 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -4450,19 +4450,19 @@ def test_rop(self):
     def test_round(self):
         # Python3 behavior: round() returns Decimal
         Decimal = self.decimal.Decimal
-        getcontext = self.decimal.getcontext
+        localcontext = self.decimal.localcontext
 
-        c = getcontext()
-        c.prec = 28
+        with localcontext() as c:
+            c.prec = 28
 
-        self.assertEqual(str(Decimal("9.99").__round__()), "10")
-        self.assertEqual(str(Decimal("9.99e-5").__round__()), "0")
-        self.assertEqual(str(Decimal("1.23456789").__round__(5)), "1.23457")
-        self.assertEqual(str(Decimal("1.2345").__round__(10)), "1.2345000000")
-        self.assertEqual(str(Decimal("1.2345").__round__(-10)), "0E+10")
+            self.assertEqual(str(Decimal("9.99").__round__()), "10")
+            self.assertEqual(str(Decimal("9.99e-5").__round__()), "0")
+            self.assertEqual(str(Decimal("1.23456789").__round__(5)), "1.23457")
+            self.assertEqual(str(Decimal("1.2345").__round__(10)), "1.2345000000")
+            self.assertEqual(str(Decimal("1.2345").__round__(-10)), "0E+10")
 
-        self.assertRaises(TypeError, Decimal("1.23").__round__, "5")
-        self.assertRaises(TypeError, Decimal("1.23").__round__, 5, 8)
+            self.assertRaises(TypeError, Decimal("1.23").__round__, "5")
+            self.assertRaises(TypeError, Decimal("1.23").__round__, 5, 8)
 
     def test_create_decimal(self):
         c = self.decimal.Context()
@@ -5406,7 +5406,7 @@ def test_from_tuple(self):
 
             # SSIZE_MIN
             x = (1, (), -sys.maxsize-1)
-            self.assertEqual(str(c.create_decimal(x)), '-0E-1000026')
+            self.assertEqual(str(c.create_decimal(x)), '-0E-1000007')
             self.assertRaises(InvalidOperation, Decimal, x)
 
             x = (1, (0, 1, 2), -sys.maxsize-1)



More information about the Python-checkins mailing list