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

Method test_parse_bytes

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

Source from the content-addressed store, hash-verified

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)

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