Skip to content

Commit b2117f5

Browse files
Aaron WieczorekAaron Wieczorek
authored andcommitted
Slight refactoring of tests; simplifying some logic
1 parent a6a3a91 commit b2117f5

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

Lib/test/pickletester.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4261,6 +4261,19 @@ def check_array(arr):
42614261
# 2-D, non-contiguous
42624262
check_array(arr[::2])
42634263

4264+
def test_concurrent_mutation_in_buffer_with_bytearray(self):
4265+
def factory():
4266+
s = b"a" * 16
4267+
return bytearray(s), s
4268+
self.do_test_concurrent_mutation_in_buffer_callback(factory)
4269+
4270+
def test_concurrent_mutation_in_buffer_with_memoryview(self):
4271+
def factory():
4272+
obj = memoryview(b"a" * 32)[10:26]
4273+
sub = b"a" * len(obj)
4274+
return obj, sub
4275+
self.do_test_concurrent_mutation_in_buffer_callback(factory)
4276+
42644277
def do_test_concurrent_mutation_in_buffer_callback(self, factory):
42654278
class R:
42664279
def __bool__(self):
@@ -4277,20 +4290,6 @@ def __bool__(self):
42774290
res = self.dumps(buf, proto, buffer_callback=buffer_callback)
42784291
self.assertIn(sub, res)
42794292

4280-
def test_concurrent_mutation_in_buffer_with_bytearray(self):
4281-
def factory():
4282-
s = b"a" * 16
4283-
return bytearray(s), s
4284-
self.do_test_concurrent_mutation_in_buffer_callback(factory)
4285-
4286-
def test_concurrent_mutation_in_buffer_with_memoryview(self):
4287-
def factory():
4288-
c, n = b"a", 64
4289-
sub = c * (n // 2)
4290-
obj = memoryview(bytearray(c * n))[n // 4 : 3 * n // 4]
4291-
return obj, sub
4292-
self.do_test_concurrent_mutation_in_buffer_callback(factory)
4293-
42944293
def test_evil_class_mutating_dict(self):
42954294
# https://github.com/python/cpython/issues/92930
42964295
from random import getrandbits

0 commit comments

Comments
 (0)