MCPcopy Index your code
hub / github.com/python/cpython / test_qname

Method test_qname

Lib/test/test_xml_etree.py:1150–1213  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1148 '</ns0:body>')
1149
1150 def test_qname(self):
1151 # Test QName handling.
1152
1153 # 1) decorated tags
1154
1155 elem = ET.Element("{uri}tag")
1156 self.serialize_check(elem, '<ns0:tag xmlns:ns0="uri" />') # 1.1
1157 elem = ET.Element(ET.QName("{uri}tag"))
1158 self.serialize_check(elem, '<ns0:tag xmlns:ns0="uri" />') # 1.2
1159 elem = ET.Element(ET.QName("uri", "tag"))
1160 self.serialize_check(elem, '<ns0:tag xmlns:ns0="uri" />') # 1.3
1161 elem = ET.Element(ET.QName("uri", "tag"))
1162 subelem = ET.SubElement(elem, ET.QName("uri", "tag1"))
1163 subelem = ET.SubElement(elem, ET.QName("uri", "tag2"))
1164 self.serialize_check(elem,
1165 '<ns0:tag xmlns:ns0="uri"><ns0:tag1 /><ns0:tag2 /></ns0:tag>') # 1.4
1166
1167 # 2) decorated attributes
1168
1169 elem.clear()
1170 elem.attrib["{uri}key"] = "value"
1171 self.serialize_check(elem,
1172 '<ns0:tag xmlns:ns0="uri" ns0:key="value" />') # 2.1
1173
1174 elem.clear()
1175 elem.attrib[ET.QName("{uri}key")] = "value"
1176 self.serialize_check(elem,
1177 '<ns0:tag xmlns:ns0="uri" ns0:key="value" />') # 2.2
1178
1179 # 3) decorated values are not converted by default, but the
1180 # QName wrapper can be used for values
1181
1182 elem.clear()
1183 elem.attrib["{uri}key"] = "{uri}value"
1184 self.serialize_check(elem,
1185 '<ns0:tag xmlns:ns0="uri" ns0:key="{uri}value" />') # 3.1
1186
1187 elem.clear()
1188 elem.attrib["{uri}key"] = ET.QName("{uri}value")
1189 self.serialize_check(elem,
1190 '<ns0:tag xmlns:ns0="uri" ns0:key="ns0:value" />') # 3.2
1191
1192 elem.clear()
1193 subelem = ET.Element("tag")
1194 subelem.attrib["{uri1}key"] = ET.QName("{uri2}value")
1195 elem.append(subelem)
1196 elem.append(subelem)
1197 self.serialize_check(elem,
1198 '<ns0:tag xmlns:ns0="uri" xmlns:ns1="uri1" xmlns:ns2="uri2">'
1199 '<tag ns1:key="ns2:value" />'
1200 '<tag ns1:key="ns2:value" />'
1201 '</ns0:tag>') # 3.3
1202
1203 # 4) Direct QName tests
1204
1205 self.assertEqual(str(ET.QName('ns', 'tag')), '{ns}tag')
1206 self.assertEqual(str(ET.QName('{ns}tag')), '{ns}tag')
1207 q1 = ET.QName('ns', 'tag')

Callers

nothing calls this directly

Calls 6

serialize_checkMethod · 0.95
clearMethod · 0.95
appendMethod · 0.95
strFunction · 0.85
assertNotEqualMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected