summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_xml_etree.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-06-29 20:08:52 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-06-29 20:08:52 (GMT)
commit4a01cab89894b157f282b2032862a278c9edb842 (patch)
treecf4d7a979b071d6c99ac909a4d47dd9b60a15aea /Lib/test/test_xml_etree.py
parentbc9e75ed023ff03f555682e57d25fee32e6548a0 (diff)
parent05744ac6e0948cbd6a50fc03a239a5402abceb14 (diff)
downloadcpython-4a01cab89894b157f282b2032862a278c9edb842.zip
cpython-4a01cab89894b157f282b2032862a278c9edb842.tar.gz
cpython-4a01cab89894b157f282b2032862a278c9edb842.tar.bz2
Issue #19176: Fixed doctype() related bugs in C implementation of ElementTree.
A deprecation warning no longer issued by XMLParser subclass with default doctype() method. Direct call of doctype() now issues a warning. Parser's doctype() now is not called if target's doctype() is called. Based on patch by Martin Panter.
Diffstat (limited to 'Lib/test/test_xml_etree.py')
-rw-r--r--Lib/test/test_xml_etree.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index c73e4be..f83db7f 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -12,6 +12,7 @@ import pickle
import sys
import types
import unittest
+import warnings
import weakref
from itertools import product
@@ -2237,6 +2238,20 @@ class XMLParserTest(unittest.TestCase):
parser.feed(self.sample1)
self._check_sample_element(parser.close())
+ def test_doctype_warning(self):
+ parser = ET.XMLParser()
+ with self.assertWarns(DeprecationWarning):
+ parser.doctype('html', '-//W3C//DTD XHTML 1.0 Transitional//EN',
+ 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd')
+ parser.feed('<html/>')
+ parser.close()
+
+ with warnings.catch_warnings():
+ warnings.simplefilter('error', DeprecationWarning)
+ parser = ET.XMLParser()
+ parser.feed(self.sample2)
+ parser.close()
+
def test_subclass_doctype(self):
_doctype = None
class MyParserWithDoctype(ET.XMLParser):
@@ -2252,6 +2267,32 @@ class XMLParserTest(unittest.TestCase):
('html', '-//W3C//DTD XHTML 1.0 Transitional//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'))
+ _doctype = _doctype2 = None
+ with warnings.catch_warnings():
+ warnings.simplefilter('error', DeprecationWarning)
+ class DoctypeParser:
+ def doctype(self, name, pubid, system):
+ nonlocal _doctype2
+ _doctype2 = (name, pubid, system)
+
+ parser = MyParserWithDoctype(target=DoctypeParser())
+ parser.feed(self.sample2)
+ parser.close()
+ self.assertIsNone(_doctype)
+ self.assertEqual(_doctype2,
+ ('html', '-//W3C//DTD XHTML 1.0 Transitional//EN',
+ 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'))
+
+ def test_inherited_doctype(self):
+ '''Ensure that ordinary usage is not deprecated (Issue 19176)'''
+ with warnings.catch_warnings():
+ warnings.simplefilter('error', DeprecationWarning)
+ class MyParserWithoutDoctype(ET.XMLParser):
+ pass
+ parser = MyParserWithoutDoctype()
+ parser.feed(self.sample2)
+ parser.close()
+
def test_parse_string(self):
parser = ET.XMLParser(target=ET.TreeBuilder())
parser.feed(self.sample3)