summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2012-05-30 14:57:50 (GMT)
committerEli Bendersky <eliben@gmail.com>2012-05-30 14:57:50 (GMT)
commit48d358ba8665ecc5d5a9f5c0ca572df39f294cb8 (patch)
treee0f298df8270b5d483ecf4ee2d2b6fbc3d524d44 /Lib
parenta0cf90e3b1bebde4dea8b99083830b9fb209a1c0 (diff)
downloadcpython-48d358ba8665ecc5d5a9f5c0ca572df39f294cb8.zip
cpython-48d358ba8665ecc5d5a9f5c0ca572df39f294cb8.tar.gz
cpython-48d358ba8665ecc5d5a9f5c0ca572df39f294cb8.tar.bz2
Issue #14007: implemented the 'element_factory' feature of TreeBuilder in
_elementtree, with a test.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_xml_etree.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 74fade5..ec352d8 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -1959,6 +1959,8 @@ class TreeBuilderTest(unittest.TestCase):
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
'<html>text</html>')
+ sample2 = '''<toplevel>sometext</toplevel>'''
+
def test_dummy_builder(self):
class BaseDummyBuilder:
def close(self):
@@ -1993,11 +1995,19 @@ class TreeBuilderTest(unittest.TestCase):
e = parser.close()
self.assertEqual(e.tag, 'html')
- # XXX in _elementtree, the constructor of TreeBuilder expects no
- # arguments
- @unittest.expectedFailure
def test_element_factory(self):
- tb = ET.TreeBuilder(element_factory=lambda: ET.Element())
+ lst = []
+ def myfactory(tag, attrib):
+ nonlocal lst
+ lst.append(tag)
+ return ET.Element(tag, attrib)
+
+ tb = ET.TreeBuilder(element_factory=myfactory)
+ parser = ET.XMLParser(target=tb)
+ parser.feed(self.sample2)
+ parser.close()
+
+ self.assertEqual(lst, ['toplevel'])
@unittest.expectedFailure # XXX issue 14007 with C ElementTree
def test_doctype(self):