summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_float.py
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-12-04 03:38:46 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-12-04 03:38:46 (GMT)
commit942af5a9a45b7b4976bea2e794eccaaf2b3b5c09 (patch)
treef621bdffa16dd0b04d7bf60d6a32f198fc7b3ec8 /Lib/test/test_float.py
parent36526bf3d95763afa6d4efe402b8840b1532d637 (diff)
downloadcpython-942af5a9a45b7b4976bea2e794eccaaf2b3b5c09.zip
cpython-942af5a9a45b7b4976bea2e794eccaaf2b3b5c09.tar.gz
cpython-942af5a9a45b7b4976bea2e794eccaaf2b3b5c09.tar.bz2
Issue #10557: Fixed error messages from float() and other numeric
types. Added a new API function, PyUnicode_TransformDecimalToASCII(), which transforms non-ASCII decimal digits in a Unicode string to their ASCII equivalents.
Diffstat (limited to 'Lib/test/test_float.py')
-rw-r--r--Lib/test/test_float.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index 0072133..9bcd63d 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -43,14 +43,30 @@ class GeneralFloatCases(unittest.TestCase):
self.assertRaises(ValueError, float, "+.inf")
self.assertRaises(ValueError, float, ".")
self.assertRaises(ValueError, float, "-.")
+ self.assertRaises(ValueError, float, b"-")
+ self.assertRaises(TypeError, float, {})
+ # Lone surrogate
+ self.assertRaises(UnicodeEncodeError, float, '\uD8F0')
# check that we don't accept alternate exponent markers
self.assertRaises(ValueError, float, "-1.7d29")
self.assertRaises(ValueError, float, "3D-14")
- self.assertEqual(float(b" \u0663.\u0661\u0664 ".decode('raw-unicode-escape')), 3.14)
+ self.assertEqual(float(" \u0663.\u0661\u0664 "), 3.14)
+ self.assertEqual(float("\N{EM SPACE}3.14\N{EN SPACE}"), 3.14)
# extra long strings should not be a problem
float(b'.' + b'1'*1000)
float('.' + '1'*1000)
+ def test_error_message(self):
+ testlist = ('\xbd', '123\xbd', ' 123 456 ')
+ for s in testlist:
+ try:
+ float(s)
+ except ValueError as e:
+ self.assertIn(s.strip(), e.args[0])
+ else:
+ self.fail("Expected int(%r) to raise a ValueError", s)
+
+
@support.run_with_locale('LC_NUMERIC', 'fr_FR', 'de_DE')
def test_float_with_comma(self):
# set locale to something that doesn't use '.' for the decimal point