(self)
| 2107 | |
| 2108 | @unittest.expectedFailure # TODO: RUSTPYTHON |
| 2109 | def test_xinclude_failures(self): |
| 2110 | from xml.etree import ElementInclude |
| 2111 | |
| 2112 | # Test failure to locate included XML file. |
| 2113 | document = ET.XML(XINCLUDE["C1.xml"]) |
| 2114 | with self.assertRaises(ElementInclude.FatalIncludeError) as cm: |
| 2115 | ElementInclude.include(document, loader=self.none_loader) |
| 2116 | self.assertEqual(str(cm.exception), |
| 2117 | "cannot load 'disclaimer.xml' as 'xml'") |
| 2118 | |
| 2119 | # Test failure to locate included text file. |
| 2120 | document = ET.XML(XINCLUDE["C2.xml"]) |
| 2121 | with self.assertRaises(ElementInclude.FatalIncludeError) as cm: |
| 2122 | ElementInclude.include(document, loader=self.none_loader) |
| 2123 | self.assertEqual(str(cm.exception), |
| 2124 | "cannot load 'count.txt' as 'text'") |
| 2125 | |
| 2126 | # Test bad parse type. |
| 2127 | document = ET.XML(XINCLUDE_BAD["B1.xml"]) |
| 2128 | with self.assertRaises(ElementInclude.FatalIncludeError) as cm: |
| 2129 | ElementInclude.include(document, loader=self.none_loader) |
| 2130 | self.assertEqual(str(cm.exception), |
| 2131 | "unknown parse type in xi:include tag ('BAD_TYPE')") |
| 2132 | |
| 2133 | # Test xi:fallback outside xi:include. |
| 2134 | document = ET.XML(XINCLUDE_BAD["B2.xml"]) |
| 2135 | with self.assertRaises(ElementInclude.FatalIncludeError) as cm: |
| 2136 | ElementInclude.include(document, loader=self.none_loader) |
| 2137 | self.assertEqual(str(cm.exception), |
| 2138 | "xi:fallback tag must be child of xi:include " |
| 2139 | "('{http://www.w3.org/2001/XInclude}fallback')") |
| 2140 | |
| 2141 | # Test infinitely recursive includes. |
| 2142 | document = self.xinclude_loader("Recursive1.xml") |
| 2143 | with self.assertRaises(ElementInclude.FatalIncludeError) as cm: |
| 2144 | ElementInclude.include(document, self.xinclude_loader) |
| 2145 | self.assertEqual(str(cm.exception), |
| 2146 | "recursive include of Recursive2.xml") |
| 2147 | |
| 2148 | # Test 'max_depth' limitation. |
| 2149 | document = self.xinclude_loader("Recursive1.xml") |
| 2150 | with self.assertRaises(ElementInclude.FatalIncludeError) as cm: |
| 2151 | ElementInclude.include(document, self.xinclude_loader, max_depth=None) |
| 2152 | self.assertEqual(str(cm.exception), |
| 2153 | "recursive include of Recursive2.xml") |
| 2154 | |
| 2155 | document = self.xinclude_loader("Recursive1.xml") |
| 2156 | with self.assertRaises(ElementInclude.LimitedRecursiveIncludeError) as cm: |
| 2157 | ElementInclude.include(document, self.xinclude_loader, max_depth=0) |
| 2158 | self.assertEqual(str(cm.exception), |
| 2159 | "maximum xinclude depth reached when including file Recursive2.xml") |
| 2160 | |
| 2161 | document = self.xinclude_loader("Recursive1.xml") |
| 2162 | with self.assertRaises(ElementInclude.LimitedRecursiveIncludeError) as cm: |
| 2163 | ElementInclude.include(document, self.xinclude_loader, max_depth=1) |
| 2164 | self.assertEqual(str(cm.exception), |
| 2165 | "maximum xinclude depth reached when including file Recursive3.xml") |
| 2166 |
nothing calls this directly
no test coverage detected