Files
screenjob/tests/test_pricing.py
Space-Banane a19b285232
All checks were successful
CI / test (push) Successful in 48s
test: add pytest verification suite and gitea ci workflow
2026-05-27 17:55:34 +02:00

33 lines
1.1 KiB
Python

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