diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index a7ad48b2e8e..f2551d6d6b7 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -102,6 +102,80 @@ def interface(): '' """ +def qname(): + """ + Test QName handling. + + 1) decorated tags + + >>> from xml.etree import ElementTree as ET + >>> elem = ET.Element("{uri}tag") + >>> serialize(ET, elem) # 1.1 + '' + >>> elem = ET.Element(ET.QName("{uri}tag")) + >>> serialize(ET, elem) # 1.2 + '' + >>> elem = ET.Element(ET.QName("uri", "tag")) + >>> serialize(ET, elem) # 1.3 + '' + >>> elem = ET.Element(ET.QName("uri", "tag")) + >>> subelem = ET.SubElement(elem, ET.QName("uri", "tag1")) + >>> subelem = ET.SubElement(elem, ET.QName("uri", "tag2")) + >>> serialize(ET, elem) # 1.4 + '' + + 2) decorated attributes + + >>> elem.clear() + >>> elem.attrib["{uri}key"] = "value" + >>> serialize(ET, elem) # 2.1 + '' + + >>> elem.clear() + >>> elem.attrib[ET.QName("{uri}key")] = "value" + >>> serialize(ET, elem) # 2.2 + '' + + 3) decorated values are not converted by default, but the + QName wrapper can be used for values + + >>> elem.clear() + >>> elem.attrib["{uri}key"] = "{uri}value" + >>> serialize(ET, elem) # 3.1 + '' + + >>> elem.clear() + >>> elem.attrib["{uri}key"] = ET.QName("{uri}value") + >>> serialize(ET, elem) # 3.2 + '' + + >>> elem.clear() + >>> subelem = ET.Element("tag") + >>> subelem.attrib["{uri1}key"] = ET.QName("{uri2}value") + >>> elem.append(subelem) + >>> elem.append(subelem) + >>> serialize(ET, elem) # 3.3 + '' + + 4) Direct QName tests + + >>> str(ET.QName('ns', 'tag')) + '{ns}tag' + >>> str(ET.QName('{ns}tag')) + '{ns}tag' + >>> q1 = ET.QName('ns', 'tag') + >>> q2 = ET.QName('ns', 'tag') + >>> q1 == q2 + True + >>> q2 = ET.QName('ns', 'other-tag') + >>> q1 == q2 + False + >>> q1 == 'ns:tag' + False + >>> q1 == '{ns}tag' + True + """ + def find(): """ Test find methods (including xpath syntax).