Index: Lib/test/test_decimal.py =================================================================== --- Lib/test/test_decimal.py (revision 77468) +++ Lib/test/test_decimal.py (working copy) @@ -479,25 +479,21 @@ d = Decimal(45) e = Decimal(d) self.assertEqual(str(e), '45') - self.assertNotEqual(id(d), id(e)) #very large positive d = Decimal(500000123) e = Decimal(d) self.assertEqual(str(e), '500000123') - self.assertNotEqual(id(d), id(e)) #negative d = Decimal(-45) e = Decimal(d) self.assertEqual(str(e), '-45') - self.assertNotEqual(id(d), id(e)) #zero d = Decimal(0) e = Decimal(d) self.assertEqual(str(e), '0') - self.assertNotEqual(id(d), id(e)) def test_explicit_context_create_decimal(self): @@ -778,7 +774,7 @@ en_US = { 'decimal_point' : '.', 'grouping' : [3, 3, 0], - 'thousands_sep': ',' + 'thousands_sep' : ',' } fr_FR = { @@ -799,6 +795,11 @@ 'thousands_sep' : '-' } + dotsep_wide = { + 'decimal_point' : b'\xc2\xbf'.decode('utf-8'), + 'grouping': [3, 3, 0], + 'thousands_sep' : b'\xc2\xb4'.decode('utf-8') + } def get_fmt(x, locale, fmt='n'): return Decimal.__format__(Decimal(x), fmt, _localeconv=locale) @@ -840,6 +841,9 @@ self.assertEqual(get_fmt(123456, crazy, '012n'), '00-01-2345-6') self.assertEqual(get_fmt(123456, crazy, '013n'), '000-01-2345-6') + # wide char separator and decimal point + self.assertEqual(get_fmt(Decimal('-1.5'), dotsep_wide, '020n'), + '-0´000´000´000´001¿5') class DecimalArithmeticOperatorsTest(unittest.TestCase): '''Unit tests for all arithmetic operators, binary and unary.''' @@ -1088,8 +1092,8 @@ test2 = d1/d3 cls.finish1.set() - cls.assertEqual(test1, Decimal('0.3333333333333333333333333333')) - cls.assertEqual(test2, Decimal('0.3333333333333333333333333333')) + cls.assertEqual(test1, Decimal('0.333333333333333333333333')) + cls.assertEqual(test2, Decimal('0.333333333333333333333333')) return def thfunc2(cls): @@ -1102,7 +1106,7 @@ cls.synchro.set() cls.finish2.set() - cls.assertEqual(test1, Decimal('0.3333333333333333333333333333')) + cls.assertEqual(test1, Decimal('0.333333333333333333333333')) cls.assertEqual(test2, Decimal('0.333333333333333333')) return @@ -1119,7 +1123,11 @@ # that hangs IDLE and I couldn't find it def test_threading(self): - #Test the "threading isolation" of a Context. + # Test the "threading isolation" of a Context. Also test changing + # the DefaultContext, which acts as a template for the thread-local + # contexts. + saveprec = DefaultContext.prec + DefaultContext.prec = 24 self.synchro = threading.Event() self.finish1 = threading.Event() @@ -1133,6 +1141,8 @@ self.finish1.wait() self.finish2.wait() + + DefaultContext.prec = saveprec return if threading is None: @@ -1615,7 +1625,7 @@ def test_from_float(self): - class MyDecimal(Decimal): + class MyDecimal(Decimal): pass r = MyDecimal.from_float(0.1) @@ -1715,12 +1725,12 @@ # check that the result (numeric result + flags raised) of an # arithmetic operation doesn't depend on the current flags - context = Context(prec=9, Emin = -999999999, Emax = 999999999, - rounding=ROUND_HALF_EVEN, traps=[], flags=[]) + context = Context(prec=9, Emin = -425000000, Emax = 425000000, + rounding=ROUND_HALF_EVEN, traps=[], flags=[]) # operations that raise various flags, in the form (function, arglist) operations = [ - (context._apply, [Decimal("100E-1000000009")]), + (context._apply, [Decimal("100E-425000010")]), (context.sqrt, [Decimal(2)]), (context.add, [Decimal("1.23456789"), Decimal("9.87654321")]), (context.multiply, [Decimal("1.23456789"), Decimal("9.87654321")]),