25
25
26
26
#locate file with float format test values
27
27
test_dir = os .path .dirname (__file__ ) or os .curdir
28
- format_testfile = os .path .join (test_dir , 'formatfloat_testcases.txt' )
28
+ format_testfile = os .path .join (test_dir , 'mathdata' , ' formatfloat_testcases.txt' )
29
29
30
30
class FloatSubclass (float ):
31
31
pass
@@ -131,7 +131,7 @@ def check(s):
131
131
with self .assertRaises (ValueError , msg = 'float(%r)' % (s ,)) as cm :
132
132
float (s )
133
133
self .assertEqual (str (cm .exception ),
134
- 'could not convert string to float: %r' % (s ,))
134
+ 'could not convert string to float: %r' % (s ,))
135
135
136
136
check ('\xbd ' )
137
137
check ('123\xbd ' )
@@ -290,11 +290,11 @@ def test_is_integer(self):
290
290
291
291
def test_floatasratio (self ):
292
292
for f , ratio in [
293
- (0.875 , (7 , 8 )),
294
- (- 0.875 , (- 7 , 8 )),
295
- (0.0 , (0 , 1 )),
296
- (11.5 , (23 , 2 )),
297
- ]:
293
+ (0.875 , (7 , 8 )),
294
+ (- 0.875 , (- 7 , 8 )),
295
+ (0.0 , (0 , 1 )),
296
+ (11.5 , (23 , 2 )),
297
+ ]:
298
298
self .assertEqual (f .as_integer_ratio (), ratio )
299
299
300
300
for i in range (10000 ):
@@ -337,7 +337,7 @@ def test_float_containment(self):
337
337
self .assertTrue ((f ,) == (f ,), "(%r,) != (%r,)" % (f , f ))
338
338
self .assertTrue ({f } == {f }, "{%r} != {%r}" % (f , f ))
339
339
self .assertTrue ({f : None } == {f : None }, "{%r : None} != "
340
- "{%r : None}" % (f , f ))
340
+ "{%r : None}" % (f , f ))
341
341
342
342
# identical containers
343
343
l , t , s , d = [f ], (f ,), {f }, {f : None }
@@ -400,9 +400,9 @@ def test_float_mod(self):
400
400
self .assertEqualAndEqualSign (mod (1e-100 , - 1.0 ), - 1.0 )
401
401
self .assertEqualAndEqualSign (mod (1.0 , - 1.0 ), - 0.0 )
402
402
403
+ @support .requires_IEEE_754
403
404
# TODO: RUSTPYTHON
404
405
@unittest .expectedFailure
405
- @support .requires_IEEE_754
406
406
def test_float_pow (self ):
407
407
# test builtin pow and ** operator for IEEE 754 special cases.
408
408
# Special cases taken from section F.9.4.4 of the C99 specification
@@ -728,6 +728,8 @@ def test_format(self):
728
728
self .assertEqual (format (INF , 'F' ), 'INF' )
729
729
730
730
@support .requires_IEEE_754
731
+ # TODO: RUSTPYTHON
732
+ @unittest .expectedFailure
731
733
def test_format_testfile (self ):
732
734
with open (format_testfile , encoding = "utf-8" ) as testfile :
733
735
for line in testfile :
@@ -772,9 +774,12 @@ def test_issue35560(self):
772
774
self .assertEqual (format (- 123.34 , '00.10g' ), '-123.34' )
773
775
774
776
class ReprTestCase (unittest .TestCase ):
777
+ # TODO: RUSTPYTHON
778
+ @unittest .expectedFailure
775
779
def test_repr (self ):
776
780
with open (os .path .join (os .path .split (__file__ )[0 ],
777
- 'floating_points.txt' ), encoding = "utf-8" ) as floats_file :
781
+ 'mathdata' ,
782
+ 'floating_points.txt' ), encoding = "utf-8" ) as floats_file :
778
783
for line in floats_file :
779
784
line = line .strip ()
780
785
if not line or line .startswith ('#' ):
@@ -824,7 +829,7 @@ def test_short_repr(self):
824
829
'2.86438000439698e+28' ,
825
830
'8.89142905246179e+28' ,
826
831
'3.08578087079232e+35' ,
827
- ]
832
+ ]
828
833
829
834
for s in test_strings :
830
835
negs = '-' + s
@@ -874,14 +879,14 @@ def test_overflow(self):
874
879
self .assertRaises (OverflowError , round , 1.6e308 , - 308 )
875
880
self .assertRaises (OverflowError , round , - 1.7e308 , - 308 )
876
881
877
- # TODO: RUSTPYTHON
878
- @unittest .expe
B41A
ctedFailure
879
882
@unittest .skipUnless (getattr (sys , 'float_repr_style' , '' ) == 'short' ,
880
883
"applies only when using short float repr style" )
884
+ # TODO: RUSTPYTHON
885
+ @unittest .expectedFailure
881
886
def test_previous_round_bugs (self ):
882
887
# particular cases that have occurred in bug reports
883
888
self .assertEqual (round (562949953421312.5 , 1 ),
884
- 562949953421312.5 )
889
+ 562949953421312.5 )
885
890
self .assertEqual (round (56294995342131.5 , 3 ),
886
891
56294995342131.5 )
887
892
# round-half-even
@@ -894,10 +899,10 @@ def test_previous_round_bugs(self):
894
899
self .assertEqual (round (85.0 , - 1 ), 80.0 )
895
900
self .assertEqual (round (95.0 , - 1 ), 100.0 )
896
901
897
- # TODO: RUSTPYTHON
898
- @unittest .expectedFailure
899
902
@unittest .skipUnless (getattr (sys , 'float_repr_style' , '' ) == 'short' ,
900
903
"applies only when using short float repr style" )
904
+ # TODO: RUSTPYTHON
905
+ @unittest .expectedFailure
901
906
def test_matches_float_format (self ):
902
907
# round should give the same results as float formatting
903
908
for i in range (500 ):
10A5F
@@ -1131,7 +1136,7 @@ def test_invalid_inputs(self):
1131
1136
'0x1.\uff10 p0' ,
1132
1137
'0x1p0 \n 0x2p0' ,
1133
1138
'0x1p0\0 0x1p0' , # embedded null byte is not end of string
1134
- ]
1139
+ ]
1135
1140
for x in invalid_inputs :
1136
1141
try :
1137
1142
result = fromHex (x )
@@ -1150,7 +1155,7 @@ def test_whitespace(self):
1150
1155
('1.0' , 1.0 ),
1151
1156
('-0x.2' , - 0.125 ),
1152
1157
('-0.0' , - 0.0 )
1153
- ]
1158
+ ]
1154
1159
whitespace = [
1155
1160
'' ,
1156
1161
' ' ,
@@ -1160,7 +1165,7 @@ def test_whitespace(self):
1160
1165
'\f ' ,
1161
1166
'\v ' ,
1162
1167
'\r '
1163
- ]
1168
+ ]
1164
1169
for inp , expected in value_pairs :
1165
1170
for lead in whitespace :
1166
1171
for trail in whitespace :
@@ -1510,4 +1515,4 @@ def __init__(self, value):
1510
1515
1511
1516
1512
1517
if __name__ == '__main__' :
1513
- unittest .main ()
1518
+ unittest .main ()
0 commit comments