diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-10-25 07:37:55 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-10-25 07:37:55 (GMT) |
commit | c3adf1e09b2cd981e4f3e07ef93c19c9513f4846 (patch) | |
tree | 25848de2d5de91c939bb4f30c877886777a64dc0 | |
parent | c4a3e90aa8903d35a7b07e751a878fbd8326799e (diff) | |
parent | 036fb15435a2b5fb8acb200ee694b1d50c87a3a9 (diff) | |
download | cpython-c3adf1e09b2cd981e4f3e07ef93c19c9513f4846.zip cpython-c3adf1e09b2cd981e4f3e07ef93c19c9513f4846.tar.gz cpython-c3adf1e09b2cd981e4f3e07ef93c19c9513f4846.tar.bz2 |
Issue #28314: Added tests for xml.etree.ElementTree.Element.getiterator().
-rw-r--r-- | Lib/test/test_xml_etree.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 054ec8f..c0144d1 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -2195,9 +2195,41 @@ class ElementIterTest(unittest.TestCase): # make sure both tag=None and tag='*' return all tags all_tags = ['document', 'house', 'room', 'room', 'shed', 'house', 'room'] + self.assertEqual(summarize_list(doc.iter()), all_tags) self.assertEqual(self._ilist(doc), all_tags) self.assertEqual(self._ilist(doc, '*'), all_tags) + def test_getiterator(self): + doc = ET.XML(''' + <document> + <house> + <room>bedroom1</room> + <room>bedroom2</room> + </house> + <shed>nothing here + </shed> + <house> + <room>bedroom8</room> + </house> + </document>''') + + self.assertEqual(summarize_list(doc.getiterator('room')), + ['room'] * 3) + self.assertEqual(summarize_list(doc.getiterator('house')), + ['house'] * 2) + + # test that getiterator also accepts 'tag' as a keyword arg + self.assertEqual( + summarize_list(doc.getiterator(tag='room')), + ['room'] * 3) + + # make sure both tag=None and tag='*' return all tags + all_tags = ['document', 'house', 'room', 'room', + 'shed', 'house', 'room'] + self.assertEqual(summarize_list(doc.getiterator()), all_tags) + self.assertEqual(summarize_list(doc.getiterator(None)), all_tags) + self.assertEqual(summarize_list(doc.getiterator('*')), all_tags) + def test_copy(self): a = ET.Element('a') it = a.iter() |