Add missing test modules for previously untested core areas: - console: ForegroundColorEnum, BackgroundColorEnum, Console methods - errors: dependency_error, module_dependency_error - log: LogLevel ordering/values, LogSettings, Logger (should_log, format, file write, fatal) - service: HostedService, StartupTask, CronjobABC (start/stop/loop/task cancellation) - time: TimeFormatSettings properties and setters - utils: Benchmark.time / .memory / .all call-count and output Also fix existing test files: environment cleanup, cron exception specificity, json_processor kwargs bug doc, configuration_model_abc to_dict bug doc. All 199 tests pass, black clean. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
import pytest
|
|
from datetime import datetime
|
|
from cpl.core.time.cron import Cron
|
|
|
|
|
|
def test_next_returns_datetime():
|
|
cron = Cron("* * * * *")
|
|
result = cron.next()
|
|
assert isinstance(result, datetime)
|
|
|
|
|
|
def test_next_is_in_the_future():
|
|
cron = Cron("* * * * *")
|
|
result = cron.next()
|
|
assert result > datetime.now()
|
|
|
|
|
|
def test_next_called_multiple_times_is_monotonic():
|
|
cron = Cron("* * * * *")
|
|
results = [cron.next() for _ in range(5)]
|
|
for i in range(1, len(results)):
|
|
assert results[i] > results[i - 1]
|
|
|
|
|
|
def test_every_minute_interval():
|
|
start = datetime(2024, 1, 1, 12, 0, 0)
|
|
cron = Cron("* * * * *", start_time=start)
|
|
first = cron.next()
|
|
second = cron.next()
|
|
diff = (second - first).total_seconds()
|
|
assert diff == 60
|
|
|
|
|
|
def test_hourly_interval():
|
|
start = datetime(2024, 1, 1, 12, 0, 0)
|
|
cron = Cron("0 * * * *", start_time=start)
|
|
first = cron.next()
|
|
second = cron.next()
|
|
diff = (second - first).total_seconds()
|
|
assert diff == 3600
|
|
|
|
|
|
def test_daily_midnight():
|
|
start = datetime(2024, 1, 1, 0, 0, 0)
|
|
cron = Cron("0 0 * * *", start_time=start)
|
|
first = cron.next()
|
|
assert first.hour == 0
|
|
assert first.minute == 0
|
|
|
|
|
|
def test_custom_start_time():
|
|
start = datetime(2024, 6, 15, 10, 30, 0)
|
|
cron = Cron("*/5 * * * *", start_time=start)
|
|
result = cron.next()
|
|
assert result > start
|
|
|
|
|
|
def test_invalid_cron_expression():
|
|
with pytest.raises((ValueError, KeyError)):
|
|
Cron("invalid expression")
|