From 59733257bb1b84d42a6ce08845ce02b06b5bd800 Mon Sep 17 00:00:00 2001 From: vitous Date: Thu, 23 Jul 2026 17:02:48 +0200 Subject: [PATCH] mark zenodo data optional --- .github/workflows/python-ci.yml | 2 +- test/conftest.py | 22 +++++++++++++++------- test/test_dataset.py | 2 ++ test/test_folders.py | 7 ++++++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 862c06a..45d1625 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -82,7 +82,7 @@ jobs: - name: Run all dataset tests run: | - python -m pytest test -v --cov=brukerapi --cov-branch --cov-report=xml --cov-report=term-missing --cov-report=html + python -m pytest test -v --download_test_data --cov=brukerapi --cov-branch --cov-report=xml --cov-report=term-missing --cov-report=html - name: Upload coverage HTML uses: actions/upload-artifact@v7 diff --git a/test/conftest.py b/test/conftest.py index 0380a8f..031c789 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -20,6 +20,7 @@ def pytest_addoption(parser): parser.addoption("--test_data", action="store", default="") parser.addoption("--test_suites", action="store", default="") parser.addoption("--properties_reference", action="store", default="") + parser.addoption("--download_test_data", action="store_true", default=False) # ------------------------------- @@ -49,22 +50,29 @@ def pytest_addoption(parser): def pytest_sessionstart(session): - for dataset in ZENODO_FILES: - _ensure_test_data(dataset) - for dataset in GITHUB_DATASETS: - _ensure_github_test_data(dataset) + if not session.config.getoption("download_test_data"): + return + + for dataset in _requested_dataset_names(session.config.getoption("test_data")): + if dataset in ZENODO_FILES: + _ensure_test_data(dataset) + elif dataset in GITHUB_DATASETS: + _ensure_github_test_data(dataset) # ------------------------------- # Helpers # ------------------------------- -def _resolve_requested_datasets(opt: str | None): +def _requested_dataset_names(opt: str | None): if not opt or opt.lower() == "all": - available_local_datasets = [name for name in LOCAL_DATASETS if (TEST_DATA_ROOT / name).is_dir()] - return [*ZENODO_FILES, *GITHUB_DATASETS, *available_local_datasets] + return [*ZENODO_FILES, *GITHUB_DATASETS, *LOCAL_DATASETS] return [opt] +def _resolve_requested_datasets(opt: str | None): + return [name for name in _requested_dataset_names(opt) if (TEST_DATA_ROOT / name).is_dir()] + + def _is_required_github_data_file(path: Path): return path.name in {"2dseq", "traj"} or path.name.startswith("rawdata.job") diff --git a/test/test_dataset.py b/test/test_dataset.py index 164e76f..6c72a0b 100644 --- a/test/test_dataset.py +++ b/test/test_dataset.py @@ -10,6 +10,7 @@ from brukerapi.exceptions import UnsuportedDatasetType data = 0 +PV51_STUDY_PATH = Path("test/test_data/PV51/0.2H2") def test_unsupported_dataset_type(tmp_path): @@ -27,6 +28,7 @@ def test_unsupported_dataset_type(tmp_path): ("test/test_data/PV51/0.2H2/10/pdata/1", "2dseq"), ], ) +@pytest.mark.skipif(not PV51_STUDY_PATH.is_dir(), reason="PV51 test data is not available") def test_directory_constructor_uses_default_load(path, dataset_type): dataset = Dataset(path) diff --git a/test/test_folders.py b/test/test_folders.py index edd3384..d85b0c3 100644 --- a/test/test_folders.py +++ b/test/test_folders.py @@ -1,8 +1,12 @@ from pathlib import Path +import pytest + from brukerapi.dataset import Dataset from brukerapi.folders import Folder, Processing, Study +PV51_STUDY_PATH = Path("test/test_data/PV51/0.2H2") + def test_folder_traversal_skips_processed_spectra(tmp_path): experiment_path = tmp_path / "1" @@ -35,9 +39,10 @@ def test_folder_traversal_skips_processed_spectra(tmp_path): assert processing_datasets == {"2dseq"} +@pytest.mark.skipif(not PV51_STUDY_PATH.is_dir(), reason="PV51 test data is not available") def test_study_get_dataset_returns_fid_and_2dseq(): study = Study( - Path("test/test_data/PV51/0.2H2"), + PV51_STUDY_PATH, dataset_state={"parameter_files": [], "property_files": [], "load": 0}, )