MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_qname

Method test_qname

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

Source from the content-addressed store, hash-verified

1123 '</ns0:body>')
1124
1125 def test_qname(self):
1126 # Test QName handling.
1127
1128 # 1) decorated tags
1129
1130 elem = ET.Element("{uri}tag")
1131 self.serialize_check(elem, '<ns0:tag xmlns:ns0="uri" />') # 1.1
1132 elem = ET.Element(ET.QName("{uri}tag"))
1133 self.serialize_check(elem, '<ns0:tag xmlns:ns0="uri" />') # 1.2
1134 elem = ET.Element(ET.QName("uri", "tag"))
1135 self.serialize_check(elem, '<ns0:tag xmlns:ns0="uri" />') # 1.3
1136 elem = ET.Element(ET.QName("uri", "tag"))
1137 subelem = ET.SubElement(elem, ET.QName("uri", "tag1"))
1138 subelem = ET.SubElement(elem, ET.QName("uri", "tag2"))
1139 self.serialize_check(elem,
1140 '<ns0:tag xmlns:ns0="uri"><ns0:tag1 /><ns0:tag2 /></ns0:tag>') # 1.4
1141
1142 # 2) decorated attributes
1143
1144 elem.clear()
1145 elem.attrib["{uri}key"] = "value"
1146 self.serialize_check(elem,
1147 '<ns0:tag xmlns:ns0="uri" ns0:key="value" />') # 2.1
1148
1149 elem.clear()
1150 elem.attrib[ET.QName("{uri}key")] = "value"
1151 self.serialize_check(elem,
1152 '<ns0:tag xmlns:ns0="uri" ns0:key="value" />') # 2.2
1153
1154 # 3) decorated values are not converted by default, but the
1155 # QName wrapper can be used for values
1156
1157 elem.clear()
1158 elem.attrib["{uri}key"] = "{uri}value"
1159 self.serialize_check(elem,
1160 '<ns0:tag xmlns:ns0="uri" ns0:key="{uri}value" />') # 3.1
1161
1162 elem.clear()
1163 elem.attrib["{uri}key"] = ET.QName("{uri}value")
1164 self.serialize_check(elem,
1165 '<ns0:tag xmlns:ns0="uri" ns0:key="ns0:value" />') # 3.2
1166
1167 elem.clear()
1168 subelem = ET.Element("tag")
1169 subelem.attrib["{uri1}key"] = ET.QName("{uri2}value")
1170 elem.append(subelem)
1171 elem.append(subelem)
1172 self.serialize_check(elem,
1173 '<ns0:tag xmlns:ns0="uri" xmlns:ns1="uri1" xmlns:ns2="uri2">'
1174 '<tag ns1:key="ns2:value" />'
1175 '<tag ns1:key="ns2:value" />'
1176 '</ns0:tag>') # 3.3
1177
1178 # 4) Direct QName tests
1179
1180 self.assertEqual(str(ET.QName('ns', 'tag')), '{ns}tag')
1181 self.assertEqual(str(ET.QName('{ns}tag')), '{ns}tag')
1182 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