81 lines
3.2 KiB
Python
81 lines
3.2 KiB
Python
"""QA for Objective.credit_attenuation config block."""
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from config import (
|
|
CreditAttenuationConfig,
|
|
Objective,
|
|
RouterConfig,
|
|
load_config,
|
|
)
|
|
|
|
|
|
CONFIG_PATH = Path("config/config.yaml")
|
|
|
|
class TestCreditAttenuationConfigDefaults:
|
|
def test_default_constructed_disabled(self):
|
|
"""(a) Objective() default constructs with credit_attenuation disabled."""
|
|
obj = Objective()
|
|
assert obj.credit_attenuation.enabled is False
|
|
assert obj.credit_attenuation.soft_floor_usd == 5.0
|
|
assert obj.credit_attenuation.zero_floor_usd == 0.0
|
|
assert obj.credit_attenuation.max_multiplier == 5.0
|
|
assert obj.credit_attenuation.refresh_seconds == 300
|
|
|
|
|
|
class TestCreditAttenuationValidators:
|
|
def test_zero_floor_eq_soft_floor_rejected(self):
|
|
"""(b) zero_floor_usd == soft_floor_usd raises."""
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
CreditAttenuationConfig(soft_floor_usd=5.0, zero_floor_usd=5.0)
|
|
assert "zero_floor_usd" in str(exc_info.value)
|
|
assert "soft_floor_usd" in str(exc_info.value)
|
|
|
|
def test_max_multiplier_not_above_one_rejected(self):
|
|
"""(c) max_multiplier=1.0 raises."""
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
CreditAttenuationConfig(max_multiplier=1.0)
|
|
assert "max_multiplier" in str(exc_info.value)
|
|
|
|
def test_refresh_seconds_zero_rejected(self):
|
|
"""(d) refresh_seconds=0 raises."""
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
CreditAttenuationConfig(refresh_seconds=0)
|
|
assert "refresh_seconds" in str(exc_info.value)
|
|
|
|
def test_soft_floor_zero_rejected(self):
|
|
"""(e) soft_floor_usd=0 raises."""
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
CreditAttenuationConfig(soft_floor_usd=0.0)
|
|
assert "soft_floor_usd" in str(exc_info.value)
|
|
|
|
def test_zero_floor_negative_rejected(self):
|
|
"""(f) zero_floor_usd<0 raises."""
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
CreditAttenuationConfig(zero_floor_usd=-1.0)
|
|
assert "zero_floor_usd" in str(exc_info.value)
|
|
|
|
|
|
class TestCreditAttenuationRealConfig:
|
|
def test_real_config_has_attenuation_disabled(self):
|
|
"""(g) real load_config returns credit_attenuation.enabled False."""
|
|
cfg = load_config(Path("config/config.yaml"))
|
|
assert cfg.objective.credit_attenuation.enabled is False
|
|
assert cfg.objective.credit_attenuation.soft_floor_usd == 5.0
|
|
assert cfg.objective.credit_attenuation.zero_floor_usd == 0.0
|
|
assert cfg.objective.credit_attenuation.max_multiplier == 5.0
|
|
assert cfg.objective.credit_attenuation.refresh_seconds == 300
|
|
|
|
|
|
class TestCreditAttenuationExtraForbid:
|
|
def test_unknown_key_inside_block_raises(self):
|
|
"""(h) unknown key inside credit_attenuation raises via extra-forbid."""
|
|
raw = load_config(CONFIG_PATH).model_dump()
|
|
raw["objective"]["credit_attenuation"]["hard_floor_usd"] = 1.0
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
RouterConfig(**raw)
|
|
assert "hard_floor_usd" in str(exc_info.value)
|