CI / lint (pull_request) Successful in 34s
CI / test (3.12) (pull_request) Successful in 22s
CI / test (3.13) (pull_request) Successful in 30s
CI / test (3.11) (pull_request) Successful in 35s
CI / lint (push) Canceled after 10s
CI / test (3.11) (push) Canceled after 0s
CI / test (3.12) (push) Canceled after 0s
CI / test (3.13) (push) Canceled after 0s
Build and Publish / release (push) Successful in 11s
DataCollectionParameters.transmission was the outlier: int percent 0-100 while BeamlineStatus / SimpleScanParameters / FluorescenceSpectrum already used a 0-1 fraction. Per the DAQ/DB consensus it is now a strict Annotated[float, Field(ge=0.0, le=1.0)] fraction (1.0 = full beam); percent-scale values in (1.0, 100.0] fail validation by design instead of being silently reinterpreted. RotationScanRequest / RasterGridRequest gain the same constraint (production data is already fraction on those paths). Human-facing surfaces (user spreadsheets, AareDB public API) stay percent; their converters live in AareDB at the boundary. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HiGzkkuiZXei894cnJfgSg
97 lines
3.0 KiB
Python
97 lines
3.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_aperture_accepts_float_string():
|
|
params = DataCollectionParameters(aperture="2.0")
|
|
assert params.aperture == 2
|
|
|
|
|
|
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)
|