Add moonshotai/kimi-k3 as OpenRouter basemodel default after live smoke, USD→EUR cost conversion, append-only usage ledger, and CLI run/cost/spend week commands with token and euro reporting.
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
import pytest
|
|
|
|
from llm_connect.fx import DEFAULT_EUR_PER_USD, FxRate, resolve_fx_rate
|
|
|
|
|
|
def test_resolve_fx_prefers_explicit_rate():
|
|
rate = resolve_fx_rate(0.85)
|
|
|
|
assert rate is not None
|
|
assert rate.eur_per_usd == pytest.approx(0.85)
|
|
assert rate.source == "explicit"
|
|
assert rate.usd_to_eur(10.0) == pytest.approx(8.5)
|
|
|
|
|
|
def test_resolve_fx_reads_env(monkeypatch):
|
|
monkeypatch.setenv("LLM_CONNECT_EUR_PER_USD", "0.9")
|
|
|
|
rate = resolve_fx_rate()
|
|
|
|
assert rate is not None
|
|
assert rate.eur_per_usd == pytest.approx(0.9)
|
|
assert rate.source == "env:LLM_CONNECT_EUR_PER_USD"
|
|
|
|
|
|
def test_resolve_fx_falls_back_to_snapshot():
|
|
rate = resolve_fx_rate(env={})
|
|
|
|
assert rate is not None
|
|
assert rate.eur_per_usd == pytest.approx(DEFAULT_EUR_PER_USD)
|
|
assert rate.source.startswith("snapshot:")
|
|
|
|
|
|
def test_invalid_env_rate_raises():
|
|
with pytest.raises(ValueError, match="LLM_CONNECT_EUR_PER_USD"):
|
|
resolve_fx_rate(env={"LLM_CONNECT_EUR_PER_USD": "0"})
|
|
|
|
|
|
def test_fx_rate_rejects_non_positive():
|
|
with pytest.raises(ValueError, match="eur_per_usd"):
|
|
FxRate(eur_per_usd=-1, source="x")
|