File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1350,6 +1350,29 @@ def __init__(self, value):
1350
1350
self .assertEqual (i , 1 )
1351
1351
self .assertEqual (getattr (i , 'foo' , 'none' ), 'bar' )
1352
1352
1353
+ class ValidBytes :
1354
+ def __bytes__ (self ):
1355
+ return b'\x01 '
1356
+ class InvalidBytes :
1357
+ def __bytes__ (self ):
1358
+ return 'abc'
1359
+ class MissingBytes : ...
1360
+ class RaisingBytes :
1361
+ def __bytes__ (self ):
1362
+ 1 / 0
1363
+
1364
+ self .assertEqual (int .from_bytes (ValidBytes ()), 1 )
1365
+ self .assertRaises (TypeError , int .from_bytes , InvalidBytes ())
1366
+ self .assertRaises (TypeError , int .from_bytes , MissingBytes ())
1367
+ self .assertRaises (ZeroDivisionError , int .from_bytes , RaisingBytes ())
1368
+
1369
+ @support .cpython_only
1370
+ def test_from_bytes_small (self ):
1371
+ # bpo-46361
1372
+ for i in range (- 5 , 257 ):
1373
+ b = i .to_bytes (2 , signed = True )
1374
+ self .assertIs (int .from_bytes (b , signed = True ), i )
1375
+
1353
1376
def test_access_to_nonexistent_digit_0 (self ):
1354
1377
# http://bugs.python.org/issue14630: A bug in _PyLong_Copy meant that
1355
1378
# ob_digit[0] was being incorrectly accessed for instances of a
You can’t perform that action at this time.
0 commit comments