Update tests/test_utils_run_later.py
Run CI Tests / test (push) Successful in 1m41s

This commit is contained in:
2025-08-05 10:41:24 +02:00
parent f0651b9b22
commit 64414a8149
+35
View File
@@ -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