diff options
author | Eli Bendersky <eliben@gmail.com> | 2012-12-30 14:17:49 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2012-12-30 14:17:49 (GMT) |
commit | 7ec45f7a360414f4b1b04cf196749db4069649da (patch) | |
tree | 1de7ab1a6e782cf1cba293d9949e8910f70d059f /Lib/test/test_xml_etree.py | |
parent | c1b59d455261de2d18fb3f5005958b4411d6b314 (diff) | |
download | cpython-7ec45f7a360414f4b1b04cf196749db4069649da.zip cpython-7ec45f7a360414f4b1b04cf196749db4069649da.tar.gz cpython-7ec45f7a360414f4b1b04cf196749db4069649da.tar.bz2 |
For Issue #16076: make sure that pickling of Element objects is tested, and do
it properly to avoid problems with test-run-order dependencies.
Diffstat (limited to 'Lib/test/test_xml_etree.py')
-rw-r--r-- | Lib/test/test_xml_etree.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 9cebc3c..ce6bdc6 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -16,6 +16,7 @@ import html import io +import pickle import sys import unittest import weakref @@ -1768,6 +1769,20 @@ class BasicElementTest(unittest.TestCase): self.assertEqual(flag, True) self.assertEqual(wref(), None) + def test_pickle(self): + # For now this test only works for the Python version of ET, + # so set sys.modules accordingly because pickle uses __import__ + # to load the __module__ of the class. + if pyET: + sys.modules['xml.etree.ElementTree'] = pyET + else: + raise unittest.SkipTest('only for the Python version') + e1 = ET.Element('foo', bar=42) + s = pickle.dumps(e1) + e2 = pickle.loads(s) + self.assertEqual(e2.tag, 'foo') + self.assertEqual(e2.attrib['bar'], 42) + class ElementTreeTest(unittest.TestCase): def test_istype(self): |