diff --git a/tests/test_utils_run_later.py b/tests/test_utils_run_later.py index 3817807ce..014e79f66 100644 --- a/tests/test_utils_run_later.py +++ b/tests/test_utils_run_later.py @@ -4,6 +4,7 @@ from datetime import datetime, timedelta from slic.utils.run_later import run_at, run_in, run_later, today, tomorrow, yesterday +''' # Dummy progress bar to disable actual waiting class DummyBar: def __enter__(self): return self @@ -73,3 +74,37 @@ def test_run_later(patch_time): traveller.move_to("2025-01-01 14:02:00") run_later(60, fexample, "later") assert "later" in triggered +''' + +import pytest +import time_machine +from datetime import datetime, timedelta +from slic.utils.run_later import run_at + + +def fexample(label): + print(f"Triggered: {label}") + + +def test_run_at_future_triggered_and_logs(capsys): + with time_machine.travel(datetime(2025, 1, 1, 12, 0, 0), tick=True): + + run_at(datetime(2025, 1, 1, 12, 0, 0) + timedelta(seconds=0.2), fexample, "A") + + captured = capsys.readouterr().out + + assert "will run at" in captured + assert "this will be in" in captured + assert "Triggered: A" in captured + + +def test_run_at_already_past(capsys): + with time_machine.travel(datetime(2025, 1, 1, 12, 0, 0), tick=True): + + run_at(datetime(2025, 1, 1, 11, 59, 59), fexample, "B") + + captured = capsys.readouterr().out + + assert "it is already past" in captured + assert "ago" in captured + assert "Triggered: B" not in captured \ No newline at end of file