From a5996c4739a18a2c3a5dc68c8019df026f6d8717 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 13 Oct 2025 09:11:43 +0200 Subject: [PATCH] LCORE-831: fixed issues found by Pyright --- tests/unit/test_llama_stack_configuration.py | 54 +++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/tests/unit/test_llama_stack_configuration.py b/tests/unit/test_llama_stack_configuration.py index 52271afd..cd396077 100644 --- a/tests/unit/test_llama_stack_configuration.py +++ b/tests/unit/test_llama_stack_configuration.py @@ -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, @@ -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 @@ -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] == { @@ -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) @@ -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) @@ -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 @@ -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] == { @@ -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) @@ -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) @@ -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 @@ -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: @@ -325,7 +329,7 @@ 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 @@ -333,7 +337,7 @@ def test_generate_configuration_proper_input_file_no_byok(tmpdir: Path) -> 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) @@ -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 @@ -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)