summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_decimal.py
diff options
context:
space:
mode:
authorStefan Krah <skrah@bytereef.org>2018-06-03 16:40:00 (GMT)
committerGitHub <noreply@github.com>2018-06-03 16:40:00 (GMT)
commite95dfc5006d19e59c7871faa9973356844ddb3ae (patch)
treef9acaaf1fd15f0a19b788e960d40db8489f29855 /Lib/test/test_decimal.py
parent867b825830b9b0baff791c9bcda57bba3809722a (diff)
downloadcpython-e95dfc5006d19e59c7871faa9973356844ddb3ae.zip
cpython-e95dfc5006d19e59c7871faa9973356844ddb3ae.tar.gz
cpython-e95dfc5006d19e59c7871faa9973356844ddb3ae.tar.bz2
bpo-33750: Reset thread-local context precision in test_round(). (#7355)
Diffstat (limited to 'Lib/test/test_decimal.py')
-rw-r--r--Lib/test/test_decimal.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 5aea51e..58bde54 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -4454,19 +4454,19 @@ class Coverage(unittest.TestCase):
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()
@@ -5410,7 +5410,7 @@ class CWhitebox(unittest.TestCase):
# 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)