diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-04-22 17:50:21 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-04-22 17:50:21 (GMT) |
commit | cf63f2fb88826ae67843b8574bca6ef25c2e791f (patch) | |
tree | 81dbf873651fdd3f9a2dcabd3c291d9911aad609 /Lib/test | |
parent | 937491d1a9a327a782f3717fd1a0d4d9ad8fdc36 (diff) | |
download | cpython-cf63f2fb88826ae67843b8574bca6ef25c2e791f.zip cpython-cf63f2fb88826ae67843b8574bca6ef25c2e791f.tar.gz cpython-cf63f2fb88826ae67843b8574bca6ef25c2e791f.tar.bz2 |
Issue #5812: Make Fraction('1e6') valid. The Fraction constructor now
accepts all strings accepted by the float and Decimal constructors,
with the exception of strings representing NaNs or infinities.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_fractions.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py index 91fcd26..448e32d 100644 --- a/Lib/test/test_fractions.py +++ b/Lib/test/test_fractions.py @@ -78,6 +78,11 @@ class FractionTest(unittest.TestCase): self.assertEquals((-16, 5), _components(F(" -3.2 "))) self.assertEquals((-3, 1), _components(F(" -3. "))) self.assertEquals((3, 5), _components(F(" .6 "))) + self.assertEquals((1, 3125), _components(F("32.e-5"))) + self.assertEquals((1000000, 1), _components(F("1E+06"))) + self.assertEquals((-12300, 1), _components(F("-1.23e4"))) + self.assertEquals((0, 1), _components(F(" .0e+0\t"))) + self.assertEquals((0, 1), _components(F("-0.000e0"))) self.assertRaisesMessage( ZeroDivisionError, "Fraction(3, 0)", @@ -86,6 +91,9 @@ class FractionTest(unittest.TestCase): ValueError, "Invalid literal for Fraction: '3/'", F, "3/") self.assertRaisesMessage( + ValueError, "Invalid literal for Fraction: '/2'", + F, "/2") + self.assertRaisesMessage( ValueError, "Invalid literal for Fraction: '3 /2'", F, "3 /2") self.assertRaisesMessage( @@ -101,10 +109,6 @@ class FractionTest(unittest.TestCase): ValueError, "Invalid literal for Fraction: '3a2'", F, "3a2") self.assertRaisesMessage( - # Only parse ordinary decimals, not scientific form. - ValueError, "Invalid literal for Fraction: '3.2e4'", - F, "3.2e4") - self.assertRaisesMessage( # Don't accept combinations of decimals and rationals. ValueError, "Invalid literal for Fraction: '3/7.2'", F, "3/7.2") |