mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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.
This commit is contained in:
parent
36526bf3d9
commit
942af5a9a4
11 changed files with 169 additions and 52 deletions
|
@ -20,7 +20,8 @@ L = [
|
|||
(' 1\02 ', ValueError),
|
||||
('', ValueError),
|
||||
(' ', ValueError),
|
||||
(' \t\t ', ValueError)
|
||||
(' \t\t ', ValueError),
|
||||
("\u0200", ValueError)
|
||||
]
|
||||
|
||||
class IntTestCases(unittest.TestCase):
|
||||
|
@ -35,6 +36,8 @@ class IntTestCases(unittest.TestCase):
|
|||
self.assertEqual(int(3.5), 3)
|
||||
self.assertEqual(int(-3.5), -3)
|
||||
self.assertEqual(int("-3"), -3)
|
||||
self.assertEqual(int(" -3 "), -3)
|
||||
self.assertEqual(int("\N{EM SPACE}-3\N{EN SPACE}"), -3)
|
||||
# Different base:
|
||||
self.assertEqual(int("10",16), 16)
|
||||
# Test conversion from strings and various anomalies
|
||||
|
@ -302,6 +305,16 @@ class IntTestCases(unittest.TestCase):
|
|||
self.fail("Failed to raise TypeError with %s" %
|
||||
((base, trunc_result_base),))
|
||||
|
||||
def test_error_message(self):
|
||||
testlist = ('\xbd', '123\xbd', ' 123 456 ')
|
||||
for s in testlist:
|
||||
try:
|
||||
int(s)
|
||||
except ValueError as e:
|
||||
self.assertIn(s.strip(), e.args[0])
|
||||
else:
|
||||
self.fail("Expected int(%r) to raise a ValueError", s)
|
||||
|
||||
def test_main():
|
||||
run_unittest(IntTestCases)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue