Files
AareCommon/tests/test_data_collection_parameters.py
GotthardGandClaude Fable 5.1 8267b704df
CI / lint (push) Skipped
CI / test (3.11) (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
refactor!: drop never-real dcp fields, deprecate the unused ones
DataCollectionParameters cleanup (AareDB audit 2026-09-08, 12,494 prod
samples + consumer grep across AareDAQ / AareProc / AareDB):

Removed — early-development leftovers, never populated, read by nothing;
the beamlines have no aperture: aperture, rescutkey, rescutvalue,
trustedhigh, chiphiangles. Stored blobs still carrying the keys are
ignored on input (extra keys are dropped), not rejected.

Deprecated (Field(deprecated=...), warn on access, flagged in the JSON
schema; removed next major): autoprocfull, procfull, adpenabled,
ffcscampaign, datacollectiontype — never set by users, no consumer;
the stored values are importer-era noise (false / 'standard').

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GPer4T34EcvqVJGpeiEJ4Y
2026-09-08 17:19:17 +02:00

118 lines
4.0 KiB
Python

import pytest
from pydantic import ValidationError
from aarecommon.models.models import DataCollectionParameters
def test_directory_defaults_when_missing():
params = DataCollectionParameters()
assert params.directory is None
def test_directory_blank_defaults_to_macro_path():
params = DataCollectionParameters(directory="")
assert params.directory == "{date}/{prefix}"
def test_directory_spaces_are_replaced():
params = DataCollectionParameters(directory="my folder/run 1")
assert params.directory == "my_folder/run_1"
def test_directory_rejects_invalid_characters():
with pytest.raises(ValidationError):
DataCollectionParameters(directory="bad|path")
def test_exposure_accepts_values_above_1_after_refactor():
params = DataCollectionParameters(exposure=1.5)
assert params.exposure == 1.5
def test_cloud_blank_defaults_to_true():
params = DataCollectionParameters(cloud="")
assert params.cloud is True
def test_directory_accepts_valid_macros():
params = DataCollectionParameters(directory="{date}/{prefix}/run")
assert params.directory == "{date}/{prefix}/run"
def test_processingpipeline_accepts_unknown_value_after_refactor():
params = DataCollectionParameters(processingpipeline="xia2")
assert params.processingpipeline == "xia2"
def test_datacollectionparameters_accepts_legacy_aliases():
params = DataCollectionParameters(
totalrange=180, cellparameters="10 20 30 90 90 120", userresolution=1.4
)
assert params.totalangle == 180
assert params.unitcell == "10 20 30 90 90 120"
assert params.processingresolution == 1.4
def test_datacollectionparameters_accepts_new_fields():
params = DataCollectionParameters(
totalangle=90,
unitcell="11,22,33,90,90,120",
processingresolution=1.2,
pdbmodel="model.pdb",
cloud=False,
)
assert params.totalangle == 90
assert params.unitcell == "11,22,33,90,90,120"
assert params.processingresolution == 1.2
assert params.pdbmodel == "model.pdb"
assert params.cloud is False
def test_transmission_is_a_fraction_of_full_beam():
params = DataCollectionParameters(transmission=0.35)
assert params.transmission == 0.35
def test_transmission_boundaries_are_valid():
assert DataCollectionParameters(transmission=0.0).transmission == 0.0
assert DataCollectionParameters(transmission=1.0).transmission == 1.0
def test_transmission_rejects_percent_scale_values():
# Percent-scale leftovers (1.0, 100.0] must fail loudly, never be
# silently reinterpreted — converters live at the producing boundary.
for percent in (1.5, 35, 100):
with pytest.raises(ValidationError):
DataCollectionParameters(transmission=percent)
def test_transmission_rejects_negative_values():
with pytest.raises(ValidationError):
DataCollectionParameters(transmission=-0.1)
def test_removed_fields_are_ignored_on_input():
# aperture / rescutkey / rescutvalue / trustedhigh / chiphiangles were early-
# development leftovers (the beamlines have no aperture) that nothing ever
# read; stored blobs still carry the keys, so they must be ignored, not rejected.
params = DataCollectionParameters(
aperture="50um", rescutkey="isig", rescutvalue=2.0, trustedhigh=1.0, chiphiangles=5.0
)
for name in ("aperture", "rescutkey", "rescutvalue", "trustedhigh", "chiphiangles"):
assert name not in DataCollectionParameters.model_fields
assert not hasattr(params, name)
def test_deprecated_fields_still_validate_but_warn():
params = DataCollectionParameters(
autoprocfull=False,
procfull=False,
adpenabled=False,
ffcscampaign=False,
datacollectiontype="standard",
)
for name in ("autoprocfull", "procfull", "adpenabled", "ffcscampaign", "datacollectiontype"):
assert DataCollectionParameters.model_fields[name].deprecated
with pytest.warns(DeprecationWarning):
getattr(params, name)