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>
93 lines
2.3 KiB
Python
93 lines
2.3 KiB
Python
import os
|
|
import pytest
|
|
from cpl.core.environment.environment import Environment
|
|
from cpl.core.environment.environment_enum import EnvironmentEnum
|
|
|
|
|
|
def test_set_and_get_environment_valid():
|
|
for env in EnvironmentEnum:
|
|
Environment.set_environment(env.value)
|
|
assert Environment.get_environment() == env.value
|
|
|
|
|
|
def test_set_environment_invalid():
|
|
with pytest.raises(AssertionError):
|
|
Environment.set_environment("invalid_env")
|
|
|
|
|
|
def test_set_environment_empty():
|
|
with pytest.raises(AssertionError):
|
|
Environment.set_environment("")
|
|
|
|
|
|
def test_set_environment_none():
|
|
with pytest.raises(AssertionError):
|
|
Environment.set_environment(None)
|
|
|
|
|
|
def test_set_and_get_app_name():
|
|
Environment.set_app_name("TestApp")
|
|
assert Environment.get_app_name() == "TestApp"
|
|
|
|
|
|
def test_get_host_name():
|
|
hostname = Environment.get_host_name()
|
|
assert isinstance(hostname, str)
|
|
assert len(hostname) > 0
|
|
|
|
|
|
def test_get_cwd():
|
|
cwd = Environment.get_cwd()
|
|
assert isinstance(cwd, str)
|
|
assert os.path.isdir(cwd)
|
|
|
|
|
|
def test_set_cwd(tmp_path):
|
|
original = Environment.get_cwd()
|
|
Environment.set_cwd(str(tmp_path))
|
|
assert Environment.get_cwd() == str(tmp_path)
|
|
Environment.set_cwd(original)
|
|
|
|
|
|
def test_set_cwd_empty():
|
|
with pytest.raises(AssertionError):
|
|
Environment.set_cwd("")
|
|
|
|
|
|
def test_set_cwd_none():
|
|
with pytest.raises(AssertionError):
|
|
Environment.set_cwd(None)
|
|
|
|
|
|
def test_set_and_get_generic():
|
|
Environment.set("CPL_TEST_KEY", "hello")
|
|
assert Environment.get("CPL_TEST_KEY", str) == "hello"
|
|
|
|
|
|
def test_get_missing_key_returns_default():
|
|
result = Environment.get("CPL_NONEXISTENT_KEY_XYZ", str, "default_value")
|
|
assert result == "default_value"
|
|
|
|
|
|
def test_get_missing_key_returns_none():
|
|
result = Environment.get("CPL_NONEXISTENT_KEY_XYZ2", str)
|
|
assert result is None
|
|
|
|
|
|
def test_set_key_empty():
|
|
with pytest.raises(AssertionError):
|
|
Environment.set("", "value")
|
|
|
|
|
|
def test_set_key_none():
|
|
with pytest.raises(AssertionError):
|
|
Environment.set(None, "value")
|
|
|
|
|
|
def test_environment_enum_values():
|
|
values = [e.value for e in EnvironmentEnum]
|
|
assert "production" in values
|
|
assert "staging" in values
|
|
assert "testing" in values
|
|
assert "development" in values
|