summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_xml_etree.py
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2013-05-19 16:01:49 (GMT)
committerEli Bendersky <eliben@gmail.com>2013-05-19 16:01:49 (GMT)
commit3a4fbd8241f9a14cb8ed3ab1369bdcf8998d5d22 (patch)
treede0e99ea689a53c2a896a51997e9a2a59099530d /Lib/test/test_xml_etree.py
parent5b6616dee302270f72379a3493de137a5994ee60 (diff)
downloadcpython-3a4fbd8241f9a14cb8ed3ab1369bdcf8998d5d22.zip
cpython-3a4fbd8241f9a14cb8ed3ab1369bdcf8998d5d22.tar.gz
cpython-3a4fbd8241f9a14cb8ed3ab1369bdcf8998d5d22.tar.bz2
_elementtree.XMLParser._setevents should support any sequence, not just tuples
Also clean up some code around this
Diffstat (limited to 'Lib/test/test_xml_etree.py')
-rw-r--r--Lib/test/test_xml_etree.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index f37cfe9..6973371 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -979,6 +979,21 @@ class IncrementalParserTest(unittest.TestCase):
parser.eof_received()
self.assertEqual(parser.root.tag, '{namespace}root')
+ def test_ns_events(self):
+ parser = ET.IncrementalParser(events=('start-ns', 'end-ns'))
+ self._feed(parser, "<!-- comment -->\n")
+ self._feed(parser, "<root xmlns='namespace'>\n")
+ self.assertEqual(
+ list(parser.events()),
+ [('start-ns', ('', 'namespace'))])
+ self._feed(parser, "<element key='value'>text</element")
+ self._feed(parser, ">\n")
+ self._feed(parser, "<element>text</element>tail\n")
+ self._feed(parser, "<empty-element/>\n")
+ self._feed(parser, "</root>\n")
+ self.assertEqual(list(parser.events()), [('end-ns', None)])
+ parser.eof_received()
+
def test_events(self):
parser = ET.IncrementalParser(events=())
self._feed(parser, "<root/>\n")
@@ -1026,6 +1041,26 @@ class IncrementalParserTest(unittest.TestCase):
parser.eof_received()
self.assertEqual(parser.root.tag, 'root')
+ def test_events_sequence(self):
+ # Test that events can be some sequence that's not just a tuple or list
+ eventset = {'end', 'start'}
+ parser = ET.IncrementalParser(events=eventset)
+ self._feed(parser, "<foo>bar</foo>")
+ self.assert_event_tags(parser, [('start', 'foo'), ('end', 'foo')])
+
+ class DummyIter:
+ def __init__(self):
+ self.events = iter(['start', 'end', 'start-ns'])
+ def __iter__(self):
+ return self
+ def __next__(self):
+ return next(self.events)
+
+ parser = ET.IncrementalParser(events=DummyIter())
+ self._feed(parser, "<foo>bar</foo>")
+ self.assert_event_tags(parser, [('start', 'foo'), ('end', 'foo')])
+
+
def test_unknown_event(self):
with self.assertRaises(ValueError):
ET.IncrementalParser(events=('start', 'end', 'bogus'))