Skip to content

Commit 11673ac

Browse files
fangchenliim-vinicius
authored and
im-vinicius
committed
TST: refactor data path for xml tests (pandas-dev#53766)
* TST: refactor data path for xml tests * fix style * fix typo
1 parent c840305 commit 11673ac

File tree

4 files changed

+153
-176
lines changed

4 files changed

+153
-176
lines changed

pandas/conftest.py

+11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from decimal import Decimal
3131
import operator
3232
import os
33+
from pathlib import Path
3334
from typing import (
3435
Callable,
3536
Hashable,
@@ -1167,6 +1168,16 @@ def strict_data_files(pytestconfig):
11671168
return pytestconfig.getoption("--strict-data-files")
11681169

11691170

1171+
@pytest.fixture
1172+
def tests_path() -> Path:
1173+
return Path(__file__).parent / "tests"
1174+
1175+
1176+
@pytest.fixture
1177+
def tests_io_data_path(tests_path) -> Path:
1178+
return tests_path / "io" / "data"
1179+
1180+
11701181
@pytest.fixture
11711182
def datapath(strict_data_files: str) -> Callable[..., str]:
11721183
"""

pandas/io/xml.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import annotations
66

77
import io
8+
from os import PathLike
89
from typing import (
910
TYPE_CHECKING,
1011
Any,
@@ -326,10 +327,13 @@ def _iterparse_nodes(self, iterparse: Callable) -> list[dict[str, str | None]]:
326327
)
327328

328329
if (not hasattr(self.path_or_buffer, "read")) and (
329-
not isinstance(self.path_or_buffer, str)
330+
not isinstance(self.path_or_buffer, (str, PathLike))
330331
or is_url(self.path_or_buffer)
331332
or is_fsspec_url(self.path_or_buffer)
332-
or self.path_or_buffer.startswith(("<?xml", "<"))
333+
or (
334+
isinstance(self.path_or_buffer, str)
335+
and self.path_or_buffer.startswith(("<?xml", "<"))
336+
)
333337
or infer_compression(self.path_or_buffer, "infer") is not None
334338
):
335339
raise ParserError(

pandas/tests/io/xml/conftest.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
3+
4+
@pytest.fixture
5+
def xml_data_path(tests_io_data_path):
6+
return tests_io_data_path / "xml"
7+
8+
9+
@pytest.fixture
10+
def xml_books(xml_data_path):
11+
return xml_data_path / "books.xml"
12+
13+
14+
@pytest.fixture
15+
def xml_doc_ch_utf(xml_data_path):
16+
return xml_data_path / "doc_ch_utf.xml"
17+
18+
19+
@pytest.fixture
20+
def xml_baby_names(xml_data_path):
21+
return xml_data_path / "baby_names.xml"
22+
23+
24+
@pytest.fixture
25+
def kml_cta_rail_lines(xml_data_path):
26+
return xml_data_path / "cta_rail_lines.kml"
27+
28+
29+
@pytest.fixture
30+
def xsl_flatten_doc(xml_data_path):
31+
return xml_data_path / "flatten_doc.xsl"

0 commit comments

Comments
 (0)