summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_bytes.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 630f862..81d2dad 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -458,6 +458,18 @@ class BytesTest(BaseBytesTest):
with open(fd, "rb", buffering=0) as f:
self.assertRaises(TypeError, f.readinto, b"")
+ def test_custom(self):
+ class A:
+ def __bytes__(self):
+ return b'abc'
+ self.assertEqual(bytes(A()), b'abc')
+ class A: pass
+ self.assertRaises(TypeError, bytes, A())
+ class A:
+ def __bytes__(self):
+ return None
+ self.assertRaises(TypeError, bytes, A())
+
class ByteArrayTest(BaseBytesTest):
type2test = bytearray