Skip to content

Commit 2583003

Browse files
Update Lib/test/test_bytes.py
Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent fcbf282 commit 2583003

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎Lib/test/test_bytes.py‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,8 +2414,8 @@ def __index__(self):
24142414
self.assertEqual(instance.ba[0], ord("?"), "Assigned bytearray not altered")
24152415
self.assertEqual(instance.new_ba, bytearray(0x180), "Wrong object altered")
24162416

2417-
def test_strip_buffer_release_mutates_self(self):
2418-
ba = bytearray(b"x" * (1 << 22))
2417+
def check_strip_mutate(self, method, initial, expected):
2418+
ba = bytearray(initial)
24192419

24202420
class S:
24212421
def __buffer__(self, flags):
@@ -2424,7 +2424,19 @@ def __buffer__(self, flags):
24242424
def __release_buffer__(self, view):
24252425
ba.clear()
24262426

2427-
result = ba.strip(S())
2427+
meth = getattr(ba, method)
2428+
result = meth(S())
2429+
self.assertEqual(result, bytearray(expected))
2430+
self.assertEqual(ba, bytearray(b''))
2431+
2432+
def test_strip_mutate(self):
2433+
self.check_strip_mutate('strip', b' abc ', b'abc')
2434+
2435+
def test_lstrip_mutate(self):
2436+
self.check_strip_mutate('lstrip', b' abc ', b'abc ')
2437+
2438+
def test_rstrip_mutate(self):
2439+
self.check_strip_mutate('rstrip', b' abc ', b' abc')
24282440

24292441
def test_search_methods_reentrancy_raises_buffererror(self):
24302442
# gh-142560: Raise BufferError if buffer mutates during search arg conversion.

0 commit comments

Comments
 (0)