From f6e224ea525d566e35ef873627f1be8bd0f16511 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Thu, 22 May 2025 08:44:00 +0200 Subject: [PATCH] Unit tests for models config --- tests/unit/models/__init__.py | 1 + tests/unit/models/test_config.py | 51 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tests/unit/models/__init__.py create mode 100644 tests/unit/models/test_config.py diff --git a/tests/unit/models/__init__.py b/tests/unit/models/__init__.py new file mode 100644 index 00000000..4f156ea4 --- /dev/null +++ b/tests/unit/models/__init__.py @@ -0,0 +1 @@ +"""Unit tests for models.""" diff --git a/tests/unit/models/test_config.py b/tests/unit/models/test_config.py new file mode 100644 index 00000000..9cf6a949 --- /dev/null +++ b/tests/unit/models/test_config.py @@ -0,0 +1,51 @@ +"""Unit tests for functions defined in src/models/config.py.""" + +import pytest + +from models.config import Configuration, LLamaStackConfiguration + + +def test_llama_stack_configuration_constructor(): + """Test the LLamaStackConfiguration constructor.""" + l = LLamaStackConfiguration( + use_as_library_client=True, library_client_config_path="foo" + ) + assert l is not None + + l = LLamaStackConfiguration(use_as_library_client=False, url="http://localhost") + assert l is not None + + l = LLamaStackConfiguration(url="http://localhost") + assert l is not None + + l = LLamaStackConfiguration( + use_as_library_client=False, url="http://localhost", api_key="foo" + ) + assert l is not None + + +def test_llama_stack_wrong_configuration_constructor_no_url(): + """Test the LLamaStackConfiguration constructor.""" + with pytest.raises( + ValueError, + match="LLama stack URL is not specified and library client mode is not specified", + ): + LLamaStackConfiguration() + + +def test_llama_stack_wrong_configuration_constructor_library_mode_off(): + """Test the LLamaStackConfiguration constructor.""" + with pytest.raises( + ValueError, + match="LLama stack URL is not specified and library client mode is not enabled", + ): + LLamaStackConfiguration(use_as_library_client=False) + + +def test_llama_stack_wrong_configuration_no_config_file(): + """Test the LLamaStackConfiguration constructor.""" + with pytest.raises( + ValueError, + match="LLama stack library client mode is enabled but a configuration file path is not specified", + ): + LLamaStackConfiguration(use_as_library_client=True)