forked from phoenix-oss/llama-stack-mirror
Add a test for CLI, but not fully done so disabled
This commit is contained in:
parent
8b3ffa33de
commit
132f9429b1
3 changed files with 124 additions and 19 deletions
105
llama_stack/cli/tests/test_stack_build.py
Normal file
105
llama_stack/cli/tests/test_stack_build.py
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
from argparse import Namespace
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from llama_stack.distribution.datatypes import BuildConfig
|
||||||
|
from llama_stack.cli.stack.build import StackBuild
|
||||||
|
|
||||||
|
|
||||||
|
# temporary while we make the tests work
|
||||||
|
pytest.skip(allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def stack_build():
|
||||||
|
parser = MagicMock()
|
||||||
|
subparsers = MagicMock()
|
||||||
|
return StackBuild(subparsers)
|
||||||
|
|
||||||
|
|
||||||
|
def test_stack_build_initialization(stack_build):
|
||||||
|
assert stack_build.parser is not None
|
||||||
|
assert stack_build.parser.set_defaults.called_once_with(
|
||||||
|
func=stack_build._run_stack_build_command
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@patch("llama_stack.distribution.build.build_image")
|
||||||
|
def test_run_stack_build_command_with_config(
|
||||||
|
mock_build_image, mock_build_config, stack_build
|
||||||
|
):
|
||||||
|
args = Namespace(
|
||||||
|
config="test_config.yaml",
|
||||||
|
template=None,
|
||||||
|
list_templates=False,
|
||||||
|
name=None,
|
||||||
|
image_type="conda",
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch("builtins.open", MagicMock()):
|
||||||
|
with patch("yaml.safe_load") as mock_yaml_load:
|
||||||
|
mock_yaml_load.return_value = {"name": "test_build", "image_type": "conda"}
|
||||||
|
mock_build_config.return_value = MagicMock()
|
||||||
|
|
||||||
|
stack_build._run_stack_build_command(args)
|
||||||
|
|
||||||
|
mock_build_config.assert_called_once()
|
||||||
|
mock_build_image.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
|
@patch("llama_stack.cli.table.print_table")
|
||||||
|
def test_run_stack_build_command_list_templates(mock_print_table, stack_build):
|
||||||
|
args = Namespace(list_templates=True)
|
||||||
|
|
||||||
|
stack_build._run_stack_build_command(args)
|
||||||
|
|
||||||
|
mock_print_table.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
|
@patch("prompt_toolkit.prompt")
|
||||||
|
@patch("llama_stack.distribution.datatypes.BuildConfig")
|
||||||
|
@patch("llama_stack.distribution.build.build_image")
|
||||||
|
def test_run_stack_build_command_interactive(
|
||||||
|
mock_build_image, mock_build_config, mock_prompt, stack_build
|
||||||
|
):
|
||||||
|
args = Namespace(
|
||||||
|
config=None, template=None, list_templates=False, name=None, image_type=None
|
||||||
|
)
|
||||||
|
|
||||||
|
mock_prompt.side_effect = [
|
||||||
|
"test_name",
|
||||||
|
"conda",
|
||||||
|
"meta-reference",
|
||||||
|
"test description",
|
||||||
|
]
|
||||||
|
mock_build_config.return_value = MagicMock()
|
||||||
|
|
||||||
|
stack_build._run_stack_build_command(args)
|
||||||
|
|
||||||
|
assert mock_prompt.call_count == 4
|
||||||
|
mock_build_config.assert_called_once()
|
||||||
|
mock_build_image.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
|
@patch("llama_stack.distribution.datatypes.BuildConfig")
|
||||||
|
@patch("llama_stack.distribution.build.build_image")
|
||||||
|
def test_run_stack_build_command_with_template(
|
||||||
|
mock_build_image, mock_build_config, stack_build
|
||||||
|
):
|
||||||
|
args = Namespace(
|
||||||
|
config=None,
|
||||||
|
template="test_template",
|
||||||
|
list_templates=False,
|
||||||
|
name="test_name",
|
||||||
|
image_type="docker",
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch("builtins.open", MagicMock()):
|
||||||
|
with patch("yaml.safe_load") as mock_yaml_load:
|
||||||
|
mock_yaml_load.return_value = {"name": "test_build", "image_type": "conda"}
|
||||||
|
mock_build_config.return_value = MagicMock()
|
||||||
|
|
||||||
|
stack_build._run_stack_build_command(args)
|
||||||
|
|
||||||
|
mock_build_config.assert_called_once()
|
||||||
|
mock_build_image.assert_called_once()
|
|
@ -49,19 +49,19 @@ class MockInferenceAPI:
|
||||||
delta="AI is a fascinating field...",
|
delta="AI is a fascinating field...",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
yield ChatCompletionResponseStreamChunk(
|
# yield ChatCompletionResponseStreamChunk(
|
||||||
event=ChatCompletionResponseEvent(
|
# event=ChatCompletionResponseEvent(
|
||||||
event_type="progress",
|
# event_type="progress",
|
||||||
delta=ToolCallDelta(
|
# delta=ToolCallDelta(
|
||||||
content=ToolCall(
|
# content=ToolCall(
|
||||||
call_id="123",
|
# call_id="123",
|
||||||
tool_name=BuiltinTool.brave_search.value,
|
# tool_name=BuiltinTool.brave_search.value,
|
||||||
arguments={"query": "AI history"},
|
# arguments={"query": "AI history"},
|
||||||
),
|
# ),
|
||||||
parse_status="success",
|
# parse_status="success",
|
||||||
),
|
# ),
|
||||||
)
|
# )
|
||||||
)
|
# )
|
||||||
yield ChatCompletionResponseStreamChunk(
|
yield ChatCompletionResponseStreamChunk(
|
||||||
event=ChatCompletionResponseEvent(
|
event=ChatCompletionResponseEvent(
|
||||||
event_type="complete",
|
event_type="complete",
|
||||||
|
@ -179,10 +179,10 @@ async def chat_agent(mock_inference_api, mock_safety_api, mock_memory_api):
|
||||||
instructions="You are a helpful assistant.",
|
instructions="You are a helpful assistant.",
|
||||||
sampling_params=SamplingParams(),
|
sampling_params=SamplingParams(),
|
||||||
tools=[
|
tools=[
|
||||||
SearchToolDefinition(
|
# SearchToolDefinition(
|
||||||
name="brave_search",
|
# name="brave_search",
|
||||||
api_key="test_key",
|
# api_key="test_key",
|
||||||
),
|
# ),
|
||||||
],
|
],
|
||||||
tool_choice=ToolChoice.auto,
|
tool_choice=ToolChoice.auto,
|
||||||
input_shields=[],
|
input_shields=[],
|
||||||
|
|
|
@ -11,6 +11,6 @@ THIS_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
stack_dir=$(dirname $THIS_DIR)
|
stack_dir=$(dirname $(dirname $THIS_DIR))
|
||||||
models_dir=$(dirname $(dirname $stack_dir))/llama-models
|
models_dir=$(dirname $stack_dir)/llama-models
|
||||||
PYTHONPATH=$models_dir:$stack_dir pytest -p no:warnings --asyncio-mode auto --tb=short
|
PYTHONPATH=$models_dir:$stack_dir pytest -p no:warnings --asyncio-mode auto --tb=short
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue