summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2012-06-01 04:13:08 (GMT)
committerEli Bendersky <eliben@gmail.com>2012-06-01 04:13:08 (GMT)
commit52467b167e28108509804d82fc050216fce3dc05 (patch)
treec30923d29e542dcb4498ff2ded7cb8a932be6783 /Lib/test
parent7e0229e90d4161ea7f81f325ac883ecd85782f71 (diff)
downloadcpython-52467b167e28108509804d82fc050216fce3dc05.zip
cpython-52467b167e28108509804d82fc050216fce3dc05.tar.gz
cpython-52467b167e28108509804d82fc050216fce3dc05.tar.bz2
Issue #14007: make XMLParser a real subclassable type exported from _elementtree. +cleanups
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_xml_etree.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index ec352d8..31e005b 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -2028,6 +2028,34 @@ class TreeBuilderTest(unittest.TestCase):
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'))
+class XMLParserTest(unittest.TestCase):
+ sample1 = '<file><line>22</line></file>'
+
+ def _check_sample_element(self, e):
+ self.assertEqual(e.tag, 'file')
+ self.assertEqual(e[0].tag, 'line')
+ self.assertEqual(e[0].text, '22')
+
+ def test_constructor_args(self):
+ # Positional args. The first (html) is not supported, but should be
+ # nevertheless correctly accepted.
+ parser = ET.XMLParser(None, ET.TreeBuilder(), 'utf-8')
+ parser.feed(self.sample1)
+ self._check_sample_element(parser.close())
+
+ # Now as keyword args.
+ parser2 = ET.XMLParser(encoding='utf-8', html=[{}], target=ET.TreeBuilder())
+ parser2.feed(self.sample1)
+ self._check_sample_element(parser2.close())
+
+ def test_subclass(self):
+ class MyParser(ET.XMLParser):
+ pass
+ parser = MyParser()
+ parser.feed(self.sample1)
+ self._check_sample_element(parser.close())
+
+
class NoAcceleratorTest(unittest.TestCase):
# Test that the C accelerator was not imported for pyET
def test_correct_import_pyET(self):
@@ -2245,6 +2273,7 @@ def test_main(module=pyET):
ElementTreeTest,
NamespaceParseTest,
TreeBuilderTest,
+ XMLParserTest,
KeywordArgsTest]
if module is pyET:
# Run the tests specific to the Python implementation