diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2012-06-17 08:41:22 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2012-06-17 08:41:22 (GMT) |
commit | bce166681cf18cb2e6ce61c937acbe7e5fdfafae (patch) | |
tree | 9f29fd9890427cd27226d790606aa35d484bfe68 /Lib | |
parent | 1e5d0ff8a02d18367001f009886241319331cc3f (diff) | |
download | cpython-bce166681cf18cb2e6ce61c937acbe7e5fdfafae.zip cpython-bce166681cf18cb2e6ce61c937acbe7e5fdfafae.tar.gz cpython-bce166681cf18cb2e6ce61c937acbe7e5fdfafae.tar.bz2 |
Issue #14055: Add __sizeof__ support to _elementtree.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_xml_etree_c.py | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index 142a22f..65b40d8 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -1,5 +1,5 @@ # xml.etree test for cElementTree - +import sys, struct from test import support from test.support import import_fresh_module import unittest @@ -40,6 +40,40 @@ class TestAcceleratorImported(unittest.TestCase): self.assertEqual(cET_alias.SubElement.__module__, '_elementtree') +@unittest.skipUnless(cET, 'requires _elementtree') +class SizeofTest(unittest.TestCase): + def setUp(self): + import _testcapi + gc_headsize = _testcapi.SIZEOF_PYGC_HEAD + # object header + header = 'PP' + if hasattr(sys, "gettotalrefcount"): + # debug header + header = 'PP' + header + # fields + element = header + '5P' + self.elementsize = gc_headsize + struct.calcsize(element) + # extra + self.extra = struct.calcsize('PiiP4P') + + def test_element(self): + e = cET.Element('a') + self.assertEqual(sys.getsizeof(e), self.elementsize) + + def test_element_with_attrib(self): + e = cET.Element('a', href='about:') + self.assertEqual(sys.getsizeof(e), + self.elementsize + self.extra) + + def test_element_with_children(self): + e = cET.Element('a') + for i in range(5): + cET.SubElement(e, 'span') + # should have space for 8 children now + self.assertEqual(sys.getsizeof(e), + self.elementsize + self.extra + + struct.calcsize('8P')) + def test_main(): from test import test_xml_etree, test_xml_etree_c @@ -47,7 +81,8 @@ def test_main(): support.run_unittest( MiscTests, TestAliasWorking, - TestAcceleratorImported + TestAcceleratorImported, + SizeofTest, ) # Run the same test suite as the Python module |