test(core): add unit tests for untested core modules
Some checks failed
Test before pr merge / test-lint (pull_request) Failing after 13s
Test before pr merge / test (pull_request) Successful in 40s

Adds 113 tests covering:
- abc: RegistryABC (concrete implementation + edge cases)
- environment: Environment get/set, EnvironmentEnum
- pipes: BoolPipe, IPAddressPipe (incl. roundtrip + error cases)
- time: Cron (next(), intervals, invalid expression)
- utils: Cache (TTL, expiry, cleanup), get_value (incl. bug
  documentation: cast result not returned for string->typed values),
  JSONProcessor (nested objects, enums, defaults)
- property: classproperty (class access, instance access, subclass)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
clu
2026-04-13 18:40:01 +02:00
parent bcca7090d3
commit ca58f636ee
13 changed files with 605 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
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(Exception):
Cron("invalid expression")