Commit 9e6ac83a authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

bpo-29773: Add more cases for testing string to float conversion errors. (#580)

parent 0f6d7334
...@@ -119,15 +119,27 @@ class GeneralFloatCases(unittest.TestCase): ...@@ -119,15 +119,27 @@ class GeneralFloatCases(unittest.TestCase):
self.assertEqual(float(memoryview(b'12.34')[1:4]), 2.3) self.assertEqual(float(memoryview(b'12.34')[1:4]), 2.3)
def test_error_message(self): def test_error_message(self):
testlist = ('\xbd', '123\xbd', ' 123 456 ') def check(s):
for s in testlist: with self.assertRaises(ValueError, msg='float(%r)' % (s,)) as cm:
try:
float(s) float(s)
except ValueError as e: self.assertEqual(str(cm.exception),
self.assertIn(s.strip(), e.args[0]) 'could not convert string to float: %r' % (s,))
else:
self.fail("Expected int(%r) to raise a ValueError", s) check('\xbd')
check('123\xbd')
check(' 123 456 ')
check(b' 123 456 ')
# non-ascii digits (error came from non-digit '!')
check('\u0663\u0661\u0664!')
# embedded NUL
check('123\x00')
check('123\x00 245')
check('123\x00245')
# byte string with embedded NUL
check(b'123\x00')
# non-UTF-8 byte string
check(b'123\xa0')
@support.run_with_locale('LC_NUMERIC', 'fr_FR', 'de_DE') @support.run_with_locale('LC_NUMERIC', 'fr_FR', 'de_DE')
def test_float_with_comma(self): def test_float_with_comma(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment