mirror of
https://github.com/python/cpython.git
synced 2026-04-14 07:41:00 +00:00
[3.13] gh-146059: Cleanup pickle fast_save_enter() test (GH-146481) (#146510)
gh-146059: Cleanup pickle fast_save_enter() test (GH-146481)
Remove {"key": data}, it's not required to reproduce the bug.
Simplify also deep_nested_struct(): remove the seed parameter.
Fix a typo in a comment.
(cherry picked from commit 0c7a75aeef)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
de1644cd40
commit
9ee6b67ee9
1 changed files with 10 additions and 14 deletions
|
|
@ -3947,13 +3947,12 @@ def __reduce__(self):
|
|||
self.assertIn(expected, str(e))
|
||||
|
||||
def fast_save_enter(self, create_data, minprotocol=0):
|
||||
# gh-146059: Check that fast_save() is called when
|
||||
# gh-146059: Check that fast_save_leave() is called when
|
||||
# fast_save_enter() is called.
|
||||
if not hasattr(self, "pickler"):
|
||||
self.skipTest("need Pickler class")
|
||||
|
||||
data = [create_data(i) for i in range(FAST_NESTING_LIMIT * 2)]
|
||||
data = {"key": data}
|
||||
protocols = range(minprotocol, pickle.HIGHEST_PROTOCOL + 1)
|
||||
for proto in protocols:
|
||||
with self.subTest(proto=proto):
|
||||
|
|
@ -3987,18 +3986,17 @@ def test_fast_save_enter_frozendict(self):
|
|||
def test_fast_save_enter_dict(self):
|
||||
self.fast_save_enter(lambda i: {"key": i})
|
||||
|
||||
def deep_nested_struct(self, seed, create_nested,
|
||||
def deep_nested_struct(self, create_nested,
|
||||
minprotocol=0, compare_equal=True,
|
||||
depth=FAST_NESTING_LIMIT * 2):
|
||||
# gh-146059: Check that fast_save() is called when
|
||||
# gh-146059: Check that fast_save_leave() is called when
|
||||
# fast_save_enter() is called.
|
||||
if not hasattr(self, "pickler"):
|
||||
self.skipTest("need Pickler class")
|
||||
|
||||
data = seed
|
||||
data = None
|
||||
for i in range(depth):
|
||||
data = create_nested(data)
|
||||
data = {"key": data}
|
||||
protocols = range(minprotocol, pickle.HIGHEST_PROTOCOL + 1)
|
||||
for proto in protocols:
|
||||
with self.subTest(proto=proto):
|
||||
|
|
@ -4014,30 +4012,28 @@ def deep_nested_struct(self, seed, create_nested,
|
|||
self.assertEqual(data2, data)
|
||||
|
||||
def test_deep_nested_struct_tuple(self):
|
||||
self.deep_nested_struct((1,), lambda data: (data,))
|
||||
self.deep_nested_struct(lambda data: (data,))
|
||||
|
||||
def test_deep_nested_struct_list(self):
|
||||
self.deep_nested_struct([1], lambda data: [data])
|
||||
self.deep_nested_struct(lambda data: [data])
|
||||
|
||||
def test_deep_nested_struct_frozenset(self):
|
||||
self.deep_nested_struct(frozenset((1,)),
|
||||
lambda data: frozenset((1, data)))
|
||||
self.deep_nested_struct(lambda data: frozenset((1, data)))
|
||||
|
||||
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
|
||||
def test_deep_nested_struct_set(self):
|
||||
self.deep_nested_struct({1}, lambda data: {K(data)},
|
||||
self.deep_nested_struct(lambda data: {K(data)},
|
||||
depth=FAST_NESTING_LIMIT+1,
|
||||
compare_equal=False)
|
||||
|
||||
def test_deep_nested_struct_frozendict(self):
|
||||
if self.py_version < (3, 15):
|
||||
self.skipTest('need frozendict')
|
||||
self.deep_nested_struct(frozendict(x=1),
|
||||
lambda data: frozendict(x=data),
|
||||
self.deep_nested_struct(lambda data: frozendict(x=data),
|
||||
minprotocol=2)
|
||||
|
||||
def test_deep_nested_struct_dict(self):
|
||||
self.deep_nested_struct({'x': 1}, lambda data: {'x': data})
|
||||
self.deep_nested_struct(lambda data: {'x': data})
|
||||
|
||||
|
||||
class BigmemPickleTests:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue