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

View File

@@ -0,0 +1,36 @@
import pytest
from cpl.core.pipes.bool_pipe import BoolPipe
def test_to_str_true():
assert BoolPipe.to_str(True) == "true"
def test_to_str_false():
assert BoolPipe.to_str(False) == "false"
def test_from_str_true_values():
assert BoolPipe.from_str("True") is True
assert BoolPipe.from_str("true") is True
assert BoolPipe.from_str("1") is True
assert BoolPipe.from_str("yes") is True
assert BoolPipe.from_str("y") is True
assert BoolPipe.from_str("Y") is True
def test_from_str_false_values():
assert BoolPipe.from_str("false") is False
assert BoolPipe.from_str("False") is False
assert BoolPipe.from_str("0") is False
assert BoolPipe.from_str("no") is False
assert BoolPipe.from_str("") is False
assert BoolPipe.from_str("anything") is False
def test_roundtrip_true():
assert BoolPipe.from_str(BoolPipe.to_str(True)) is True
def test_roundtrip_false():
assert BoolPipe.from_str(BoolPipe.to_str(False)) is False

View File

@@ -0,0 +1,59 @@
import pytest
from cpl.core.pipes.ip_address_pipe import IPAddressPipe
def test_to_str_valid():
assert IPAddressPipe.to_str([192, 168, 1, 1]) == "192.168.1.1"
assert IPAddressPipe.to_str([0, 0, 0, 0]) == "0.0.0.0"
assert IPAddressPipe.to_str([255, 255, 255, 255]) == "255.255.255.255"
assert IPAddressPipe.to_str([127, 0, 0, 1]) == "127.0.0.1"
def test_to_str_too_few_parts():
with pytest.raises(ValueError):
IPAddressPipe.to_str([192, 168, 1])
def test_to_str_too_many_parts():
with pytest.raises(ValueError):
IPAddressPipe.to_str([192, 168, 1, 1, 5])
def test_to_str_byte_out_of_range():
with pytest.raises(ValueError):
IPAddressPipe.to_str([256, 0, 0, 0])
with pytest.raises(ValueError):
IPAddressPipe.to_str([-1, 0, 0, 0])
def test_from_str_valid():
assert IPAddressPipe.from_str("192.168.1.1") == [192, 168, 1, 1]
assert IPAddressPipe.from_str("0.0.0.0") == [0, 0, 0, 0]
assert IPAddressPipe.from_str("255.255.255.255") == [255, 255, 255, 255]
assert IPAddressPipe.from_str("127.0.0.1") == [127, 0, 0, 1]
def test_from_str_too_few_parts():
with pytest.raises(Exception):
IPAddressPipe.from_str("192.168.1")
def test_from_str_too_many_parts():
with pytest.raises(Exception):
IPAddressPipe.from_str("192.168.1.1.5")
def test_from_str_byte_out_of_range():
with pytest.raises(Exception):
IPAddressPipe.from_str("256.0.0.0")
def test_from_str_invalid_format():
with pytest.raises(Exception):
IPAddressPipe.from_str("not.an.ip.addr")
def test_roundtrip():
original = [10, 20, 30, 40]
assert IPAddressPipe.from_str(IPAddressPipe.to_str(original)) == original