diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2010-08-04 20:56:28 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2010-08-04 20:56:28 (GMT) |
commit | 388122d43b2b6bb41774d9680b9ad3bc05682f85 (patch) | |
tree | 4b3059b3dbd916fde44702e732f507788c433fbf /Lib | |
parent | b6c50749207688902a6378958da474f7c31f179d (diff) | |
download | cpython-388122d43b2b6bb41774d9680b9ad3bc05682f85.zip cpython-388122d43b2b6bb41774d9680b9ad3bc05682f85.tar.gz cpython-388122d43b2b6bb41774d9680b9ad3bc05682f85.tar.bz2 |
Issue #9337: Make float.__str__ identical to float.__repr__.
(And similarly for complex numbers.)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/formatfloat_testcases.txt | 64 | ||||
-rw-r--r-- | Lib/test/test_float.py | 4 | ||||
-rw-r--r-- | Lib/test/test_tokenize.py | 4 | ||||
-rw-r--r-- | Lib/test/test_unicodedata.py | 9 |
4 files changed, 38 insertions, 43 deletions
diff --git a/Lib/test/formatfloat_testcases.txt b/Lib/test/formatfloat_testcases.txt index 4cf20aa..9f045b7 100644 --- a/Lib/test/formatfloat_testcases.txt +++ b/Lib/test/formatfloat_testcases.txt @@ -314,43 +314,37 @@ %#.5g 234.56 -> 234.56 %#.6g 234.56 -> 234.560 --- for repr formatting see the separate test_short_repr test in --- test_float.py. Not all platforms use short repr for floats. - --- str formatting. Result always includes decimal point and at +-- repr formatting. Result always includes decimal point and at -- least one digit after the point, or an exponent. -%s 0 -> 0.0 -%s 1 -> 1.0 - -%s 0.01 -> 0.01 -%s 0.02 -> 0.02 -%s 0.03 -> 0.03 -%s 0.04 -> 0.04 -%s 0.05 -> 0.05 +%r 0 -> 0.0 +%r 1 -> 1.0 --- str truncates to 12 significant digits -%s 1.234123412341 -> 1.23412341234 -%s 1.23412341234 -> 1.23412341234 -%s 1.2341234123 -> 1.2341234123 +%r 0.01 -> 0.01 +%r 0.02 -> 0.02 +%r 0.03 -> 0.03 +%r 0.04 -> 0.04 +%r 0.05 -> 0.05 --- values >= 1e11 get an exponent -%s 10 -> 10.0 -%s 100 -> 100.0 -%s 1e10 -> 10000000000.0 -%s 9.999e10 -> 99990000000.0 -%s 99999999999 -> 99999999999.0 -%s 99999999999.9 -> 99999999999.9 -%s 99999999999.99 -> 1e+11 -%s 1e11 -> 1e+11 -%s 1e12 -> 1e+12 +-- values >= 1e16 get an exponent +%r 10 -> 10.0 +%r 100 -> 100.0 +%r 1e15 -> 1000000000000000.0 +%r 9.999e15 -> 9999000000000000.0 +%r 9999999999999998 -> 9999999999999998.0 +%r 9999999999999999 -> 1e+16 +%r 1e16 -> 1e+16 +%r 1e17 -> 1e+17 -- as do values < 1e-4 -%s 1e-3 -> 0.001 -%s 1.001e-4 -> 0.0001001 -%s 1.000000000001e-4 -> 0.0001 -%s 1.00000000001e-4 -> 0.000100000000001 -%s 1.0000000001e-4 -> 0.00010000000001 -%s 1e-4 -> 0.0001 -%s 0.999999999999e-4 -> 9.99999999999e-05 -%s 0.999e-4 -> 9.99e-05 -%s 1e-5 -> 1e-05 +%r 1e-3 -> 0.001 +%r 1.001e-4 -> 0.0001001 +%r 1.0000000000000001e-4 -> 0.0001 +%r 1.000000000000001e-4 -> 0.0001000000000000001 +%r 1.00000000001e-4 -> 0.000100000000001 +%r 1.0000000001e-4 -> 0.00010000000001 +%r 1e-4 -> 0.0001 +%r 0.99999999999999999e-4 -> 0.0001 +%r 0.9999999999999999e-4 -> 9.999999999999999e-05 +%r 0.999999999999e-4 -> 9.99999999999e-05 +%r 0.999e-4 -> 9.99e-05 +%r 1e-5 -> 1e-05 diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index a1b130b..ac5fc33 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -617,7 +617,9 @@ class ReprTestCase(unittest.TestCase): negs = '-'+s self.assertEqual(s, repr(float(s))) self.assertEqual(negs, repr(float(negs))) - + # Since Python 3.2, repr and str are identical + self.assertEqual(repr(float(s)), str(float(s))) + self.assertEqual(repr(float(negs)), str(float(negs))) @requires_IEEE_754 class RoundTestCase(unittest.TestCase): diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py index d0853d3..4b56699 100644 --- a/Lib/test/test_tokenize.py +++ b/Lib/test/test_tokenize.py @@ -598,11 +598,11 @@ def decistmt(s): The format of the exponent is inherited from the platform C library. Known cases are "e-007" (Windows) and "e-07" (not Windows). Since - we're only showing 12 digits, and the 13th isn't close to 5, the + we're only showing 11 digits, and the 12th isn't close to 5, the rest of the output should be platform-independent. >>> exec(s) #doctest: +ELLIPSIS - -3.21716034272e-0...7 + -3.2171603427...e-0...7 Output from calculations with Decimal should be identical across all platforms. diff --git a/Lib/test/test_unicodedata.py b/Lib/test/test_unicodedata.py index 59e6d39..b572261 100644 --- a/Lib/test/test_unicodedata.py +++ b/Lib/test/test_unicodedata.py @@ -80,8 +80,7 @@ class UnicodeDatabaseTest(unittest.TestCase): class UnicodeFunctionsTest(UnicodeDatabaseTest): # update this, if the database changes - expectedchecksum = '6ccf1b1a36460d2694f9b0b0f0324942fe70ede6' - + expectedchecksum = 'e89a6380093a00a7685ac7b92e7367d737fcb79b' def test_function_checksum(self): data = [] h = hashlib.sha1() @@ -90,9 +89,9 @@ class UnicodeFunctionsTest(UnicodeDatabaseTest): char = chr(i) data = [ # Properties - str(self.db.digit(char, -1)), - str(self.db.numeric(char, -1)), - str(self.db.decimal(char, -1)), + format(self.db.digit(char, -1), '.12g'), + format(self.db.numeric(char, -1), '.12g'), + format(self.db.decimal(char, -1), '.12g'), self.db.category(char), self.db.bidirectional(char), self.db.decomposition(char), |