Skip to content

Commit edfbb37

Browse files
committed
More refactoring
1 parent 455f613 commit edfbb37

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

tests/unit/metrics/test_utis.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Unit tests for functions defined in metrics/utils.py"""
22

3+
from pytest_mock import MockerFixture
34
from metrics.utils import setup_model_metrics, update_llm_token_count_from_turn
45

56

6-
async def test_setup_model_metrics(mocker) -> None:
7+
async def test_setup_model_metrics(mocker: MockerFixture) -> None:
78
"""Test the setup_model_metrics function."""
89

910
# Mock the LlamaStackAsLibraryClient
@@ -76,7 +77,7 @@ async def test_setup_model_metrics(mocker) -> None:
7677
)
7778

7879

79-
def test_update_llm_token_count_from_turn(mocker) -> None:
80+
def test_update_llm_token_count_from_turn(mocker: MockerFixture) -> None:
8081
"""Test the update_llm_token_count_from_turn function."""
8182
mocker.patch("metrics.utils.Tokenizer.get_instance")
8283
mock_formatter_class = mocker.patch("metrics.utils.ChatFormat")

tests/unit/utils/auth_helpers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Helper functions for mocking authorization in tests."""
22

3-
from typing import Any
43
from unittest.mock import AsyncMock, Mock
54
from pytest_mock import MockerFixture
65

tests/unit/utils/test_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Test module for utils/common.py."""
22

33
from unittest.mock import Mock, AsyncMock
4-
from pytest_mock import MockerFixture
54
from logging import Logger
5+
from pytest_mock import MockerFixture
66

77
import pytest
88

tests/unit/utils/test_endpoints.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import pytest
5+
from pytest_mock import MockerFixture
56
from fastapi import HTTPException
67
from pydantic import AnyUrl
78

@@ -245,7 +246,9 @@ def test_get_profile_prompt_with_enabled_query_system_prompt(
245246

246247

247248
@pytest.mark.asyncio
248-
async def test_get_agent_with_conversation_id(prepare_agent_mocks, mocker):
249+
async def test_get_agent_with_conversation_id(
250+
prepare_agent_mocks, mocker: MockerFixture
251+
):
249252
"""Test get_agent function when agent exists in llama stack."""
250253
mock_client, mock_agent = prepare_agent_mocks
251254
conversation_id = "test_conversation_id"
@@ -664,7 +667,9 @@ async def test_get_agent_no_tools_false_preserves_parser(
664667

665668

666669
@pytest.mark.asyncio
667-
async def test_get_temp_agent_basic_functionality(prepare_agent_mocks, mocker):
670+
async def test_get_temp_agent_basic_functionality(
671+
prepare_agent_mocks, mocker: MockerFixture
672+
):
668673
"""Test get_temp_agent function creates agent with correct parameters."""
669674
mock_client, mock_agent = prepare_agent_mocks
670675
mock_agent.create_session.return_value = "temp_session_id"
@@ -703,7 +708,9 @@ async def test_get_temp_agent_basic_functionality(prepare_agent_mocks, mocker):
703708

704709

705710
@pytest.mark.asyncio
706-
async def test_get_temp_agent_returns_valid_ids(prepare_agent_mocks, mocker):
711+
async def test_get_temp_agent_returns_valid_ids(
712+
prepare_agent_mocks, mocker: MockerFixture
713+
):
707714
"""Test get_temp_agent function returns valid agent_id and session_id."""
708715
mock_client, mock_agent = prepare_agent_mocks
709716
mock_agent.agent_id = "generated_agent_id"
@@ -736,7 +743,9 @@ async def test_get_temp_agent_returns_valid_ids(prepare_agent_mocks, mocker):
736743

737744

738745
@pytest.mark.asyncio
739-
async def test_get_temp_agent_no_persistence(prepare_agent_mocks, mocker):
746+
async def test_get_temp_agent_no_persistence(
747+
prepare_agent_mocks, mocker: MockerFixture
748+
):
740749
"""Test get_temp_agent function creates agent without session persistence."""
741750
mock_client, mock_agent = prepare_agent_mocks
742751
mock_agent.create_session.return_value = "temp_session_id"
@@ -818,7 +827,9 @@ def test_get_topic_summary_system_prompt_with_custom_profile():
818827
assert topic_summary_prompt == prompts.get("topic_summary")
819828

820829

821-
def test_get_topic_summary_system_prompt_with_custom_profile_no_topic_summary(mocker):
830+
def test_get_topic_summary_system_prompt_with_custom_profile_no_topic_summary(
831+
mocker: MockerFixture,
832+
):
822833
"""Test that default topic summary prompt is returned when custom profile has
823834
no topic_summary prompt.
824835
"""

tests/unit/utils/test_llama_stack_version.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44
from semver import Version
5+
from pytest_mock import MockerFixture
56

67
from llama_stack_client.types import VersionInfo
78

@@ -17,7 +18,7 @@
1718

1819

1920
@pytest.mark.asyncio
20-
async def test_check_llama_stack_version_minimal_supported_version(mocker):
21+
async def test_check_llama_stack_version_minimal_supported_version(mocker: MockerFixture):
2122
"""Test the check_llama_stack_version function."""
2223

2324
# mock the Llama Stack client
@@ -31,7 +32,7 @@ async def test_check_llama_stack_version_minimal_supported_version(mocker):
3132

3233

3334
@pytest.mark.asyncio
34-
async def test_check_llama_stack_version_maximal_supported_version(mocker):
35+
async def test_check_llama_stack_version_maximal_supported_version(mocker: MockerFixture):
3536
"""Test the check_llama_stack_version function."""
3637

3738
# mock the Llama Stack client
@@ -45,7 +46,7 @@ async def test_check_llama_stack_version_maximal_supported_version(mocker):
4546

4647

4748
@pytest.mark.asyncio
48-
async def test_check_llama_stack_version_too_small_version(mocker):
49+
async def test_check_llama_stack_version_too_small_version(mocker: MockerFixture):
4950
"""Test the check_llama_stack_version function."""
5051

5152
# mock the Llama Stack client

0 commit comments

Comments
 (0)