File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -1518,6 +1518,22 @@ def __init__(self, value):
1518
1518
self .assertEqual (i , 1 )
1519
1519
self .assertEqual (getattr (i , 'foo' , 'none' ), 'bar' )
1520
1520
1521
+ class ValidBytes :
1522
+ def __bytes__ (self ):
1523
+ return b'\x01 '
1524
+ class InvalidBytes :
1525
+ def __bytes__ (self ):
1526
+ return 'abc'
1527
+ class MissingBytes : ...
1528
+ class RaisingBytes :
1529
+ def __bytes__ (self ):
1530
+ 1 / 0
1531
+
1532
+ self .assertEqual (int .from_bytes (ValidBytes ()), 1 )
1533
+ self .assertRaises (TypeError , int .from_bytes , InvalidBytes ())
1534
+ self .assertRaises (TypeError , int .from_bytes , MissingBytes ())
1535
+ self .assertRaises (ZeroDivisionError , int .from_bytes , RaisingBytes ())
1536
+
1521
1537
@support .cpython_only
1522
1538
def test_from_bytes_small (self ):
1523
1539
# bpo-46361
You can’t perform that action at this time.
0 commit comments