Skip to content

Commit 2e80c2a

Browse files
authored
gh-100882: Improve test_pickling case in test_ast.py (#100883)
1 parent f082098 commit 2e80c2a

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

Lib/test/test_ast.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -639,18 +639,11 @@ def test_no_fields(self):
639639

640640
def test_pickling(self):
641641
import pickle
642-
mods = [pickle]
643-
try:
644-
import cPickle
645-
mods.append(cPickle)
646-
except ImportError:
647-
pass
648-
protocols = [0, 1, 2]
649-
for mod in mods:
650-
for protocol in protocols:
651-
for ast in (compile(i, "?", "exec", 0x400) for i in exec_tests):
652-
ast2 = mod.loads(mod.dumps(ast, protocol))
653-
self.assertEqual(to_tuple(ast2), to_tuple(ast))
642+
643+
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
644+
for ast in (compile(i, "?", "exec", 0x400) for i in exec_tests):
645+
ast2 = pickle.loads(pickle.dumps(ast, protocol))
646+
self.assertEqual(to_tuple(ast2), to_tuple(ast))
654647

655648
def test_invalid_sum(self):
656649
pos = dict(lineno=2, col_offset=3)

0 commit comments

Comments
 (0)