From f484363baecbe69def74a4535cb9545869424dcb Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Sat, 21 Jun 2008 13:47:20 +0000 Subject: Use repr() for bad input strings; this makes the empty string or binary characters more visible --- Lib/fractions.py | 2 +- Lib/test/test_fractions.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Lib/fractions.py b/Lib/fractions.py index 0d85f15..f06e4d4 100755 --- a/Lib/fractions.py +++ b/Lib/fractions.py @@ -70,7 +70,7 @@ class Fraction(Rational): input = numerator m = _RATIONAL_FORMAT.match(input) if m is None: - raise ValueError('Invalid literal for Fraction: ' + input) + raise ValueError('Invalid literal for Fraction: %r' % input) numerator = m.group('num') decimal = m.group('decimal') if decimal: diff --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py index 743f094..3d90b5a 100644 --- a/Lib/test/test_fractions.py +++ b/Lib/test/test_fractions.py @@ -86,38 +86,38 @@ class FractionTest(unittest.TestCase): ZeroDivisionError, "Fraction(3, 0)", F, "3/0") self.assertRaisesMessage( - ValueError, "Invalid literal for Fraction: 3/", + ValueError, "Invalid literal for Fraction: '3/'", F, "3/") self.assertRaisesMessage( - ValueError, "Invalid literal for Fraction: 3 /2", + ValueError, "Invalid literal for Fraction: '3 /2'", F, "3 /2") self.assertRaisesMessage( # Denominators don't need a sign. - ValueError, "Invalid literal for Fraction: 3/+2", + ValueError, "Invalid literal for Fraction: '3/+2'", F, "3/+2") self.assertRaisesMessage( # Imitate float's parsing. - ValueError, "Invalid literal for Fraction: + 3/2", + ValueError, "Invalid literal for Fraction: '+ 3/2'", F, "+ 3/2") self.assertRaisesMessage( # Avoid treating '.' as a regex special character. - ValueError, "Invalid literal for Fraction: 3a2", + ValueError, "Invalid literal for Fraction: '3a2'", F, "3a2") self.assertRaisesMessage( # Only parse ordinary decimals, not scientific form. - ValueError, "Invalid literal for Fraction: 3.2e4", + ValueError, "Invalid literal for Fraction: '3.2e4'", F, "3.2e4") self.assertRaisesMessage( # Don't accept combinations of decimals and fractions. - ValueError, "Invalid literal for Fraction: 3/7.2", + ValueError, "Invalid literal for Fraction: '3/7.2'", F, "3/7.2") self.assertRaisesMessage( # Don't accept combinations of decimals and fractions. - ValueError, "Invalid literal for Fraction: 3.2/7", + ValueError, "Invalid literal for Fraction: '3.2/7'", F, "3.2/7") self.assertRaisesMessage( # Allow 3. and .3, but not . - ValueError, "Invalid literal for Fraction: .", + ValueError, "Invalid literal for Fraction: '.'", F, ".") def testImmutable(self): -- cgit v0.12