Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 15 additions & 7 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


# -------------------------------
Expand Down Expand Up @@ -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")

Expand Down
2 changes: 2 additions & 0 deletions test/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down
7 changes: 6 additions & 1 deletion test/test_folders.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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},
)

Expand Down