Skip to content

Improve test_pickling in test_ast #100882

Closed
Closed
@sobolevn

Description

@sobolevn

Here's how it is defined right now:

def test_pickling(self):
import pickle
mods = [pickle]
try:
import cPickle
mods.append(cPickle)
except ImportError:
pass
protocols = [0, 1, 2]
for mod in mods:
for protocol in protocols:
for ast in (compile(i, "?", "exec", 0x400) for i in exec_tests):
ast2 = mod.loads(mod.dumps(ast, protocol))
self.assertEqual(to_tuple(ast2), to_tuple(ast))
def test_invalid_sum(self):

I see two major problems here:

  1. cPickle does not exist anymore (since 3.0), so it always fails with ImportError. If we want to be sure that both Python and C versions behave the same - we can surely do that with import_helper.import_fresh_module or we can drop this part and only keep pickle module direct usage (as other modules do). I prefer the second option, because of how other things are tested. But, in the end it is up to maintainers to decide :)
  2. Not all pickle protocols are tested: we need to use pickle.HIGHEST_PROTOCOL instead of just three items

PR is incoming!

Linked PRs

Metadata

Metadata

Assignees

Labels

testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions