test: convert tests to use show

Signed-off-by: Charlie Doern <cdoern@redhat.com>
This commit is contained in:
Charlie Doern 2025-07-31 20:14:37 -04:00
parent 2584c73295
commit 26a490b7fc
16 changed files with 177 additions and 239 deletions

View file

@ -1,40 +0,0 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.
from pathlib import Path
from llama_stack.cli.stack._sync import (
_run_stack_build_command_from_build_config,
)
from llama_stack.core.datatypes import BuildConfig, DistributionSpec
from llama_stack.core.utils.image_types import LlamaStackImageType
def test_container_build_passes_path(monkeypatch, tmp_path):
called_with = {}
def spy_build_image(build_config, image_name, distro_or_config, run_config=None):
called_with["path"] = distro_or_config
called_with["run_config"] = run_config
return 0
monkeypatch.setattr(
"llama_stack.cli.stack._build.build_image",
spy_build_image,
raising=True,
)
cfg = BuildConfig(
image_type=LlamaStackImageType.CONTAINER.value,
distribution_spec=DistributionSpec(providers={}, description=""),
)
_run_stack_build_command_from_build_config(cfg, image_name="dummy")
assert "path" in called_with
assert isinstance(called_with["path"], str)
assert Path(called_with["path"]).exists()
assert called_with["run_config"] is None

View file

@ -0,0 +1,45 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.
import argparse
from io import StringIO
from unittest.mock import patch
from llama_stack.cli.stack._show import (
run_stack_show_command,
)
def test_stack_show_basic():
args = argparse.Namespace(
config=None,
distro=None,
env_name="test-env",
providers="inference=remote::ollama",
)
with patch("sys.stdout", new_callable=StringIO) as mock_stdout:
run_stack_show_command(args)
output = mock_stdout.getvalue()
assert "# Dependencies for test-env" in output
assert "uv pip install" in output
def test_stack_show_with_distro():
args = argparse.Namespace(
config=None,
distro="starter",
env_name=None,
providers=None,
)
with patch("sys.stdout", new_callable=StringIO) as mock_stdout:
run_stack_show_command(args)
output = mock_stdout.getvalue()
assert "# Dependencies for starter" in output
assert "uv pip install" in output