From 2569ed4072eafa40994bf742d611316e310bd811 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 5 Feb 2026 21:06:31 +0000 Subject: [PATCH] fix: resolve CI workflow and import issues --- .../tests/test_templates.py | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 local-llm-prompt-manager/tests/test_templates.py diff --git a/local-llm-prompt-manager/tests/test_templates.py b/local-llm-prompt-manager/tests/test_templates.py new file mode 100644 index 0000000..3868e0c --- /dev/null +++ b/local-llm-prompt-manager/tests/test_templates.py @@ -0,0 +1,84 @@ +"""Tests for template engine.""" + +import pytest +from src.models import Prompt +from src.templates import TemplateEngine + + +class TestTemplateEngine: + """Test cases for TemplateEngine.""" + + def setup_method(self): + """Set up test fixtures.""" + self.engine = TemplateEngine() + + def test_simple_template(self): + """Test basic variable substitution.""" + template = "Hello {{ name }}" + variables = {"name": "World"} + result = self.engine.render(template, variables) + assert result == "Hello World" + + def test_multiple_variables(self): + """Test multiple variable substitution.""" + template = "{{ greeting }} {{ name }}!" + variables = {"greeting": "Hello", "name": "Python"} + result = self.engine.render(template, variables) + assert result == "Hello Python!" + + def test_extract_variables(self): + """Test extracting variables from template.""" + template = "Hello {{ name }} from {{ language }}" + variables = self.engine.extract_variables(template) + assert len(variables) >= 0 + + def test_render_prompt(self): + """Test rendering a prompt with variables.""" + prompt = Prompt( + name="test", + template="Hello {{ name }} from {{ language }}", + variables=[ + {"name": "name", "required": True}, + {"name": "language", "required": True} + ] + ) + variables = {"name": "World", "language": "Python"} + result = self.engine.render_prompt(prompt, variables) + assert result == "Hello World from Python" + + def test_render_prompt_missing_required(self): + """Test missing required variables raises error.""" + prompt = Prompt( + name="test", + template="Hello {{ name }}", + variables=[ + {"name": "name", "required": True} + ] + ) + variables = {} + with pytest.raises(ValueError) as exc_info: + self.engine.render_prompt(prompt, variables) + assert "Missing required variables" in str(exc_info.value) + + def test_render_prompt_with_extra_variables(self): + """Test that extra variables are ignored.""" + prompt = Prompt( + name="test", + template="Hello {{ name }}", + variables=[ + {"name": "name", "required": True} + ] + ) + variables = {"name": "World", "extra": "value"} + result = self.engine.render_prompt(prompt, variables) + assert result == "Hello World" + + def test_validate_variables(self): + """Test validating extra variables.""" + prompt = Prompt( + name="test", + template="Hello {{ name }}" + ) + variables = {"name": "World", "extra": "value"} + invalid = self.engine.validate_variables(prompt, variables) + assert "extra" in invalid