File tree 1 file changed +20
-8
lines changed
1 file changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -119,15 +119,27 @@ def test_float_memoryview(self):
119
119
self .assertEqual (float (memoryview (b'12.34' )[1 :4 ]), 2.3 )
120
120
121
121
def test_error_message (self ):
122
- testlist = ('\xbd ' , '123\xbd ' , ' 123 456 ' )
123
- for s in testlist :
124
- try :
122
+ def check (s ):
123
+ with self .assertRaises (ValueError , msg = 'float(%r)' % (s ,)) as cm :
125
124
float (s )
126
- except ValueError as e :
127
- self .assertIn (s .strip (), e .args [0 ])
128
- else :
129
- self .fail ("Expected int(%r) to raise a ValueError" , s )
130
-
125
+ self .assertEqual (str (cm .exception ),
126
+ 'could not convert string to float: %r' % (s ,))
127
+
128
+ check ('\xbd ' )
129
+ check ('123\xbd ' )
130
+ check (' 123 456 ' )
131
+ check (b' 123 456 ' )
132
+
133
+ # non-ascii digits (error came from non-digit '!')
134
+ check ('\u0663 \u0661 \u0664 !' )
135
+ # embedded NUL
136
+ check ('123\x00 ' )
137
+ check ('123\x00 245' )
138
+ check ('123\x00 245' )
139
+ # byte string with embedded NUL
140
+ check (b'123\x00 ' )
141
+ # non-UTF-8 byte string
142
+ check (b'123\xa0 ' )
131
143
132
144
@support .run_with_locale ('LC_NUMERIC' , 'fr_FR' , 'de_DE' )
133
145
def test_float_with_comma (self ):
You can’t perform that action at this time.
0 commit comments