Make AST nodes pickleable.

This commit is contained in:
Georg Brandl 2008-03-30 20:20:39 +00:00
parent 1721e75749
commit e34c21c2a0
3 changed files with 68 additions and 4 deletions

View file

@ -166,6 +166,20 @@ class AST_Tests(unittest.TestCase):
# this used to fail because Sub._fields was None
x = _ast.Sub()
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.assertEquals(to_tuple(ast2), to_tuple(ast))
def test_main():
test_support.run_unittest(AST_Tests)