Skip to content

Commit 3b33264

Browse files
committed
bpo-36676: Add test to see if a target only with an "end_ns()" callback receives the calls in the right order.
1 parent aa52e04 commit 3b33264

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Lib/test/test_xml_etree.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import operator
1414
import pickle
1515
import sys
16+
import textwrap
1617
import types
1718
import unittest
1819
import warnings
@@ -715,6 +716,27 @@ def end_ns(self, prefix):
715716
('end-ns', ''),
716717
])
717718

719+
def test_custom_builder_only_end_ns(self):
720+
class Builder(list):
721+
def end_ns(self, prefix):
722+
self.append(("end-ns", prefix))
723+
724+
builder = Builder()
725+
parser = ET.XMLParser(target=builder)
726+
parser.feed(textwrap.dedent("""\
727+
<?pi data?>
728+
<!-- comment -->
729+
<root xmlns='namespace' xmlns:p='pns' xmlns:a='ans'>
730+
<a:element key='value'>text</a:element>
731+
<p:element>text</p:element>tail
732+
<empty-element/>
733+
</root>
734+
"""))
735+
self.assertEqual(builder, [
736+
('end-ns', 'a'),
737+
('end-ns', 'p'),
738+
('end-ns', ''),
739+
])
718740

719741
# Element.getchildren() and ElementTree.getiterator() are deprecated.
720742
@checkwarnings(("This method will be removed in future versions. "

0 commit comments

Comments
 (0)