[3.5] bpo-29773: Add more cases for testing string to float conversio… · python/cpython@5fad493 (original) (raw)

`@@ -98,15 +98,27 @@ def test_float_memoryview(self):

`

98

98

`self.assertEqual(float(memoryview(b'12.34')[1:4]), 2.3)

`

99

99

``

100

100

`def test_error_message(self):

`

101

``

`-

testlist = ('\xbd', '123\xbd', ' 123 456 ')

`

102

``

`-

for s in testlist:

`

103

``

`-

try:

`

``

101

`+

def check(s):

`

``

102

`+

with self.assertRaises(ValueError, msg='float(%r)' % (s,)) as cm:

`

104

103

`float(s)

`

105

``

`-

except ValueError as e:

`

106

``

`-

self.assertIn(s.strip(), e.args[0])

`

107

``

`-

else:

`

108

``

`-

self.fail("Expected int(%r) to raise a ValueError", s)

`

109

``

-

``

104

`+

self.assertEqual(str(cm.exception),

`

``

105

`+

'could not convert string to float: %r' % (s,))

`

``

106

+

``

107

`+

check('\xbd')

`

``

108

`+

check('123\xbd')

`

``

109

`+

check(' 123 456 ')

`

``

110

`+

check(b' 123 456 ')

`

``

111

+

``

112

`+

non-ascii digits (error came from non-digit '!')

`

``

113

`+

check('\u0663\u0661\u0664!')

`

``

114

`+

embedded NUL

`

``

115

`+

check('123\x00')

`

``

116

`+

check('123\x00 245')

`

``

117

`+

check('123\x00245')

`

``

118

`+

byte string with embedded NUL

`

``

119

`+

check(b'123\x00')

`

``

120

`+

non-UTF-8 byte string

`

``

121

`+

check(b'123\xa0')

`

110

122

``

111

123

`@support.run_with_locale('LC_NUMERIC', 'fr_FR', 'de_DE')

`

112

124

`def test_float_with_comma(self):

`