(self)
| 147 | self.check_parse(f) |
| 148 | |
| 149 | def test_parse_bytes(self): |
| 150 | # UTF-8 is default encoding, US-ASCII is compatible with UTF-8, |
| 151 | # UTF-16 is autodetected |
| 152 | encodings = ('us-ascii', 'utf-8', 'utf-16', 'utf-16le', 'utf-16be') |
| 153 | for encoding in encodings: |
| 154 | self.check_parse(BytesIO(xml_bytes(self.data, encoding))) |
| 155 | make_xml_file(self.data, encoding) |
| 156 | self.check_parse(TESTFN) |
| 157 | with open(TESTFN, 'rb') as f: |
| 158 | self.check_parse(f) |
| 159 | self.check_parse(BytesIO(xml_bytes(self.data, encoding, None))) |
| 160 | make_xml_file(self.data, encoding, None) |
| 161 | self.check_parse(TESTFN) |
| 162 | with open(TESTFN, 'rb') as f: |
| 163 | self.check_parse(f) |
| 164 | # accept UTF-8 with BOM |
| 165 | self.check_parse(BytesIO(xml_bytes(self.data, 'utf-8-sig', 'utf-8'))) |
| 166 | make_xml_file(self.data, 'utf-8-sig', 'utf-8') |
| 167 | self.check_parse(TESTFN) |
| 168 | with open(TESTFN, 'rb') as f: |
| 169 | self.check_parse(f) |
| 170 | self.check_parse(BytesIO(xml_bytes(self.data, 'utf-8-sig', None))) |
| 171 | make_xml_file(self.data, 'utf-8-sig', None) |
| 172 | self.check_parse(TESTFN) |
| 173 | with open(TESTFN, 'rb') as f: |
| 174 | self.check_parse(f) |
| 175 | # accept data with declared encoding |
| 176 | self.check_parse(BytesIO(xml_bytes(self.data, 'iso-8859-1'))) |
| 177 | make_xml_file(self.data, 'iso-8859-1') |
| 178 | self.check_parse(TESTFN) |
| 179 | with open(TESTFN, 'rb') as f: |
| 180 | self.check_parse(f) |
| 181 | # fail on non-UTF-8 incompatible data without declared encoding |
| 182 | with self.assertRaises(SAXException): |
| 183 | self.check_parse(BytesIO(xml_bytes(self.data, 'iso-8859-1', None))) |
| 184 | make_xml_file(self.data, 'iso-8859-1', None) |
| 185 | with self.assertRaises(SAXException): |
| 186 | self.check_parse(TESTFN) |
| 187 | with open(TESTFN, 'rb') as f: |
| 188 | with self.assertRaises(SAXException): |
| 189 | self.check_parse(f) |
| 190 | |
| 191 | def test_parse_path_object(self): |
| 192 | make_xml_file(self.data, 'utf-8', None) |
nothing calls this directly
no test coverage detected