CI / lint (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
import pytest
|
|
from aarecommon.models.models import SampleShortInfo
|
|
|
|
from aare.daq.samples import DummySampleStore
|
|
|
|
|
|
def test_shipped_catalogue_loads():
|
|
store = DummySampleStore()
|
|
samples = store.spreadsheet.s
|
|
tools = store.reference_tools.s
|
|
assert samples and tools, "shipped dummy_samples.json should fill both lists"
|
|
assert all(isinstance(s, SampleShortInfo) for s in samples + tools)
|
|
ids = [s.db_id for s in samples + tools]
|
|
assert len(set(ids)) == len(ids), "db_ids must be unique across both lists"
|
|
assert all(s.location and s.location.segment == "X" for s in tools)
|
|
assert all(s.location and s.location.segment != "X" for s in samples)
|
|
assert all(s.user.startswith("p") for s in samples + tools)
|
|
|
|
|
|
def test_find_sample_in_each_list(tmp_path):
|
|
path = tmp_path / "samples.json"
|
|
path.write_text(
|
|
"""{
|
|
"samples": [{"db_id": 7, "puck_name": "P", "dewar_name": "D", "sample_name": "x",
|
|
"run_number": 1, "user": "p1", "pin": 1}],
|
|
"reference_tools": [{"db_id": 8, "puck_name": "R", "dewar_name": "D", "sample_name": "y",
|
|
"run_number": 1, "user": "p2", "pin": 1}]
|
|
}"""
|
|
)
|
|
store = DummySampleStore(path)
|
|
assert store.find_sample(7).user == "p1"
|
|
assert store.find_sample(7, reference=True) is None
|
|
assert store.find_sample(8, reference=True).user == "p2"
|
|
assert store.find_sample(8) is None
|
|
assert store.find_sample(99) is None
|
|
|
|
|
|
def test_invalid_catalogue_rejected(tmp_path):
|
|
path = tmp_path / "samples.json"
|
|
path.write_text('{"samples": [{"db_id": "seven"}], "reference_tools": []}')
|
|
with pytest.raises(ValueError):
|
|
DummySampleStore(path)
|