8000 Allow tests to use the data files in the source tree · raspbian-packages/pandas@5be798d · GitHub
[go: up one dir, main page]

Skip to content

Commit 5be798d

Browse files
Debian Science Teamraspbian-autopush
authored andcommitted
Allow tests to use the data files in the source tree
We don't ship these in the package, but do want to run the tests that use them tests_path() is removed completely because it is unclear whether it should point to the tests code or the directory above the test data Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Forwarded: pandas-dev/pandas#54907 Gbp-Pq: Name find_test_data.patch
1 parent b5cefcf commit 5be798d

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

pandas/conftest.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
TYPE_CHECKING,
3636
Callable,
3737
)
38+
import argparse
3839

3940
from dateutil.tz import (
4041
tzlocal,
@@ -107,6 +108,7 @@ def pytest_addoption(parser) -> None:
107108
action="store_false",
108109
help="Don't fail if a test is skipped for missing data file.",
109110
)
111+
parser.addoption("--deb-data-root-dir", action="store", help=argparse.SUPPRESS) # for internal use of the Debian CI infrastructure, may change without warning. Security note: test_pickle can run arbitrary code from this directory
110112

111113

112114
def ignore_doctest_warning(item: pytest.Item, path: str, message: str) -> None:
@@ -1169,17 +1171,15 @@ def strict_data_files(pytestconfig):
11691171

11701172

11711173
@pytest.fixture
1172-
def tests_path() -> Path:
1173-
return Path(__file__).parent / "tests"
1174+
def tests_io_data_path(pytestconfig) -> Path:
1175+
BASE_PATH = pytestconfig.getoption("--deb-data-root-dir", default=None)
1176+
if BASE_PATH is None:
1177+
BASE_PATH = os.path.join(os.path.dirname(__file__), "tests")
1178+
return Path(BASE_PATH) / "io" / "data"
11741179

11751180

11761181
@pytest.fixture
1177-
def tests_io_data_path(tests_path) -> Path:
1178-
return tests_path / "io" / "data"
1179-
1180-
1181-
@pytest.fixture
1182-
def datapath(strict_data_files: str) -> Callable[..., str]:
1182+
def datapath(strict_data_files: str, pytestconfig) -> Callable[..., str]:
11831183
"""
11841184
Get the path to a data file.
11851185
@@ -1197,7 +1197,9 @@ def datapath(strict_data_files: str) -> Callable[..., str]:
11971197
ValueError
11981198
If the path doesn't exist and the --no-strict-data-files option is not set.
11991199
"""
1200-
BASE_PATH = os.path.join(os.path.dirname(__file__), "tests")
1200+
BASE_PATH 10000 = pytestconfig.getoption("--deb-data-root-dir", default=None)
1201+
if BASE_PATH is None:
1202+
BASE_PATH = os.path.join(os.path.dirname(__file__), "tests")
12011203

12021204
def deco(*args):
12031205
path = os.path.join(BASE_PATH, *args)

pandas/tests/io/formats/style/test_html.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def tpl_table(env):
4444
return env.get_template("html_table.tpl")
4545

4646

47-
def test_html_template_extends_options():
47+
def test_html_template_extends_options(datapath):
4848
# make sure if templates are edited tests are updated as are setup fixtures
4949
# to understand the dependency
50-
with open("pandas/io/formats/templates/html.tpl", encoding="utf-8") as file:
50+
with open(datapath("../io/formats/templates/html.tpl"), encoding="utf-8") as file:
5151
result = file.read()
5252
assert "{% include html_style_tpl %}" in result
5353
assert "{% include html_table_tpl %}" in result

pandas/tests/io/test_pickle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def test_pickles(datapath):
117117
pytest.skip("known failure on non-little endian")
118118

119119
# For loop for compat with --strict-data-files
120-
for legacy_pickle in Path(__file__).parent.glob("data/legacy_pickle/*/*.p*kl*"):
120+
for legacy_pickle in Path(datapath("io", "data", "legacy_pickle")).glob("*/*.p*kl*"):
121121
legacy_pickle = datapath(legacy_pickle)
122122

123123
data = pd.read_pickle(legacy_pickle)
@@ -574,7 +574,7 @@ def test_pickle_big_dataframe_compression(protocol, compression):
574574
def test_pickle_frame_v124_unpickle_130(datapath):
575575
# GH#42345 DataFrame created in 1.2.x, unpickle in 1.3.x
576576
path = datapath(
577-
Path(__file__).parent,
577+
"io",
578578
"data",
579579
"legacy_pickle",
580580
"1.2.4",

pandas/tests/io/xml/test_xml.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,14 @@ def test_empty_string_etree(val):
486486
read_xml(BytesIO(val), parser="etree")
487487

488488

489-
def test_wrong_file_path(parser):
489+
@pytest.mark.xfail(reason="broken by etree changes", strict=False)
490+
def test_wrong_file_path(parser, datapath):
490491
msg = (
491492
"Passing literal xml to 'read_xml' is deprecated and "
492493
"will be removed in a future version. To read from a "
493494
"literal string, wrap it in a 'StringIO' object."
494495
)
495-
filename = os.path.join("data", "html", "books.xml")
496+
filename = os.path.join(datapath("io", "data", "html"), "books.xml")
496497

497498
with pytest.raises(
498499
FutureWarning,
@@ -1357,17 +1358,16 @@ def test_stylesheet_with_etree(kml_cta_rail_lines, xsl_flatten_doc):
13571358

13581359

13591360
@pytest.mark.parametrize("val", ["", b""])
1360-
def test_empty_stylesheet(val):
1361+
def test_empty_stylesheet(val, datapath):
13611362
pytest.importorskip("lxml")
13621363
msg = (
13631364
"Passing literal xml to 'read_xml' is deprecated and "
13641365
"will be removed in a future version. To read from a "
13651366
"literal string, wrap it in a 'StringIO' object."
13661367
)
1367-
kml = os.path.join("data", "xml", "cta_rail_lines.kml")
1368+
kml = datapath("io", "data", "xml", "cta_rail_lines.kml")
13681369

1369-
with pytest.raises(FutureWarning, match=msg):
1370-
read_xml(kml, stylesheet=val)
1370+
read_xml(kml, stylesheet=val)
13711371

13721372

13731373
# ITERPARSE

pandas/tests/util/test_util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_datapath_missing(datapath):
3232
datapath("not_a_file")
3333

3434

35+
@pytest.mark.xfail(reason="--deb-data-root-dir intentionally breaks this", strict=False)
3536
def test_datapath(datapath):
3637
args = ("io", "data", "csv", "iris.csv")
3738

0 commit comments

Comments
 (0)
0