mirror of
https://github.com/python/cpython.git
synced 2026-04-14 15:50:50 +00:00
[3.14] gh-146059: Cleanup pickle fast_save_enter() test (GH-146481) (#146509)
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
4d61fd6b7a
commit
cba54979df
1 changed files with 10 additions and 14 deletions
|
|
@ -4276,13 +4276,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):
|
||||
|
|
@ -4316,18 +4315,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):
|
||||
|
|
@ -4343,29 +4341,27 @@ 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)))
|
||||
|
||||
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