forked from retoor/devplacepy
38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
# retoor <retoor@molodetz.nl>
|
|||
|
|
|
||
|
|
from devplacepy.services.openai_gateway import model_stats_query as msq
|
||
|
|
|
||
|
|
|
||
|
|
def test_bucket_seconds_has_a_floor():
|
||
|
|
assert msq._bucket_seconds(60) == 60
|
||
|
|
assert msq._bucket_seconds(3600) == 60
|
||
|
|
|
||
|
|
|
||
|
|
def test_bucket_seconds_scales_with_range():
|
||
|
|
week = 7 * 86400
|
||
|
|
assert msq._bucket_seconds(week) == week // 120
|
||
|
|
|
||
|
|
|
||
|
|
def test_histogram_places_values_in_the_right_bucket():
|
||
|
|
edges = (10, 20)
|
||
|
|
labels = ("low", "mid", "high")
|
||
|
|
result = msq._histogram([5, 15, 25, 9.999, 20], edges, labels)
|
||
|
|
counts = {row["label"]: row["count"] for row in result}
|
||
|
|
assert counts == {"low": 2, "mid": 1, "high": 2}
|
||
|
|
|
||
|
|
|
||
|
|
def test_histogram_empty_input_is_all_zero():
|
||
|
|
result = msq._histogram([], (200, 500), ("a", "b", "c"))
|
||
|
|
assert all(row["count"] == 0 for row in result)
|
||
|
|
|
||
|
|
|
||
|
|
def test_resolve_range_rejects_unknown_key():
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
with pytest.raises(ValueError):
|
||
|
|
msq._resolve_range("not-a-real-range")
|
||
|
|
|
||
|
|
|
||
|
|
def test_resolve_range_known_key():
|
||
|
|
assert msq._resolve_range("24h") == msq.RANGE_SECONDS["24h"]
|