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

Method test_parse_bytes

Lib/test/test_sax.py:151–191  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

check_parseMethod · 0.95
BytesIOClass · 0.90
xml_bytesFunction · 0.85
make_xml_fileFunction · 0.85
openFunction · 0.50
assertRaisesMethod · 0.45

Tested by

no test coverage detected