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

Method test_xinclude_failures

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

Source from the content-addressed store, hash-verified

2151 self.assertEqual(1+4*2, len(document.findall(".//p")))
2152
2153 def test_xinclude_failures(self):
2154 from xml.etree import ElementInclude
2155
2156 # Test failure to locate included XML file.
2157 document = ET.XML(XINCLUDE["C1.xml"])
2158 with self.assertRaises(ElementInclude.FatalIncludeError) as cm:
2159 ElementInclude.include(document, loader=self.none_loader)
2160 self.assertEqual(str(cm.exception),
2161 "cannot load 'disclaimer.xml' as 'xml'")
2162
2163 # Test failure to locate included text file.
2164 document = ET.XML(XINCLUDE["C2.xml"])
2165 with self.assertRaises(ElementInclude.FatalIncludeError) as cm:
2166 ElementInclude.include(document, loader=self.none_loader)
2167 self.assertEqual(str(cm.exception),
2168 "cannot load 'count.txt' as 'text'")
2169
2170 # Test bad parse type.
2171 document = ET.XML(XINCLUDE_BAD["B1.xml"])
2172 with self.assertRaises(ElementInclude.FatalIncludeError) as cm:
2173 ElementInclude.include(document, loader=self.none_loader)
2174 self.assertEqual(str(cm.exception),
2175 "unknown parse type in xi:include tag ('BAD_TYPE')")
2176
2177 # Test xi:fallback outside xi:include.
2178 document = ET.XML(XINCLUDE_BAD["B2.xml"])
2179 with self.assertRaises(ElementInclude.FatalIncludeError) as cm:
2180 ElementInclude.include(document, loader=self.none_loader)
2181 self.assertEqual(str(cm.exception),
2182 "xi:fallback tag must be child of xi:include "
2183 "('{http://www.w3.org/2001/XInclude}fallback')")
2184
2185 # Test infinitely recursive includes.
2186 document = self.xinclude_loader("Recursive1.xml")
2187 with self.assertRaises(ElementInclude.FatalIncludeError) as cm:
2188 ElementInclude.include(document, self.xinclude_loader)
2189 self.assertEqual(str(cm.exception),
2190 "recursive include of Recursive2.xml")
2191
2192 # Test 'max_depth' limitation.
2193 document = self.xinclude_loader("Recursive1.xml")
2194 with self.assertRaises(ElementInclude.FatalIncludeError) as cm:
2195 ElementInclude.include(document, self.xinclude_loader, max_depth=None)
2196 self.assertEqual(str(cm.exception),
2197 "recursive include of Recursive2.xml")
2198
2199 document = self.xinclude_loader("Recursive1.xml")
2200 with self.assertRaises(ElementInclude.LimitedRecursiveIncludeError) as cm:
2201 ElementInclude.include(document, self.xinclude_loader, max_depth=0)
2202 self.assertEqual(str(cm.exception),
2203 "maximum xinclude depth reached when including file Recursive2.xml")
2204
2205 document = self.xinclude_loader("Recursive1.xml")
2206 with self.assertRaises(ElementInclude.LimitedRecursiveIncludeError) as cm:
2207 ElementInclude.include(document, self.xinclude_loader, max_depth=1)
2208 self.assertEqual(str(cm.exception),
2209 "maximum xinclude depth reached when including file Recursive3.xml")
2210

Callers

nothing calls this directly

Calls 4

xinclude_loaderMethod · 0.95
strFunction · 0.85
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected