32 lines
762 B
Python
32 lines
762 B
Python
from providers.chatgpt.usage import _parse_window, clamp_percent
|
|
|
|
|
|
def test_clamp_percent_bounds():
|
|
assert clamp_percent(-1) == 0
|
|
assert clamp_percent(150) == 100
|
|
assert clamp_percent(49.6) == 50
|
|
|
|
|
|
def test_clamp_percent_invalid():
|
|
assert clamp_percent(None) == 0
|
|
assert clamp_percent("bad") == 0
|
|
|
|
|
|
def test_parse_window_valid():
|
|
window = {
|
|
"used_percent": 34.4,
|
|
"limit_window_seconds": 3600,
|
|
"reset_after_seconds": 120,
|
|
"reset_at": 999,
|
|
}
|
|
parsed = _parse_window(window)
|
|
assert parsed == {
|
|
"used_percent": 34,
|
|
"limit_window_seconds": 3600,
|
|
"reset_after_seconds": 120,
|
|
"reset_at": 999,
|
|
}
|
|
|
|
|
|
def test_parse_window_none():
|
|
assert _parse_window(None) is None
|