Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 29 additions & 25 deletions tests/unit/test_llama_stack_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

from pathlib import Path

from typing import Any

import pytest
import yaml

from pydantic import SecretStr

from models.config import (
ByokRag,
Configuration,
Expand All @@ -27,8 +31,8 @@

def test_construct_vector_dbs_section_init() -> None:
"""Test the function construct_vector_dbs_section for no vector_dbs configured before."""
ls_config = {}
byok_rag = []
ls_config: dict[str, Any] = {}
byok_rag: list[ByokRag] = []
output = construct_vector_dbs_section(ls_config, byok_rag)
assert len(output) == 0

Expand All @@ -51,7 +55,7 @@ def test_construct_vector_dbs_section_init_with_existing_data() -> None:
},
]
}
byok_rag = []
byok_rag: list[ByokRag] = []
output = construct_vector_dbs_section(ls_config, byok_rag)
assert len(output) == 2
assert output[0] == {
Expand All @@ -70,17 +74,17 @@ def test_construct_vector_dbs_section_init_with_existing_data() -> None:

def test_construct_vector_dbs_section_append() -> None:
"""Test the function construct_vector_dbs_section for no vector_dbs configured before."""
ls_config = {}
byok_rag = [
ls_config: dict[str, Any] = {}
byok_rag: list[ByokRag] = [
ByokRag(
rag_id="rag_id_1",
vector_db_id="vector_db_id_1",
db_path="tests/configuration/rag.txt",
db_path=Path("tests/configuration/rag.txt"),
),
ByokRag(
rag_id="rag_id_2",
vector_db_id="vector_db_id_2",
db_path="tests/configuration/rag.txt",
db_path=Path("tests/configuration/rag.txt"),
),
]
output = construct_vector_dbs_section(ls_config, byok_rag)
Expand Down Expand Up @@ -121,12 +125,12 @@ def test_construct_vector_dbs_section_full_merge() -> None:
ByokRag(
rag_id="rag_id_1",
vector_db_id="vector_db_id_1",
db_path="tests/configuration/rag.txt",
db_path=Path("tests/configuration/rag.txt"),
),
ByokRag(
rag_id="rag_id_2",
vector_db_id="vector_db_id_2",
db_path="tests/configuration/rag.txt",
db_path=Path("tests/configuration/rag.txt"),
),
]
output = construct_vector_dbs_section(ls_config, byok_rag)
Expand Down Expand Up @@ -159,8 +163,8 @@ def test_construct_vector_dbs_section_full_merge() -> None:

def test_construct_vector_io_providers_section_init() -> None:
"""Test construct_vector_io_providers_section for no vector_io_providers configured before."""
ls_config = {"providers": {}}
byok_rag = []
ls_config: dict[str, Any] = {"providers": {}}
byok_rag: list[ByokRag] = []
output = construct_vector_io_providers_section(ls_config, byok_rag)
assert len(output) == 0

Expand All @@ -181,7 +185,7 @@ def test_construct_vector_io_providers_section_init_with_existing_data() -> None
]
}
}
byok_rag = []
byok_rag: list[ByokRag] = []
output = construct_vector_io_providers_section(ls_config, byok_rag)
assert len(output) == 2
assert output[0] == {
Expand All @@ -196,17 +200,17 @@ def test_construct_vector_io_providers_section_init_with_existing_data() -> None

def test_construct_vector_io_providers_section_append() -> None:
"""Test construct_vector_io_providers_section for no vector_io_providers configured before."""
ls_config = {"providers": {}}
ls_config: dict[str, Any] = {"providers": {}}
byok_rag = [
ByokRag(
rag_id="rag_id_1",
vector_db_id="vector_db_id_1",
db_path="tests/configuration/rag.txt",
db_path=Path("tests/configuration/rag.txt"),
),
ByokRag(
rag_id="rag_id_2",
vector_db_id="vector_db_id_2",
db_path="tests/configuration/rag.txt",
db_path=Path("tests/configuration/rag.txt"),
),
]
output = construct_vector_io_providers_section(ls_config, byok_rag)
Expand Down Expand Up @@ -255,12 +259,12 @@ def test_construct_vector_io_providers_section_full_merge() -> None:
ByokRag(
rag_id="rag_id_1",
vector_db_id="vector_db_id_1",
db_path="tests/configuration/rag.txt",
db_path=Path("tests/configuration/rag.txt"),
),
ByokRag(
rag_id="rag_id_2",
vector_db_id="vector_db_id_2",
db_path="tests/configuration/rag.txt",
db_path=Path("tests/configuration/rag.txt"),
),
]
output = construct_vector_io_providers_section(ls_config, byok_rag)
Expand Down Expand Up @@ -305,7 +309,7 @@ def test_generate_configuration_no_input_file(tmpdir: Path) -> None:
llama_stack=LlamaStackConfiguration(
use_as_library_client=True,
library_client_config_path="tests/configuration/run.yaml",
api_key="whatever",
api_key=SecretStr("whatever"),
),
user_data_collection=UserDataCollection(
feedback_enabled=False, feedback_storage=None
Expand All @@ -314,7 +318,7 @@ def test_generate_configuration_no_input_file(tmpdir: Path) -> None:
outfile = tmpdir / "run.xml"
# try to generate new configuration file
with pytest.raises(FileNotFoundError, match="No such file"):
generate_configuration("/does/not/exist", outfile, cfg)
generate_configuration("/does/not/exist", str(outfile), cfg)


def test_generate_configuration_proper_input_file_no_byok(tmpdir: Path) -> None:
Expand All @@ -325,15 +329,15 @@ def test_generate_configuration_proper_input_file_no_byok(tmpdir: Path) -> None:
llama_stack=LlamaStackConfiguration(
use_as_library_client=True,
library_client_config_path="tests/configuration/run.yaml",
api_key="whatever",
api_key=SecretStr("whatever"),
),
user_data_collection=UserDataCollection(
feedback_enabled=False, feedback_storage=None
),
)
outfile = tmpdir / "run.xml"
# try to generate new configuration file
generate_configuration("tests/configuration/run.yaml", outfile, cfg)
generate_configuration("tests/configuration/run.yaml", str(outfile), cfg)

with open(outfile, "r", encoding="utf-8") as fin:
generated = yaml.safe_load(fin)
Expand All @@ -350,7 +354,7 @@ def test_generate_configuration_proper_input_file_configured_byok(tmpdir: Path)
llama_stack=LlamaStackConfiguration(
use_as_library_client=True,
library_client_config_path="tests/configuration/run.yaml",
api_key="whatever",
api_key=SecretStr("whatever"),
),
user_data_collection=UserDataCollection(
feedback_enabled=False, feedback_storage=None
Expand All @@ -359,18 +363,18 @@ def test_generate_configuration_proper_input_file_configured_byok(tmpdir: Path)
ByokRag(
rag_id="rag_id_1",
vector_db_id="vector_db_id_1",
db_path="tests/configuration/rag.txt",
db_path=Path("tests/configuration/rag.txt"),
),
ByokRag(
rag_id="rag_id_2",
vector_db_id="vector_db_id_2",
db_path="tests/configuration/rag.txt",
db_path=Path("tests/configuration/rag.txt"),
),
],
)
outfile = tmpdir / "run.xml"
# try to generate new configuration file
generate_configuration("tests/configuration/run.yaml", outfile, cfg)
generate_configuration("tests/configuration/run.yaml", str(outfile), cfg)

with open(outfile, "r", encoding="utf-8") as fin:
generated = yaml.safe_load(fin)
Expand Down
Loading