Skip to content

gh-100931: Test all pickle protocols in test_slice #100932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/test/test_json/test_attrdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_pickle(self):
cached_module = sys.modules.get('json')
sys.modules['json'] = self.json
try:
for protocol in range(6):
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not related, but I think it is minor enough to be included. It just replaces a magic number 6 with more context.

kepler_ad2 = pickle.loads(pickle.dumps(kepler_ad, protocol))
self.assertEqual(kepler_ad2, kepler_ad)
self.assertEqual(type(kepler_ad2), AttrDict)
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,10 @@ def __setitem__(self, i, k):
self.assertEqual(tmp, [(slice(1, 2), 42)])

def test_pickle(self):
import pickle

s = slice(10, 20, 3)
for protocol in (0,1,2):
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
t = loads(dumps(s, protocol))
self.assertEqual(s, t)
self.assertEqual(s.indices(15), t.indices(15))
Expand Down