From 7ef6757d28f568e56653b3d2f3564972971dc5bd Mon Sep 17 00:00:00 2001 From: spions Date: Mon, 31 Aug 2026 16:55:21 +0300 Subject: [PATCH] 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. --- .../test_litellm_logging.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py index 614904921dc..a2914a8a159 100644 --- a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py +++ b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py @@ -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