diff --git a/news/tests-restruct.rst b/news/tests-restruct.rst new file mode 100644 index 00000000..4b28c56f --- /dev/null +++ b/news/tests-restruct.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* \tests directory tree to match \src + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* file paths of the test files according to new \tests directory tree + +**Security:** + +* diff --git a/tests/conftest.py b/tests/conftest.py index 5471acc1..09de40f6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -22,8 +22,9 @@ def user_filesystem(tmp_path): @pytest.fixture def datafile(): """Fixture to dynamically load any test file.""" + base_path = Path(__file__).parent / "testdata" # Adjusted base path def _load(filename): - return "tests/testdata/" + filename + return base_path / filename return _load diff --git a/tests/test_loaddata.py b/tests/diffpy/utils/parsers/test_loaddata.py similarity index 100% rename from tests/test_loaddata.py rename to tests/diffpy/utils/parsers/test_loaddata.py diff --git a/tests/test_serialization.py b/tests/diffpy/utils/parsers/test_serialization.py similarity index 91% rename from tests/test_serialization.py rename to tests/diffpy/utils/parsers/test_serialization.py index fc3696bf..0ba397ad 100644 --- a/tests/test_serialization.py +++ b/tests/diffpy/utils/parsers/test_serialization.py @@ -1,4 +1,4 @@ -import os +from pathlib import Path import numpy import pytest @@ -7,26 +7,24 @@ from diffpy.utils.parsers.loaddata import loadData from diffpy.utils.parsers.serialization import deserialize_data, serialize_data -tests_dir = os.path.dirname(os.path.abspath(locals().get("__file__", "file.py"))) - def test_load_multiple(tmp_path, datafile): # Load test data targetjson = datafile("targetjson.json") generatedjson = tmp_path / "generated_serialization.json" - tlm_list = os.listdir(os.path.join(tests_dir, "testdata", "dbload")) - tlm_list.sort() + dbload_dir = datafile("dbload") + tlm_list = sorted(dbload_dir.glob("*.gr")) + generated_data = None - for hfname in tlm_list: + for headerfile in tlm_list: # gather data using loadData - headerfile = os.path.normpath(os.path.join(tests_dir, "testdata", "dbload", hfname)) hdata = loadData(headerfile, headers=True) data_table = loadData(headerfile) # check path extraction generated_data = serialize_data(headerfile, hdata, data_table, dt_colnames=["r", "gr"], show_path=True) - assert headerfile == os.path.normpath(generated_data[hfname].pop("path")) + assert headerfile == Path(generated_data[headerfile.name].pop("path")) # rerun without path information and save to file generated_data = serialize_data( diff --git a/tests/test_diffraction_objects.py b/tests/diffpy/utils/scattering_objects/test_diffraction_objects.py similarity index 100% rename from tests/test_diffraction_objects.py rename to tests/diffpy/utils/scattering_objects/test_diffraction_objects.py diff --git a/tests/test_resample.py b/tests/diffpy/utils/test_resample.py similarity index 100% rename from tests/test_resample.py rename to tests/diffpy/utils/test_resample.py diff --git a/tests/test_tools.py b/tests/diffpy/utils/test_tools.py similarity index 100% rename from tests/test_tools.py rename to tests/diffpy/utils/test_tools.py diff --git a/tests/test_version.py b/tests/diffpy/utils/test_version.py similarity index 100% rename from tests/test_version.py rename to tests/diffpy/utils/test_version.py