diff options
| author | Mark Dickinson <dickinsm@gmail.com> | 2008-03-25 18:47:59 (GMT) |
|---|---|---|
| committer | Mark Dickinson <dickinsm@gmail.com> | 2008-03-25 18:47:59 (GMT) |
| commit | 8e85ffa4b213be809109180142a107a1ac66f4d5 (patch) | |
| tree | be8be758b90490e46c83c0f0d4bbf49536bd0de2 /Lib/test/test_decimal.py | |
| parent | cdde579fb9d3ccadff3f3e334d59b26aa74941f0 (diff) | |
| download | cpython-8e85ffa4b213be809109180142a107a1ac66f4d5.zip cpython-8e85ffa4b213be809109180142a107a1ac66f4d5.tar.gz cpython-8e85ffa4b213be809109180142a107a1ac66f4d5.tar.bz2 | |
Issue #2482: Make sure that the coefficient of a Decimal
instance is always stored as a str instance, even
when that Decimal has been created from a unicode string.
Diffstat (limited to 'Lib/test/test_decimal.py')
| -rw-r--r-- | Lib/test/test_decimal.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 46d2dc7..ce6acb6 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -434,6 +434,12 @@ class DecimalExplicitConstructionTest(unittest.TestCase): self.assertEqual(str(Decimal('1.3E4 \n')), '1.3E+4') self.assertEqual(str(Decimal(' -7.89')), '-7.89') + #unicode strings should be permitted + self.assertEqual(str(Decimal(u'0E-017')), '0E-17') + self.assertEqual(str(Decimal(u'45')), '45') + self.assertEqual(str(Decimal(u'-Inf')), '-Infinity') + self.assertEqual(str(Decimal(u'NaN123')), 'NaN123') + def test_explicit_from_tuples(self): #zero @@ -1149,6 +1155,16 @@ class DecimalUsabilityTest(unittest.TestCase): self.assertEqual(str(d), '15.32') # str self.assertEqual(repr(d), "Decimal('15.32')") # repr + # result type of string methods should be str, not unicode + unicode_inputs = [u'123.4', u'0.5E2', u'Infinity', u'sNaN', + u'-0.0E100', u'-NaN001', u'-Inf'] + + for u in unicode_inputs: + d = Decimal(u) + self.assertEqual(type(str(d)), str) + self.assertEqual(type(repr(d)), str) + self.assertEqual(type(d.to_eng_string()), str) + def test_tonum_methods(self): #Test float, int and long methods. |
