summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_xml_etree.py
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2012-06-01 08:32:34 (GMT)
committerEli Bendersky <eliben@gmail.com>2012-06-01 08:32:34 (GMT)
commit2b6b73e7e1a9d13545bea9636936ce5d3e1a87df (patch)
tree821b6042eb5a92d2cbda4931dc4515b0fa3d4348 /Lib/test/test_xml_etree.py
parent20d4174b3d211609c774bd0711dcbc1793f146aa (diff)
downloadcpython-2b6b73e7e1a9d13545bea9636936ce5d3e1a87df.zip
cpython-2b6b73e7e1a9d13545bea9636936ce5d3e1a87df.tar.gz
cpython-2b6b73e7e1a9d13545bea9636936ce5d3e1a87df.tar.bz2
Issue #14007: implement doctype() method calling in XMLParser of _elementtree.
Includes exposing a doctype handler from expat through pyexpat.
Diffstat (limited to 'Lib/test/test_xml_etree.py')
-rw-r--r--Lib/test/test_xml_etree.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 31e005b..49a5633 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -2009,7 +2009,6 @@ class TreeBuilderTest(unittest.TestCase):
self.assertEqual(lst, ['toplevel'])
- @unittest.expectedFailure # XXX issue 14007 with C ElementTree
def test_doctype(self):
class DoctypeParser:
_doctype = None
@@ -2030,6 +2029,10 @@ class TreeBuilderTest(unittest.TestCase):
class XMLParserTest(unittest.TestCase):
sample1 = '<file><line>22</line></file>'
+ sample2 = ('<!DOCTYPE html PUBLIC'
+ ' "-//W3C//DTD XHTML 1.0 Transitional//EN"'
+ ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
+ '<html>text</html>')
def _check_sample_element(self, e):
self.assertEqual(e.tag, 'file')
@@ -2055,6 +2058,20 @@ class XMLParserTest(unittest.TestCase):
parser.feed(self.sample1)
self._check_sample_element(parser.close())
+ def test_subclass_doctype(self):
+ _doctype = None
+ class MyParserWithDoctype(ET.XMLParser):
+ def doctype(self, name, pubid, system):
+ nonlocal _doctype
+ _doctype = (name, pubid, system)
+
+ parser = MyParserWithDoctype()
+ parser.feed(self.sample2)
+ parser.close()
+ self.assertEqual(_doctype,
+ ('html', '-//W3C//DTD XHTML 1.0 Transitional//EN',
+ 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'))
+
class NoAcceleratorTest(unittest.TestCase):
# Test that the C accelerator was not imported for pyET