test(logging): add direct unit test for _get_rerank_usage_from_meta

The name-based logging code-coverage gate requires every staticmethod
on StandardLoggingPayloadSetup to be called by name from a test file
whose name contains "logging". The existing rerank tests only
exercised the helper indirectly through get_usage_from_response_obj/
get_usage_as_dict.
This commit is contained in:
spions 2026-08-31 16:55:21 +03:00
parent 5d8907fc92
commit 7ef6757d28

View file

@ -4893,6 +4893,33 @@ def test_pre_call_does_not_pin_request_in_module_state(logging_obj):
assert litellm.error_logs == {}
@pytest.mark.parametrize(
"meta,expected",
[
(None, None),
({}, None),
({"billed_units": {"total_tokens": 42}, "tokens": {"input_tokens": 42}}, (42, 42)),
({"tokens": {"input_tokens": 38}}, (38, 38)),
({"billed_units": {"total_tokens": 38}}, (38, 38)),
],
)
def test_get_rerank_usage_from_meta(meta, expected):
"""Direct unit test of the helper both get_usage_from_response_obj and
get_usage_as_dict delegate to for the rerank `meta` shape."""
from litellm.litellm_core_utils.litellm_logging import StandardLoggingPayloadSetup
result = StandardLoggingPayloadSetup._get_rerank_usage_from_meta(meta)
if expected is None:
assert result is None
else:
prompt_tokens, total_tokens = expected
assert result is not None
assert result.prompt_tokens == prompt_tokens
assert result.completion_tokens == 0
assert result.total_tokens == total_tokens
def test_get_usage_from_response_obj_rerank_meta():
"""
RerankResponse has no top-level `usage` field - token usage lives under