mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
bpo-44891: Tests id
preserving on * 1
for str
and bytes
(GH-27745)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
7bf28cbb4b
commit
a2ce538e16
3 changed files with 46 additions and 0 deletions
|
@ -1169,6 +1169,28 @@ class BytesTest(BaseBytesTest, unittest.TestCase):
|
|||
self.assertEqual(bytes(ba), b'ab')
|
||||
self.assertRaises(TypeError, bytes, bb)
|
||||
|
||||
def test_repeat_id_preserving(self):
|
||||
a = b'123abc1@'
|
||||
b = b'456zyx-+'
|
||||
self.assertEqual(id(a), id(a))
|
||||
self.assertNotEqual(id(a), id(b))
|
||||
self.assertNotEqual(id(a), id(a * -4))
|
||||
self.assertNotEqual(id(a), id(a * 0))
|
||||
self.assertEqual(id(a), id(a * 1))
|
||||
self.assertEqual(id(a), id(1 * a))
|
||||
self.assertNotEqual(id(a), id(a * 2))
|
||||
|
||||
class SubBytes(bytes):
|
||||
pass
|
||||
|
||||
s = SubBytes(b'qwerty()')
|
||||
self.assertEqual(id(s), id(s))
|
||||
self.assertNotEqual(id(s), id(s * -4))
|
||||
self.assertNotEqual(id(s), id(s * 0))
|
||||
self.assertNotEqual(id(s), id(s * 1))
|
||||
self.assertNotEqual(id(s), id(1 * s))
|
||||
self.assertNotEqual(id(s), id(s * 2))
|
||||
|
||||
|
||||
class ByteArrayTest(BaseBytesTest, unittest.TestCase):
|
||||
type2test = bytearray
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue