mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-24234: Implement bytes.__bytes__ (GH-27901)
This commit is contained in:
parent
6082bb5add
commit
24b63c695a
7 changed files with 63 additions and 3 deletions
|
@ -981,6 +981,18 @@ class BaseBytesTest:
|
|||
class BytesTest(BaseBytesTest, unittest.TestCase):
|
||||
type2test = bytes
|
||||
|
||||
def test__bytes__(self):
|
||||
foo = b'foo'
|
||||
self.assertEqual(foo.__bytes__(), foo)
|
||||
self.assertEqual(type(foo.__bytes__()), self.type2test)
|
||||
|
||||
class bytes_subclass(bytes):
|
||||
pass
|
||||
|
||||
bar = bytes_subclass(b'bar')
|
||||
self.assertEqual(bar.__bytes__(), bar)
|
||||
self.assertEqual(type(bar.__bytes__()), self.type2test)
|
||||
|
||||
def test_getitem_error(self):
|
||||
b = b'python'
|
||||
msg = "byte indices must be integers or slices"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue