|
16 | 16 | import unittest |
17 | 17 |
|
18 | 18 | import test.support |
| 19 | +from test.support import import_helper |
| 20 | +from test.support import warnings_helper |
19 | 21 | import test.string_tests |
20 | 22 | 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 |
22 | 24 | from test.support.script_helper import assert_python_failure |
23 | 25 |
|
24 | 26 |
|
@@ -1177,6 +1179,28 @@ class BufferBlocked(bytearray): |
1177 | 1179 | self.assertEqual(bytes(ba), b'ab') |
1178 | 1180 | self.assertRaises(TypeError, bytes, bb) |
1179 | 1181 |
|
| 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 | + |
1180 | 1204 |
|
1181 | 1205 | class ByteArrayTest(BaseBytesTest, unittest.TestCase): |
1182 | 1206 | type2test = bytearray |
@@ -1799,7 +1823,7 @@ def test_return_self(self): |
1799 | 1823 | "BytesWarning is needed for this test: use -bb option") |
1800 | 1824 | def test_compare(self): |
1801 | 1825 | def bytes_warning(): |
1802 | | - return test.warnings_helper.check_warningswarnings(('', BytesWarning)) |
| 1826 | + return warnings_helper.check_warnings(('', BytesWarning)) |
1803 | 1827 | with bytes_warning(): |
1804 | 1828 | b'' == '' |
1805 | 1829 | with bytes_warning(): |
|
0 commit comments