|
18 | 18 | from io import BytesIO, StringIO |
19 | 19 | import codecs |
20 | 20 | import os.path |
| 21 | +import pathlib |
21 | 22 | import shutil |
22 | 23 | from urllib.error import URLError |
23 | 24 | from test import support |
@@ -182,6 +183,10 @@ def test_parse_bytes(self): |
182 | 183 | with self.assertRaises(SAXException): |
183 | 184 | self.check_parse(f) |
184 | 185 |
|
| 186 | + def test_parse_path_object(self): |
| 187 | + make_xml_file(self.data, 'utf-8', None) |
| 188 | + self.check_parse(pathlib.Path(TESTFN)) |
| 189 | + |
185 | 190 | def test_parse_InputSource(self): |
186 | 191 | # accept data without declared but with explicitly specified encoding |
187 | 192 | make_xml_file(self.data, 'iso-8859-1', None) |
@@ -397,6 +402,13 @@ def test_string(self): |
397 | 402 | self.checkContent(prep.getByteStream(), |
398 | 403 | b"This was read from a file.") |
399 | 404 |
|
| 405 | + def test_path_objects(self): |
| 406 | + # If the source is a Path object, use it as a system ID and open it. |
| 407 | + prep = prepare_input_source(pathlib.Path(self.file)) |
| 408 | + self.assertIsNone(prep.getCharacterStream()) |
| 409 | + self.checkContent(prep.getByteStream(), |
| 410 | + b"This was read from a file.") |
| 411 | + |
400 | 412 | def test_binary_file(self): |
401 | 413 | # If the source is a binary file-like object, use it as a byte |
402 | 414 | # stream. |
|
0 commit comments