@@ -789,13 +789,20 @@ def test_iteration_text_only(self):
789789            result .append (el .tag )
790790        self .assertEqual ([], result )
791791
792-     def  test_iteration_crash (self ):
792+     def  test_iteration_set_tail_empty (self ):
793793        # this would cause a crash in the past 
794794        fromstring  =  self .etree .fromstring 
795-         root  =  etree . fromstring ('<html><p></p>x</html>' )
795+         root  =  fromstring ('<html><p></p>x</html>' )
796796        for  elem  in  root :
797797            elem .tail  =  '' 
798798
799+     def  test_iteration_clear_tail (self ):
800+         # this would cause a crash in the past 
801+         fromstring  =  self .etree .fromstring 
802+         root  =  fromstring ('<html><p></p>x</html>' )
803+         for  elem  in  root :
804+             elem .tail  =  None 
805+ 
799806    def  test_iteration_reversed (self ):
800807        XML  =  self .etree .XML 
801808        root  =  XML (_bytes ('<doc><one/><two>Two</two>Hm<three/></doc>' ))
@@ -1735,7 +1742,21 @@ def test_remove_tail(self):
17351742            a )
17361743        self .assertEqual ('b2' , b .tail )
17371744
1738-     def  _test_getchildren (self ):
1745+     def  test_remove_while_iterating (self ):
1746+         # There is no guarantee that this "works", but it should 
1747+         # remove at least one child and not crash. 
1748+         Element  =  self .etree .Element 
1749+         SubElement  =  self .etree .SubElement 
1750+ 
1751+         a  =  Element ('a' )
1752+         SubElement (a , 'b' )
1753+         SubElement (a , 'c' )
1754+         SubElement (a , 'd' )
1755+         for  el  in  a :
1756+             a .remove (el )
1757+         self .assertLess (len (a ), 3 )
1758+ 
1759+     def  test_getchildren (self ):
17391760        Element  =  self .etree .Element 
17401761        SubElement  =  self .etree .SubElement 
17411762
@@ -1784,6 +1805,34 @@ def test_iter(self):
17841805            [d ],
17851806            list (d .iter ()))
17861807
1808+     def  test_iter_remove_tail (self ):
1809+         Element  =  self .etree .Element 
1810+         SubElement  =  self .etree .SubElement 
1811+ 
1812+         a  =  Element ('a' )
1813+         a .text  =  'a' 
1814+         a .tail  =  'a1'  *  100 
1815+         b  =  SubElement (a , 'b' )
1816+         b .text  =  'b' 
1817+         b .tail  =  'b1'  *  100 
1818+         c  =  SubElement (a , 'c' )
1819+         c .text  =  'c' 
1820+         c .tail  =  'c1'  *  100 
1821+         d  =  SubElement (b , 'd' )
1822+         d .text  =  'd' 
1823+         d .tail  =  'd1'  *  100 
1824+         e  =  SubElement (c , 'e' )
1825+         e .text  =  'e' 
1826+         e .tail  =  'e1'  *  100 
1827+ 
1828+         for  el  in  a .iter ():
1829+             el .tail  =  None 
1830+         el  =  None 
1831+ 
1832+         self .assertEqual (
1833+             [None ] *  5 ,
1834+             [el .tail  for  el  in  a .iter ()])
1835+ 
17871836    def  test_getiterator (self ):
17881837        Element  =  self .etree .Element 
17891838        SubElement  =  self .etree .SubElement 
@@ -1919,8 +1968,8 @@ def test_getiterator_with_text(self):
19191968        c .text  =  'c' 
19201969        c .tail  =  'c1' 
19211970        d  =  SubElement (b , 'd' )
1922-         c .text  =  'd' 
1923-         c .tail  =  'd1' 
1971+         d .text  =  'd' 
1972+         d .tail  =  'd1' 
19241973        e  =  SubElement (c , 'e' )
19251974        e .text  =  'e' 
19261975        e .tail  =  'e1' 
@@ -1945,8 +1994,8 @@ def test_getiterator_filter_with_text(self):
19451994        c .text  =  'c' 
19461995        c .tail  =  'c1' 
19471996        d  =  SubElement (b , 'd' )
1948-         c .text  =  'd' 
1949-         c .tail  =  'd1' 
1997+         d .text  =  'd' 
1998+         d .tail  =  'd1' 
19501999        e  =  SubElement (c , 'e' )
19512000        e .text  =  'e' 
19522001        e .tail  =  'e1' 
0 commit comments