test(core): add unit tests for untested core modules
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:
0
test/core/abc/__init__.py
Normal file
0
test/core/abc/__init__.py
Normal file
66
test/core/abc/registry_abc_test.py
Normal file
66
test/core/abc/registry_abc_test.py
Normal 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()
|
||||
Reference in New Issue
Block a user