mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Issue #28314: Added tests for xml.etree.ElementTree.Element.getiterator().
This commit is contained in:
		
							parent
							
								
									839023f12c
								
							
						
					
					
						commit
						036fb15435
					
				
					 1 changed files with 32 additions and 0 deletions
				
			
		| 
						 | 
					@ -2191,9 +2191,41 @@ def test_iter_by_tag(self):
 | 
				
			||||||
        # make sure both tag=None and tag='*' return all tags
 | 
					        # make sure both tag=None and tag='*' return all tags
 | 
				
			||||||
        all_tags = ['document', 'house', 'room', 'room',
 | 
					        all_tags = ['document', 'house', 'room', 'room',
 | 
				
			||||||
                    'shed', 'house', '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)
 | 
				
			||||||
        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):
 | 
					    def test_copy(self):
 | 
				
			||||||
        a = ET.Element('a')
 | 
					        a = ET.Element('a')
 | 
				
			||||||
        it = a.iter()
 | 
					        it = a.iter()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue