Skip to content

Commit 36f5134

Browse files
CPython developersyouknowone
authored andcommitted
Update test_bytes from CPython 3.10.5
1 parent 8a6fc05 commit 36f5134

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Lib/test/test_bytes.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
import unittest
1717

1818
import test.support
19+
from test.support import import_helper
20+
from test.support import warnings_helper
1921
import test.string_tests
2022
import test.list_tests
21-
from test.support import bigaddrspacetest, MAX_Py_ssize_t, import_helper, warnings_helper
23+
from test.support import bigaddrspacetest, MAX_Py_ssize_t
2224
from test.support.script_helper import assert_python_failure
2325

2426

@@ -1177,6 +1179,28 @@ class BufferBlocked(bytearray):
11771179
self.assertEqual(bytes(ba), b'ab')
11781180
self.assertRaises(TypeError, bytes, bb)
11791181

1182+
def test_repeat_id_preserving(self):
1183+
a = b'123abc1@'
1184+
b = b'456zyx-+'
1185+
self.assertEqual(id(a), id(a))
1186+
self.assertNotEqual(id(a), id(b))
1187+
self.assertNotEqual(id(a), id(a * -4))
1188+
self.assertNotEqual(id(a), id(a * 0))
1189+
self.assertEqual(id(a), id(a * 1))
1190+
self.assertEqual(id(a), id(1 * a))
1191+
self.assertNotEqual(id(a), id(a * 2))
1192+
1193+
class SubBytes(bytes):
1194+
pass
1195+
1196+
s = SubBytes(b'qwerty()')
1197+
self.assertEqual(id(s), id(s))
1198+
self.assertNotEqual(id(s), id(s * -4))
1199+
self.assertNotEqual(id(s), id(s * 0))
1200+
self.assertNotEqual(id(s), id(s * 1))
1201+
self.assertNotEqual(id(s), id(1 * s))
1202+
self.assertNotEqual(id(s), id(s * 2))
1203+
11801204

11811205
class ByteArrayTest(BaseBytesTest, unittest.TestCase):
11821206
type2test = bytearray
@@ -1799,7 +1823,7 @@ def test_return_self(self):
17991823
"BytesWarning is needed for this test: use -bb option")
18001824
def test_compare(self):
18011825
def bytes_warning():
1802-
return test.warnings_helper.check_warningswarnings(('', BytesWarning))
1826+
return warnings_helper.check_warnings(('', BytesWarning))
18031827
with bytes_warning():
18041828
b'' == ''
18051829
with bytes_warning():

0 commit comments

Comments
 (0)