test: add pytest verification suite and gitea ci workflow
All checks were successful
CI / test (push) Successful in 48s
All checks were successful
CI / test (push) Successful in 48s
This commit is contained in:
32
tests/test_pricing.py
Normal file
32
tests/test_pricing.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from src.models import UsageSummary
|
||||
from src.pricing import estimate_cost_usd, normalize_model_for_pricing
|
||||
|
||||
|
||||
def test_normalize_model_for_pricing() -> None:
|
||||
assert normalize_model_for_pricing("gpt-5.4-mini") == "gpt-5.4-mini"
|
||||
assert normalize_model_for_pricing("gpt-5.4-mini-2026-05-01") == "gpt-5.4-mini"
|
||||
assert normalize_model_for_pricing("unknown-model") == "unknown-model"
|
||||
|
||||
|
||||
def test_estimate_cost_with_cached_tokens() -> None:
|
||||
usage = UsageSummary(
|
||||
input_tokens=100_000,
|
||||
cached_input_tokens=20_000,
|
||||
output_tokens=50_000,
|
||||
total_tokens=150_000,
|
||||
)
|
||||
cost, model = estimate_cost_usd("gpt-5.4-mini", usage)
|
||||
assert model == "gpt-5.4-mini"
|
||||
assert cost is not None
|
||||
# Non-cached input: 80k at $0.75/M = 0.06
|
||||
# Cached input: 20k at $0.075/M = 0.0015
|
||||
# Output: 50k at $4.50/M = 0.225
|
||||
assert abs(cost - 0.2865) < 1e-9
|
||||
|
||||
|
||||
def test_estimate_cost_unknown_model_returns_none() -> None:
|
||||
usage = UsageSummary(input_tokens=10, output_tokens=10)
|
||||
cost, model = estimate_cost_usd("my-new-model", usage)
|
||||
assert model == "my-new-model"
|
||||
assert cost is None
|
||||
|
||||
Reference in New Issue
Block a user