Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
PyObject_PyBytes
__bytes__
1 parent 0d68879 commit e39ae6bCopy full SHA for e39ae6b
1 file changed
Lib/test/test_long.py
@@ -1518,6 +1518,22 @@ def __init__(self, value):
1518
self.assertEqual(i, 1)
1519
self.assertEqual(getattr(i, 'foo', 'none'), 'bar')
1520
1521
+ class ValidBytes:
1522
+ def __bytes__(self):
1523
+ return b'\x01'
1524
+ class InvalidBytes:
1525
1526
+ return 'abc'
1527
+ class MissingBytes: ...
1528
+ class RaisingBytes:
1529
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
1537
@support.cpython_only
1538
def test_from_bytes_small(self):
1539
# bpo-46361
0 commit comments