bpo-44891: Tests id preserving on * 1 for str and bytes (GH-27745)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit a2ce538e16)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2021-08-13 04:04:08 -07:00 committed by GitHub
parent ebc5926234
commit 45a97d91a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 0 deletions

View file

@ -508,6 +508,28 @@ class UnicodeTest(string_tests.CommonTest,
text = 'abc def'
self.assertIs(text.replace(pattern, pattern), text)
def test_repeat_id_preserving(self):
a = '123abc1@'
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 SubStr(str):
pass
s = SubStr('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))
def test_bytes_comparison(self):
with warnings_helper.check_warnings():
warnings.simplefilter('ignore', BytesWarning)