Skip to content

Commit d17e44e

Browse files
committed
Remove Timer.periodic() and Timer.timeout() from tests
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 841cf87 commit d17e44e

File tree

3 files changed

+13
-51
lines changed

3 files changed

+13
-51
lines changed

tests/test_file_watcher_integration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from frequenz.channels import select, selected_from
1313
from frequenz.channels.file_watcher import Event, EventType, FileWatcher
14-
from frequenz.channels.timer import Timer
14+
from frequenz.channels.timer import SkipMissedAndDrift, Timer
1515

1616

1717
@pytest.mark.integration
@@ -27,7 +27,7 @@ async def test_file_watcher(tmp_path: pathlib.Path) -> None:
2727
expected_number_of_writes = 3
2828

2929
file_watcher = FileWatcher(paths=[str(tmp_path)])
30-
timer = Timer.timeout(timedelta(seconds=0.1))
30+
timer = Timer(timedelta(seconds=0.1), SkipMissedAndDrift())
3131

3232
async for selected in select(file_watcher, timer):
3333
if selected_from(selected, timer):
@@ -55,8 +55,8 @@ async def test_file_watcher_deletes(tmp_path: pathlib.Path) -> None:
5555
"""
5656
filename = tmp_path / "test-file"
5757
file_watcher = FileWatcher(paths=[str(tmp_path)], event_types={EventType.DELETE})
58-
write_timer = Timer.timeout(timedelta(seconds=0.1))
59-
deletion_timer = Timer.timeout(timedelta(seconds=0.25))
58+
write_timer = Timer(timedelta(seconds=0.1), SkipMissedAndDrift())
59+
deletion_timer = Timer(timedelta(seconds=0.25), SkipMissedAndDrift())
6060

6161
number_of_write = 0
6262
number_of_deletes = 0

tests/test_timer.py

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -266,53 +266,15 @@ async def test_timer_construction_custom_args() -> None:
266266
assert timer.is_running is True
267267

268268

269-
async def test_timer_construction_timeout_custom_args() -> None:
270-
"""Test the construction of a timeout timer with custom arguments."""
271-
timer = Timer.timeout(
272-
timedelta(seconds=5.0),
273-
auto_start=True,
274-
loop=None,
275-
)
276-
assert timer.interval == timedelta(seconds=5.0)
277-
assert isinstance(timer.missed_tick_policy, SkipMissedAndDrift)
278-
assert timer.missed_tick_policy.delay_tolerance == timedelta(0)
279-
assert timer.loop is asyncio.get_running_loop()
280-
assert timer.is_running is True
281-
282-
283-
async def test_timer_construction_periodic_defaults() -> None:
284-
"""Test the construction of a periodic timer."""
285-
timer = Timer.periodic(timedelta(seconds=5.0))
286-
assert timer.interval == timedelta(seconds=5.0)
287-
assert isinstance(timer.missed_tick_policy, TriggerAllMissed)
288-
assert timer.loop is asyncio.get_running_loop()
289-
assert timer.is_running is True
290-
291-
292-
async def test_timer_construction_periodic_custom_args() -> None:
293-
"""Test the construction of a timeout timer with custom arguments."""
294-
timer = Timer.periodic(
295-
timedelta(seconds=5.0),
296-
skip_missed_ticks=True,
297-
auto_start=True,
298-
start_delay=timedelta(seconds=1.0),
299-
loop=None,
300-
)
301-
assert timer.interval == timedelta(seconds=5.0)
302-
assert isinstance(timer.missed_tick_policy, SkipMissedAndResync)
303-
assert timer.loop is asyncio.get_running_loop()
304-
assert timer.is_running is True
305-
306-
307269
async def test_timer_construction_wrong_args() -> None:
308-
"""Test the construction of a timeout timer with wrong arguments."""
270+
"""Test the construction of a timer with wrong arguments."""
309271
with pytest.raises(
310272
ValueError,
311273
match="^The `interval` must be positive and at least 1 microsecond, not -1 day, 23:59:55$",
312274
):
313-
_ = Timer.periodic(
275+
_ = Timer(
314276
timedelta(seconds=-5.0),
315-
skip_missed_ticks=True,
277+
SkipMissedAndResync(),
316278
auto_start=True,
317279
loop=None,
318280
)
@@ -321,9 +283,9 @@ async def test_timer_construction_wrong_args() -> None:
321283
ValueError,
322284
match="^`start_delay` can't be negative, got -1 day, 23:59:59$",
323285
):
324-
_ = Timer.periodic(
286+
_ = Timer(
325287
timedelta(seconds=5.0),
326-
skip_missed_ticks=True,
288+
SkipMissedAndResync(),
327289
auto_start=True,
328290
start_delay=timedelta(seconds=-1.0),
329291
loop=None,
@@ -333,9 +295,9 @@ async def test_timer_construction_wrong_args() -> None:
333295
ValueError,
334296
match="^`auto_start` must be `True` if a `start_delay` is specified$",
335297
):
336-
_ = Timer.periodic(
298+
_ = Timer(
337299
timedelta(seconds=5.0),
338-
skip_missed_ticks=True,
300+
SkipMissedAndResync(),
339301
auto_start=False,
340302
start_delay=timedelta(seconds=1.0),
341303
loop=None,

tests/test_timer_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import async_solipsism
1111
import pytest
1212

13-
from frequenz.channels.timer import Timer
13+
from frequenz.channels.timer import SkipMissedAndDrift, Timer
1414

1515

1616
@pytest.mark.integration
@@ -24,7 +24,7 @@ async def timer_wait(timer: Timer) -> None:
2424

2525
async with asyncio.timeout(2.0):
2626
async with asyncio.TaskGroup() as task_group:
27-
timer = Timer.timeout(timedelta(seconds=1.0))
27+
timer = Timer(timedelta(seconds=1.0), SkipMissedAndDrift())
2828
start_time = event_loop.time()
2929
task_group.create_task(timer_wait(timer))
3030
await asyncio.sleep(0.5)

0 commit comments

Comments
 (0)