refactor!: a lot of stuff
This commit is contained in:
parent
d6396e4050
commit
0af7179596
15 changed files with 663 additions and 302 deletions
32
tests/test_usage_unit.py
Normal file
32
tests/test_usage_unit.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue