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
11 changes: 8 additions & 3 deletions src/pyrecest/filters/update_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ def __post_init__(self):
"active_measurement_indices must be smaller than measurement_count"
)
object.__setattr__(self, "measurement_count", measurement_count)
object.__setattr__(self, "skipped_reason", _normalize_skipped_reason(self.skipped_reason))
skipped_reason = _normalize_skipped_reason(self.skipped_reason)
if skipped_reason is not None and indices:
raise ValueError(
"skipped diagnostics must not contain active_measurement_indices"
)
object.__setattr__(self, "skipped_reason", skipped_reason)
object.__setattr__(self, "metadata", _normalize_metadata(self.metadata))

@property
Expand Down Expand Up @@ -114,8 +119,8 @@ def _normalize_skipped_reason(skipped_reason: str | None) -> str | None:
return None
if not isinstance(skipped_reason, str):
raise ValueError("skipped_reason must be a string or None")
if not skipped_reason:
raise ValueError("skipped_reason must not be empty")
if not skipped_reason.strip():
raise ValueError("skipped_reason must not be empty or whitespace-only")
return skipped_reason


Expand Down
14 changes: 13 additions & 1 deletion tests/filters/test_update_diagnostics_skipped_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
from pyrecest.filters.update_diagnostics import MeasurementUpdateDiagnostics


@pytest.mark.parametrize("skipped_reason", ["", 0, object()])
@pytest.mark.parametrize("skipped_reason", ["", " ", 0, object()])
def test_skipped_reason_rejects_non_text_or_empty_values(skipped_reason):
with pytest.raises(ValueError, match="skipped_reason"):
MeasurementUpdateDiagnostics(skipped_reason=skipped_reason)


def test_skipped_reason_rejects_active_measurements():
with pytest.raises(
ValueError,
match="skipped diagnostics must not contain active_measurement_indices",
):
MeasurementUpdateDiagnostics(
active_measurement_indices=[0],
measurement_count=1,
skipped_reason="gated",
)


def test_skipped_constructor_accepts_non_empty_reason():
diagnostics = MeasurementUpdateDiagnostics.skipped("gated")

Expand Down
Loading