File tree Expand file tree Collapse file tree 1 file changed +20
-8
lines changed Expand file tree Collapse file tree 1 file changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -98,15 +98,27 @@ def test_float_memoryview(self):
9898 self .assertEqual (float (memoryview (b'12.34' )[1 :4 ]), 2.3 )
9999
100100 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 :
104103 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\x00 245' )
118+ # byte string with embedded NUL
119+ check (b'123\x00 ' )
120+ # non-UTF-8 byte string
121+ check (b'123\xa0 ' )
110122
111123 @support .run_with_locale ('LC_NUMERIC' , 'fr_FR' , 'de_DE' )
112124 def test_float_with_comma (self ):
You can’t perform that action at this time.
0 commit comments