bpo-34179: Make sure decimal context doesn't affect other tests. (#8376)

This commit is contained in:
Bo Bayles 2018-07-21 12:54:14 -05:00 committed by Stefan Krah
parent 56868f940e
commit 938045f335
1 changed files with 12 additions and 12 deletions

View File

@ -872,19 +872,19 @@ class CPyTimeTestCase:
ns_timestamps = self._rounding_values(use_float) ns_timestamps = self._rounding_values(use_float)
valid_values = convert_values(ns_timestamps) valid_values = convert_values(ns_timestamps)
for time_rnd, decimal_rnd in ROUNDING_MODES : for time_rnd, decimal_rnd in ROUNDING_MODES :
context = decimal.getcontext() with decimal.localcontext() as context:
context.rounding = decimal_rnd context.rounding = decimal_rnd
for value in valid_values: for value in valid_values:
debug_info = {'value': value, 'rounding': decimal_rnd} debug_info = {'value': value, 'rounding': decimal_rnd}
try: try:
result = pytime_converter(value, time_rnd) result = pytime_converter(value, time_rnd)
expected = expected_func(value) expected = expected_func(value)
except Exception as exc: except Exception as exc:
self.fail("Error on timestamp conversion: %s" % debug_info) self.fail("Error on timestamp conversion: %s" % debug_info)
self.assertEqual(result, self.assertEqual(result,
expected, expected,
debug_info) debug_info)
# test overflow # test overflow
ns = self.OVERFLOW_SECONDS * SEC_TO_NS ns = self.OVERFLOW_SECONDS * SEC_TO_NS