forked from OpenHands/OpenHands
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_cli_default_model.py
More file actions
79 lines (68 loc) · 2.46 KB
/
test_cli_default_model.py
File metadata and controls
79 lines (68 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from openhands.cli.settings import modify_llm_settings_basic
from openhands.cli.utils import VERIFIED_ANTHROPIC_MODELS
@pytest.mark.asyncio
@patch('openhands.cli.settings.get_supported_llm_models')
@patch('openhands.cli.settings.organize_models_and_providers')
@patch('openhands.cli.settings.PromptSession')
@patch('openhands.cli.settings.cli_confirm')
@patch('openhands.cli.settings.print_formatted_text')
async def test_anthropic_default_model_is_best_verified(
mock_print,
mock_confirm,
mock_session,
mock_organize,
mock_get_models,
):
"""Test that the default model for anthropic is the best verified model."""
# Setup mocks
mock_get_models.return_value = [
'anthropic/claude-sonnet-4-20250514',
'anthropic/claude-2',
]
mock_organize.return_value = {
'anthropic': {
'models': ['claude-sonnet-4-20250514', 'claude-2'],
'separator': '/',
},
}
# Mock session to avoid actual user input
session_instance = MagicMock()
session_instance.prompt_async = AsyncMock(side_effect=KeyboardInterrupt())
mock_session.return_value = session_instance
# Mock config and settings store
app_config = MagicMock()
llm_config = MagicMock()
app_config.get_llm_config.return_value = llm_config
settings_store = AsyncMock()
# Mock cli_confirm to avoid actual user input
# We need enough values to handle all the calls in the function
mock_confirm.side_effect = [
0,
0,
0,
] # Use default provider, use default model, etc.
try:
# Call the function (it will exit early due to KeyboardInterrupt)
await modify_llm_settings_basic(app_config, settings_store)
except KeyboardInterrupt:
pass # Expected exception
# Check that the default model displayed is the best verified model
best_verified_model = VERIFIED_ANTHROPIC_MODELS[
0
] # First model in the list is the best
default_model_displayed = False
for call in mock_print.call_args_list:
args, _ = call
if (
args
and hasattr(args[0], 'value')
and f'Default model: </grey><green>{best_verified_model}</green>'
in args[0].value
):
default_model_displayed = True
break
assert default_model_displayed, (
f'Default model displayed was not {best_verified_model}'
)