@@ -386,15 +386,6 @@ def __long__(self):
386386 return 42
387387 self .assertRaises (TypeError , int , JustLong ())
388388
389- class LongTrunc :
390- # __long__ should be ignored in 3.x
391- def __long__ (self ):
392- return 42
393- def __trunc__ (self ):
394- return 1729
395- with self .assertWarns (DeprecationWarning ):
396- self .assertEqual (int (LongTrunc ()), 1729 )
397-
398389 def check_float_conversion (self , n ):
399390 # Check that int -> float conversion behaviour matches
400391 # that of the pure Python version above.
@@ -412,7 +403,7 @@ def check_float_conversion(self, n):
412403 "Got {}, expected {}." .format (n , actual , expected ))
413404 self .assertEqual (actual , expected , msg )
414405
415- @unittest .expectedFailure # TODO: RUSTPYTHON
406+ @unittest .expectedFailure # TODO: RUSTPYTHON
416407 @support .requires_IEEE_754
417408 def test_float_conversion (self ):
418409
@@ -483,6 +474,12 @@ def test_float_conversion(self):
483474 self .check_float_conversion (value )
484475 self .check_float_conversion (- value )
485476
477+ @support .requires_IEEE_754
478+ @support .bigmemtest (2 ** 32 , memuse = 0.2 )
479+ def test_float_conversion_huge_integer (self , size ):
480+ v = 1 << size
481+ self .assertRaises (OverflowError , float , v )
482+
486483 def test_float_overflow (self ):
487484 for x in - 2.0 , - 1.0 , 0.0 , 1.0 , 2.0 :
488485 self .assertEqual (float (int (x )), x )
@@ -624,6 +621,56 @@ def __lt__(self, other):
624621 eq (x > y , Rcmp > 0 )
625622 eq (x >= y , Rcmp >= 0 )
626623
624+ @support .requires_IEEE_754
625+ @support .bigmemtest (2 ** 32 , memuse = 0.2 )
626+ def test_mixed_compares_huge_integer (self , size ):
627+ v = 1 << size
628+ f = sys .float_info .max
629+ self .assertIs (f == v , False )
630+ self .assertIs (f != v , True )
631+ self .assertIs (f < v , True )
632+ self .assertIs (f <= v , True )
633+ self .assertIs (f > v , False )
634+ self .assertIs (f >= v , False )
635+ f = float ('inf' )
636+ self .assertIs (f == v , False )
637+ self .assertIs (f != v , True )
638+ self .assertIs (f < v , False )
639+ self .assertIs (f <= v , False )
640+ self .assertIs (f > v , True )
641+ self .assertIs (f >= v , True )
642+ f = float ('nan' )
643+ self .assertIs (f == v , False )
644+ self .assertIs (f != v , True )
645+ self .assertIs (f < v , False )
646+ self .assertIs (f <= v , False )
647+ self .assertIs (f > v , False )
648+ self .assertIs (f >= v , False )
649+
650+ del v
651+ v = (- 1 ) << size
652+ f = - sys .float_info .max
653+ self .assertIs (f == v , False )
654+ self .assertIs (f != v , True )
655+ self .assertIs (f < v , False )
656+ self .assertIs (f <= v , False )
657+ self .assertIs (f > v , True )
658+ self .assertIs (f >= v , True )
659+ f = float ('-inf' )
660+ self .assertIs (f == v , False )
661+ self .assertIs (f != v , True )
662+ self .assertIs (f < v , True )
663+ self .assertIs (f <= v , True )
664+ self .assertIs (f > v , False )
665+ self .assertIs (f >= v , False )
666+ f = float ('nan' )
667+ self .assertIs (f == v , False )
668+ self .assertIs (f != v , True )
669+ self .assertIs (f < v , False )
670+ self .assertIs (f <= v , False )
671+ self .assertIs (f > v , False )
672+ self .assertIs (f >= v , False )
673+
627674 def test__format__ (self ):
628675 self .assertEqual (format (123456789 , 'd' ), '123456789' )
629676 self .assertEqual (format (123456789 , 'd' ), '123456789' )
@@ -823,7 +870,7 @@ def check_truediv(self, a, b, skip_small=True):
823870 self .assertEqual (expected , got , "Incorrectly rounded division {}/{}: "
824871 "expected {}, got {}" .format (a , b , expected , got ))
825872
826- @unittest .expectedFailure # TODO: RUSTPYTHON
873+ @unittest .expectedFailure # TODO: RUSTPYTHON
827874 @support .requires_IEEE_754
828875 def test_correctly_rounded_true_division (self ):
829876 # more stringent tests than those above, checking that the
@@ -944,9 +991,12 @@ def test_huge_lshift_of_zero(self):
944991 self .assertEqual (0 << (sys .maxsize + 1 ), 0 )
945992
946993 @support .cpython_only
947- @support .bigmemtest (sys . maxsize + 1000 , memuse = 2 / 15 * 2 , dry_run = False )
994+ @support .bigmemtest (2 ** 32 , memuse = 0.2 )
948995 def test_huge_lshift (self , size ):
949- self .assertEqual (1 << (sys .maxsize + 1000 ), 1 << 1000 << sys .maxsize )
996+ v = 5 << size
997+ self .assertEqual (v .bit_length (), size + 3 )
998+ self .assertEqual (v .bit_count (), 2 )
999+ self .assertEqual (v >> size , 5 )
9501000
9511001 def test_huge_rshift (self ):
9521002 huge_shift = 1 << 1000
@@ -958,11 +1008,13 @@ def test_huge_rshift(self):
9581008 self .assertEqual (- 2 ** 128 >> huge_shift , - 1 )
9591009
9601010 @support .cpython_only
961- @support .bigmemtest (sys . maxsize + 500 , memuse = 2 / 15 , dry_run = False )
1011+ @support .bigmemtest (2 ** 32 , memuse = 0.2 )
9621012 def test_huge_rshift_of_huge (self , size ):
963- huge = ((1 << 500 ) + 11 ) << sys .maxsize
964- self .assertEqual (huge >> (sys .maxsize + 1 ), (1 << 499 ) + 5 )
965- self .assertEqual (huge >> (sys .maxsize + 1000 ), 0 )
1013+ huge = ((1 << 500 ) + 11 ) << size
1014+ self .assertEqual (huge .bit_length (), size + 501 )
1015+ self .assertEqual (huge .bit_count (), 4 )
1016+ self .assertEqual (huge >> (size + 1 ), (1 << 499 ) + 5 )
1017+ self .assertEqual (huge >> (size + 1000 ), 0 )
9661018
9671019 def test_small_rshift (self ):
9681020 self .assertEqual (42 >> 1 , 21 )
@@ -1347,7 +1399,7 @@ class SubStr(str):
13471399 self .assertEqual ((0 ).to_bytes (1 , SubStr ('big' )), b'\x00 ' )
13481400 self .assertEqual ((0 ).to_bytes (0 , SubStr ('little' )), b'' )
13491401
1350- @unittest .expectedFailure # TODO: RUSTPYTHON
1402+ @unittest .expectedFailure # TODO: RUSTPYTHON
13511403 def test_from_bytes (self ):
13521404 def check (tests , byteorder , signed = False ):
13531405 def equivalent_python (byte_array , byteorder , signed = False ):
@@ -1426,7 +1478,6 @@ def equivalent_python(byte_array, byteorder, signed=False):
14261478 b'\x00 ' : 0 ,
14271479 b'\x00 \x00 ' : 0 ,
14281480 b'\x01 ' : 1 ,
1429- b'\x00 \x01 ' : 256 ,
14301481 b'\xff ' : - 1 ,
14311482 b'\xff \xff ' : - 1 ,
14321483 b'\x81 ' : - 127 ,
@@ -1609,7 +1660,7 @@ def test_square(self):
16091660 self .assertEqual (n ** 2 ,
16101661 (1 << (2 * bitlen )) - (1 << (bitlen + 1 )) + 1 )
16111662
1612- @unittest .expectedFailure # TODO: RUSTPYTHON
1663+ @unittest .expectedFailure # TODO: RUSTPYTHON
16131664 def test___sizeof__ (self ):
16141665 self .assertEqual (int .__itemsize__ , sys .int_info .sizeof_digit )
16151666
0 commit comments