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

Method test_entity

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

Source from the content-addressed store, hash-verified

1078 '<html><CamelCase>text</CamelCase></html>')
1079
1080 def test_entity(self):
1081 # Test entity handling.
1082
1083 # 1) good entities
1084
1085 e = ET.XML("<document title='&#x8230;'>test</document>")
1086 self.assertEqual(serialize(e, encoding="us-ascii"),
1087 b'<document title="&#33328;">test</document>')
1088 self.serialize_check(e, '<document title="\u8230">test</document>')
1089
1090 # 2) bad entities
1091
1092 with self.assertRaises(ET.ParseError) as cm:
1093 ET.XML("<document>&entity;</document>")
1094 self.assertEqual(str(cm.exception),
1095 'undefined entity: line 1, column 10')
1096
1097 with self.assertRaises(ET.ParseError) as cm:
1098 ET.XML(ENTITY_XML)
1099 self.assertEqual(str(cm.exception),
1100 'undefined entity &entity;: line 5, column 10')
1101
1102 # 3) custom entity
1103
1104 parser = ET.XMLParser()
1105 parser.entity["entity"] = "text"
1106 parser.feed(ENTITY_XML)
1107 root = parser.close()
1108 self.serialize_check(root, '<document>text</document>')
1109
1110 # 4) external (SYSTEM) entity
1111
1112 with self.assertRaises(ET.ParseError) as cm:
1113 ET.XML(EXTERNAL_ENTITY_XML)
1114 self.assertEqual(str(cm.exception),
1115 'undefined entity &entity;: line 4, column 10')
1116
1117 def test_namespace(self):
1118 # Test namespace issues.

Callers

nothing calls this directly

Calls 7

serialize_checkMethod · 0.95
feedMethod · 0.95
closeMethod · 0.95
serializeFunction · 0.85
strFunction · 0.85
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected