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
14 changes: 11 additions & 3 deletions src/mozanalysis/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,12 +1458,20 @@ class AnalysisWindow:

@start.validator
def _validate_start(self, attribute, value):
assert (value >= 0 and self.end >= 0) or (value < 0 and self.end < 0)
assert (value >= 0 and self.end >= 0) or (value < 0 and self.end < 0), (
f"AnalysisWindow `start` invalid: {value} and {self.end} must share a sign",
"(either both positive/zero, or both negative)",
)

@end.validator
def _validate_end(self, attribute, value):
assert value >= self.start
assert (value >= 0 and self.start >= 0) or (value < 0 and self.start < 0)
assert value >= self.start, (
f"AnalysisWindow `end` invalid: {value} must be >= {self.start}"
)
assert (value >= 0 and self.start >= 0) or (value < 0 and self.start < 0), (
f"AnalysisWindow `end` invalid: {value} and {self.start} must share a sign",
"(either both positive/zero, or both negative)",
)


@attr.s(frozen=True, slots=True)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
from mozanalysis.segments import Segment, SegmentDataSource


@pytest.mark.parametrize(("start", "end", "invalid"), [(-1, 1, "start"), (3, 1, "end")])
def test_analysis_window_validation(start, end, invalid):
with pytest.raises(AssertionError, match=f"AnalysisWindow `{invalid}` invalid"):
AnalysisWindow(start, end)


def test_time_limits_validates():
# Mainly check that the validation is running at all
# No need to specify the same checks twice(?)
Expand Down