Skip to content

Commit

Permalink
TST: refactor data path for xml tests (#53766)
Browse files Browse the repository at this point in the history
* TST: refactor data path for xml tests

* fix style

* fix typo
  • Loading branch information
fangchenli committed Jun 21, 2023
1 parent 841ebb1 commit 942bf3e
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 176 deletions.
11 changes: 11 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from decimal import Decimal
import operator
import os
from pathlib import Path
from typing import (
Callable,
Hashable,
Expand Down Expand Up @@ -1167,6 +1168,16 @@ def strict_data_files(pytestconfig):
return pytestconfig.getoption("--strict-data-files")


@pytest.fixture
def tests_path() -> Path:
return Path(__file__).parent / "tests"


@pytest.fixture
def tests_io_data_path(tests_path) -> Path:
return tests_path / "io" / "data"


@pytest.fixture
def datapath(strict_data_files: str) -> Callable[..., str]:
"""
Expand Down
8 changes: 6 additions & 2 deletions pandas/io/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import annotations

import io
from os import PathLike
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -326,10 +327,13 @@ def _iterparse_nodes(self, iterparse: Callable) -> list[dict[str, str | None]]:
)

if (not hasattr(self.path_or_buffer, "read")) and (
not isinstance(self.path_or_buffer, str)
not isinstance(self.path_or_buffer, (str, PathLike))
or is_url(self.path_or_buffer)
or is_fsspec_url(self.path_or_buffer)
or self.path_or_buffer.startswith(("<?xml", "<"))
or (
isinstance(self.path_or_buffer, str)
and self.path_or_buffer.startswith(("<?xml", "<"))
)
or infer_compression(self.path_or_buffer, "infer") is not None
):
raise ParserError(
Expand Down
31 changes: 31 additions & 0 deletions pandas/tests/io/xml/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest


@pytest.fixture
def xml_data_path(tests_io_data_path):
return tests_io_data_path / "xml"


@pytest.fixture
def xml_books(xml_data_path):
return xml_data_path / "books.xml"


@pytest.fixture
def xml_doc_ch_utf(xml_data_path):
return xml_data_path / "doc_ch_utf.xml"


@pytest.fixture
def xml_baby_names(xml_data_path):
return xml_data_path / "baby_names.xml"


@pytest.fixture
def kml_cta_rail_lines(xml_data_path):
return xml_data_path / "cta_rail_lines.kml"


@pytest.fixture
def xsl_flatten_doc(xml_data_path):
return xml_data_path / "flatten_doc.xsl"

0 comments on commit 942bf3e

Please sign in to comment.