1
- # Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
1
+ # Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2
2
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3
3
#
4
4
# The Universal Permissive License (UPL), Version 1.0
@@ -60,29 +60,29 @@ def test_int_subclassing():
60
60
MAXREPEAT = _NamedIntConstant (1 , 'MAXREPEAT' )
61
61
assert MAXREPEAT == 1
62
62
assert str (MAXREPEAT ) == "MAXREPEAT"
63
-
63
+
64
64
65
65
def test_boolean2int ():
66
66
assert int (True ) == 1
67
67
assert int (False ) == 0
68
-
69
-
68
+
69
+
70
70
def test_int_from_custom ():
71
71
class CustomInt4 ():
72
72
def __int__ (self ):
73
73
return 1
74
-
74
+
75
75
class CustomInt8 ():
76
76
def __int__ (self ):
77
77
return 0xCAFEBABECAFED00D
78
-
78
+
79
79
class SubInt (int ):
80
80
def __int__ (self ):
81
81
return 0xBADF00D
82
-
82
+
83
83
class NoInt ():
84
84
pass
85
-
85
+
86
86
assert int (CustomInt4 ()) == 1
87
87
assert int (CustomInt8 ()) == 0xCAFEBABECAFED00D
88
88
assert CustomInt8 () != 0xCAFEBABECAFED00D
@@ -124,7 +124,7 @@ def builtinTest(number):
124
124
builtinTest (9 )
125
125
builtinTest (6227020800 )
126
126
builtinTest (9999992432902008176640000999999 )
127
-
127
+
128
128
assert True .__int__ () == 1
129
129
assert False .__int__ () == 0
130
130
@@ -161,13 +161,13 @@ def builtinTest(number):
161
161
builtinTest (9 )
162
162
builtinTest (6227020800 )
163
163
builtinTest (9999992432902008176640000999999 )
164
-
164
+
165
165
assert True .real == 1
166
166
assert False .real == 0
167
167
assert True .imag == 0
168
168
assert False .imag == 0
169
169
170
- def test_real_imag_subclass ():
170
+ def test_real_imag_subclass ():
171
171
def subclassTest (number ):
172
172
a = MyInt (number )
173
173
b = a .real
@@ -202,7 +202,7 @@ def builtinTest(number):
202
202
builtinTest (9 )
203
203
builtinTest (6227020800 )
204
204
builtinTest (9999992432902008176640000999999 )
205
-
205
+
206
206
assert True .numerator == 1
207
207
assert False .numerator == 0
208
208
assert True .denominator == 1
@@ -240,7 +240,7 @@ def builtinTest(number):
240
240
builtinTest (9 )
241
241
builtinTest (6227020800 )
242
242
builtinTest (9999992432902008176640000999999 )
243
-
243
+
244
244
assert True .conjugate () == 1
245
245
assert False .conjugate () == 0
246
246
@@ -282,7 +282,7 @@ def builtinTest(number):
282
282
builtinTest (9 )
283
283
builtinTest (6227020800 )
284
284
builtinTest (9999992432902008176640000999999 )
285
-
285
+
286
286
assert True .__trunc__ () == 1
287
287
assert False .__trunc__ () == 0
288
288
@@ -325,7 +325,7 @@ def test_create_int_from_string():
325
325
326
326
327
327
class FromBytesTests (unittest .TestCase ):
328
-
328
+
329
329
def check (self , tests , byteorder , signed = False ):
330
330
for test , expected in tests .items ():
331
331
try :
@@ -447,10 +447,10 @@ def test_from_list(self):
447
447
class LyingList (list ):
448
448
def __iter__ (self ):
449
449
return iter ([10 , 20 , 30 , 40 ])
450
-
450
+
451
451
self .assertEqual (
452
452
int .from_bytes (LyingList ([255 , 1 , 1 ]), 'big' ), 169090600 )
453
-
453
+
454
454
def test_from_tuple (self ):
455
455
self .assertEqual (
456
456
int .from_bytes ((255 , 0 , 0 ), 'big' , signed = True ), - 65536 )
@@ -464,7 +464,7 @@ def __iter__(self):
464
464
return iter ((15 , 25 , 35 , 45 ))
465
465
self .assertEqual (
466
466
int .from_bytes (LyingTuple ((255 , 1 , 1 )), 'big' ), 253305645 )
467
-
467
+
468
468
def test_from_bytearray (self ):
469
469
self .assertEqual (int .from_bytes (
470
470
bytearray (b'\xff \x00 \x00 ' ), 'big' , signed = True ), - 65536 )
@@ -487,11 +487,10 @@ def test_wrong_input(self):
487
487
self .assertRaises (TypeError , int .from_bytes , 0 , 'big' )
488
488
self .assertRaises (TypeError , int .from_bytes , 0 , 'big' , True )
489
489
490
- #TODO uncoment these tests, when GR-12453 is fixed
491
- #self.assertRaises(TypeError, int.from_bytes, "", 'big')
492
- #self.assertRaises(TypeError, int.from_bytes, "\x00", 'big')
493
- #self.assertRaises(TypeError, MyInt.from_bytes, "", 'big')
494
- #self.assertRaises(TypeError, MyInt.from_bytes, "\x00", 'big')
490
+ self .assertRaises (TypeError , int .from_bytes , "" , 'big' )
491
+ self .assertRaises (TypeError , int .from_bytes , "\x00 " , 'big' )
492
+ self .assertRaises (TypeError , MyInt .from_bytes , "" , 'big' )
493
+ self .assertRaises (TypeError , MyInt .from_bytes , "\x00 " , 'big' )
495
494
self .assertRaises (TypeError , MyInt .from_bytes , 0 , 'big' )
496
495
self .assertRaises (TypeError , int .from_bytes , 0 , 'big' , True )
497
496
@@ -550,7 +549,7 @@ class mybyteslike2():
550
549
def __bytes__ (self ):
551
550
return array .array ('b' , [2 , 2 , 3 ])
552
551
553
- self .assertRaises (TypeError , int .from_bytes , mybyteslike2 (), 'big' )
552
+ self .assertRaises (TypeError , int .from_bytes , mybyteslike2 (), 'big' )
554
553
555
554
def test_from_list_with_byteslike (self ):
556
555
class StrangeList (list ):
@@ -564,7 +563,7 @@ def __iter__(self):
564
563
class ToBytesTests (unittest .TestCase ):
565
564
566
565
class MyInt (int ):
567
- pass
566
+ pass
568
567
569
568
def check (self , tests , byteorder , signed = False ):
570
569
for test , expected in tests .items ():
@@ -634,7 +633,7 @@ def test_SignedLittleEndian(self):
634
633
}
635
634
self .check (tests2 , 'little' , signed = True )
636
635
self .checkPIntSpec (tests2 , 'little' , signed = True )
637
-
636
+
638
637
def test_UnsignedBigEndian (self ):
639
638
# Convert integers to unsigned big-endian byte arrays.
640
639
tests3 = {
@@ -706,7 +705,5 @@ def __int__(self):
706
705
return 3
707
706
def __index__ (self ):
708
707
return 4
709
-
710
- self .assertEqual (MyTest (1 ).to_bytes (MyTest (10 ), 'big' ), b'\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x01 ' )
711
-
712
708
709
+ self .assertEqual (MyTest (1 ).to_bytes (MyTest (10 ), 'big' ), b'\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x01 ' )
0 commit comments