Skip to content

TST: refactor data path for xml tests #53766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading