Skip to content

Commit b7c3603

Browse files
committed
Use a float for the tolerance in the timer tests
When using an `int`, we need to do a double conversion, first to `float` and then back to `int`, and due to rounding errors, this means there are inconsistencies between the expected and actual values. Using `float` directly ensures we are comparing the same values in the tests and in the code. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 18bb37d commit b7c3603

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tests/test_timer.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,31 @@ def test_policy_skip_missed_and_resync_examples() -> None:
132132

133133

134134
@hypothesis.given(
135-
tolerance=st.integers(min_value=_min_timedelta_microseconds, max_value=-1)
135+
tolerance=st.floats(
136+
min_value=timedelta.min.total_seconds(),
137+
max_value=-1,
138+
exclude_max=False,
139+
allow_nan=False,
140+
allow_infinity=False,
141+
),
136142
)
137-
def test_policy_skip_missed_and_drift_invalid_tolerance(tolerance: int) -> None:
143+
def test_policy_skip_missed_and_drift_invalid_tolerance(tolerance: float) -> None:
138144
"""Test the SkipMissedAndDrift policy raises an error for invalid tolerances."""
139145
with pytest.raises(ValueError, match="delay_tolerance must be positive"):
140146
SkipMissedAndDrift(delay_tolerance=timedelta(microseconds=tolerance))
141147

142148

143149
@hypothesis.given(
144-
tolerance=st.integers(min_value=0, max_value=_max_timedelta_microseconds),
150+
tolerance=st.floats(
151+
min_value=0,
152+
max_value=timedelta.max.total_seconds(),
153+
allow_nan=False,
154+
allow_infinity=False,
155+
),
145156
**_calculate_next_tick_time_args,
146157
)
147158
def test_policy_skip_missed_and_drift(
148-
tolerance: int, now: int, scheduled_tick_time: int, interval: int
159+
tolerance: float, now: int, scheduled_tick_time: int, interval: int
149160
) -> None:
150161
"""Test the SkipMissedAndDrift policy."""
151162
hypothesis.assume(now >= scheduled_tick_time)

0 commit comments

Comments
 (0)