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,66 @@
import pytest
from cpl.core.abc.registry_abc import RegistryABC
class StringRegistry(RegistryABC[str]):
def __init__(self):
super().__init__()
def extend(self, items: list[str]) -> None:
for item in items:
self.add(item)
def add(self, item: str) -> None:
self._items[item] = item
def get(self, key: str) -> str | None:
return self._items.get(key)
def all(self) -> list[str]:
return list(self._items.values())
def test_add_and_get():
reg = StringRegistry()
reg.add("hello")
assert reg.get("hello") == "hello"
def test_get_missing_returns_none():
reg = StringRegistry()
assert reg.get("nonexistent") is None
def test_all_empty():
reg = StringRegistry()
assert reg.all() == []
def test_all_returns_all_items():
reg = StringRegistry()
reg.add("a")
reg.add("b")
reg.add("c")
items = reg.all()
assert set(items) == {"a", "b", "c"}
def test_extend():
reg = StringRegistry()
reg.extend(["x", "y", "z"])
assert reg.get("x") == "x"
assert reg.get("y") == "y"
assert reg.get("z") == "z"
assert len(reg.all()) == 3
def test_overwrite_key():
reg = StringRegistry()
reg.add("key")
reg.add("key")
assert len(reg.all()) == 1
def test_cannot_instantiate_abc_directly():
with pytest.raises(TypeError):
RegistryABC()