From: Stefan Krah Date: Sun, 3 Jun 2018 16:40:00 +0000 (+0200) Subject: bpo-33750: Reset thread-local context precision in test_round(). (#7355) X-Git-Tag: v3.8.0a1~1682 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e95dfc5006d19e59c7871faa9973356844ddb3ae;p=python bpo-33750: Reset thread-local context precision in test_round(). (#7355) --- diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 5aea51e8b7..58bde54b0a 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)