FIX frequency with long intervals
This commit is contained in:
parent
f48c246ad3
commit
cf87e73cd5
2 changed files with 18 additions and 1 deletions
|
@ -61,6 +61,14 @@ def tenseconds(now, request):
|
||||||
'end': now + days(1)})
|
'end': now + days(1)})
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(params=[1, 2, 3, 4, 5, 6, 7, 8])
|
||||||
|
def manyweeks(request):
|
||||||
|
yield FrequencyAlarm({
|
||||||
|
'interval': '{}w'.format(request.param),
|
||||||
|
'start': 0
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def days(n):
|
def days(n):
|
||||||
return timedelta(days=n)
|
return timedelta(days=n)
|
||||||
|
|
||||||
|
@ -155,6 +163,15 @@ def test_sunday_is_not_0():
|
||||||
assert 'Not a valid weekday:' in excinfo.value.args[0]
|
assert 'Not a valid weekday:' in excinfo.value.args[0]
|
||||||
|
|
||||||
|
|
||||||
|
def test_long_interval(manyweeks):
|
||||||
|
t = datetime.fromtimestamp(1)
|
||||||
|
expected = manyweeks.interval
|
||||||
|
got = manyweeks.next_ring(t)
|
||||||
|
assert got is not None
|
||||||
|
assert int(got.strftime('%s')) == expected
|
||||||
|
assert manyweeks.next_ring(got) is not None
|
||||||
|
|
||||||
|
|
||||||
def test_single_registered():
|
def test_single_registered():
|
||||||
timegenerate({
|
timegenerate({
|
||||||
'kind': 'single',
|
'kind': 'single',
|
||||||
|
|
|
@ -100,7 +100,7 @@ class FrequencyAlarm(Alarm):
|
||||||
# fact, it is necessary to retry until a valid event/weekday is
|
# fact, it is necessary to retry until a valid event/weekday is
|
||||||
# found. a "while True" might have been more elegant (and maybe
|
# found. a "while True" might have been more elegant (and maybe
|
||||||
# fast), but this gives a clear upper bound to the cycle.
|
# fast), but this gives a clear upper bound to the cycle.
|
||||||
for _ in range(60*60*24*7 // self.interval):
|
for _ in range(max(60*60*24*7 // self.interval, 1)):
|
||||||
n_interval = (
|
n_interval = (
|
||||||
(current_time - self.start).total_seconds() // self.interval
|
(current_time - self.start).total_seconds() // self.interval
|
||||||
) + 1
|
) + 1
|
||||||
|
|
Loading…
Reference in a new issue