summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2008-03-25 18:58:13 +0000
committerMark Dickinson <dickinsm@gmail.com>2008-03-25 18:58:13 +0000
commit0e335a925e9abd2109db43a3d660ae24af028e0c (patch)
treee2348d4e88a054458d9bcb6b4c98cd4e31b719d8 /Lib/test
parentf2c98a832f9331709ae1b4bccce67f6a4a845a9c (diff)
downloadcpython-0e335a925e9abd2109db43a3d660ae24af028e0c.tar.gz
Issue #2482: Make sure that the coefficient of a Decimal instance
is stored as a str instance rather than a unicode instance. Backported from Python 2.6 (see r61904).
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_decimal.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index efaa174301..db55b83fc3 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -429,6 +429,12 @@ class DecimalExplicitConstructionTest(unittest.TestCase):
#just not a number
self.assertEqual(str(Decimal('ugly')), 'NaN')
+ #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
@@ -1032,6 +1038,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.