summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2012-03-16 06:20:05 (GMT)
committerEli Bendersky <eliben@gmail.com>2012-03-16 06:20:05 (GMT)
commit5b77d81314bb974f212d5849b4c5ceae9e2ba142 (patch)
tree5cb5d2796e6848d6169bcf21569360c1cdd33cc1 /Lib
parentf996e775eaf22e6a6465e640a6de46ea74011bc0 (diff)
downloadcpython-5b77d81314bb974f212d5849b4c5ceae9e2ba142.zip
cpython-5b77d81314bb974f212d5849b4c5ceae9e2ba142.tar.gz
cpython-5b77d81314bb974f212d5849b4c5ceae9e2ba142.tar.bz2
Issue #14207: the ParseError exception raised by _elementtree was made
consistent to the one raised by the Python module (the 'code' attribute was added). In addition, the exception is now documented. Added a test to check that ParseError has the required attributes, and threw away the equivalent doctest which is no longer required.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_xml_etree.py42
1 files changed, 22 insertions, 20 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 97fc690..c1dce04 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -1055,26 +1055,6 @@ def entity():
'<document>text</document>'
"""
-def error(xml):
- """
-
- Test error handling.
-
- >>> issubclass(ET.ParseError, SyntaxError)
- True
- >>> error("foo").position
- (1, 0)
- >>> error("<tag>&foo;</tag>").position
- (1, 5)
- >>> error("foobar<").position
- (1, 6)
-
- """
- try:
- ET.XML(xml)
- except ET.ParseError:
- return sys.exc_info()[1]
-
def namespace():
"""
Test namespace issues.
@@ -2039,6 +2019,27 @@ class StringIOTest(unittest.TestCase):
self.assertEqual(tree.getroot().tag, 'site')
+class ParseErrorTest(unittest.TestCase):
+ def test_subclass(self):
+ self.assertIsInstance(ET.ParseError(), SyntaxError)
+
+ def _get_error(self, s):
+ try:
+ ET.fromstring(s)
+ except ET.ParseError as e:
+ return e
+
+ def test_error_position(self):
+ self.assertEqual(self._get_error('foo').position, (1, 0))
+ self.assertEqual(self._get_error('<tag>&foo;</tag>').position, (1, 5))
+ self.assertEqual(self._get_error('foobar<').position, (1, 6))
+
+ def test_error_code(self):
+ import xml.parsers.expat.errors as ERRORS
+ self.assertEqual(self._get_error('foo').code,
+ ERRORS.codes[ERRORS.XML_ERROR_SYNTAX])
+
+
# --------------------------------------------------------------------
@@ -2091,6 +2092,7 @@ def test_main(module=pyET):
test_classes = [
ElementSlicingTest,
StringIOTest,
+ ParseErrorTest,
ElementTreeTest,
TreeBuilderTest]
if module is pyET: