Add test suite for all modules
This commit is contained in:
133
local_code_assistant/tests/test_prompts.py
Normal file
133
local_code_assistant/tests/test_prompts.py
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
"""Tests for Local Code Assistant prompt templates."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from local_code_assistant.prompts.templates import PromptTemplates, LanguageConfig
|
||||||
|
|
||||||
|
|
||||||
|
class TestPromptTemplates:
|
||||||
|
"""Tests for prompt template generation."""
|
||||||
|
|
||||||
|
def test_code_generation_prompt(self):
|
||||||
|
"""Test code generation prompt creation."""
|
||||||
|
prompt = PromptTemplates.code_generation(
|
||||||
|
language="python",
|
||||||
|
user_prompt="Create a function to add numbers"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert "python" in prompt
|
||||||
|
assert "Create a function to add numbers" in prompt
|
||||||
|
assert "Generate" in prompt
|
||||||
|
|
||||||
|
def test_code_explanation_prompt(self):
|
||||||
|
"""Test code explanation prompt creation."""
|
||||||
|
code = "def add(a, b): return a + b"
|
||||||
|
prompt = PromptTemplates.code_explanation(
|
||||||
|
language="python",
|
||||||
|
code=code
|
||||||
|
)
|
||||||
|
|
||||||
|
assert "python" in prompt
|
||||||
|
assert code in prompt
|
||||||
|
assert "Explain" in prompt
|
||||||
|
|
||||||
|
def test_code_refactor_prompt(self):
|
||||||
|
"""Test refactoring prompt creation."""
|
||||||
|
code = "def add(a,b):return a+b"
|
||||||
|
prompt = PromptTemplates.code_refactor(
|
||||||
|
language="python",
|
||||||
|
code=code,
|
||||||
|
focus=["readability", "naming"]
|
||||||
|
)
|
||||||
|
|
||||||
|
assert "python" in prompt
|
||||||
|
assert code in prompt
|
||||||
|
assert "readability" in prompt
|
||||||
|
assert "naming" in prompt
|
||||||
|
|
||||||
|
def test_safe_refactor_prompt(self):
|
||||||
|
"""Test safe refactoring prompt creation."""
|
||||||
|
code = "x = 1 + 2"
|
||||||
|
prompt = PromptTemplates.code_refactor_safe(
|
||||||
|
language="python",
|
||||||
|
code=code
|
||||||
|
)
|
||||||
|
|
||||||
|
assert "Safe refactoring" in prompt
|
||||||
|
assert "no changing external APIs" in prompt
|
||||||
|
|
||||||
|
def test_optimize_prompt(self):
|
||||||
|
"""Test optimization prompt creation."""
|
||||||
|
code = "for i in range(1000): print(i)"
|
||||||
|
prompt = PromptTemplates.code_refactor_optimize(
|
||||||
|
language="python",
|
||||||
|
code=code
|
||||||
|
)
|
||||||
|
|
||||||
|
assert "Optimize" in prompt
|
||||||
|
assert "performance" in prompt
|
||||||
|
|
||||||
|
def test_test_generation_prompt(self):
|
||||||
|
"""Test test generation prompt creation."""
|
||||||
|
code = "def add(a, b): return a + b"
|
||||||
|
prompt = PromptTemplates.test_generation(
|
||||||
|
language="python",
|
||||||
|
code=code
|
||||||
|
)
|
||||||
|
|
||||||
|
assert "pytest" in prompt or "testing framework" in prompt
|
||||||
|
assert code in prompt
|
||||||
|
|
||||||
|
def test_build_system_prompt(self):
|
||||||
|
"""Test system prompt building."""
|
||||||
|
prompt = PromptTemplates.build_system_prompt()
|
||||||
|
|
||||||
|
assert "coding assistant" in prompt.lower()
|
||||||
|
assert "Generate" in prompt
|
||||||
|
assert "Explain" in prompt
|
||||||
|
|
||||||
|
def test_build_system_prompt_with_context(self):
|
||||||
|
"""Test system prompt with extra context."""
|
||||||
|
prompt = PromptTemplates.build_system_prompt(
|
||||||
|
extra_context="Focus on performance optimization."
|
||||||
|
)
|
||||||
|
|
||||||
|
assert "performance optimization" in prompt
|
||||||
|
|
||||||
|
|
||||||
|
class TestLanguageConfig:
|
||||||
|
"""Tests for language configuration."""
|
||||||
|
|
||||||
|
def test_get_supported_languages(self):
|
||||||
|
"""Test getting list of supported languages."""
|
||||||
|
languages = LanguageConfig.get_supported_languages()
|
||||||
|
|
||||||
|
assert "python" in languages
|
||||||
|
assert "javascript" in languages
|
||||||
|
assert "typescript" in languages
|
||||||
|
assert "go" in languages
|
||||||
|
assert "rust" in languages
|
||||||
|
|
||||||
|
def test_is_supported(self):
|
||||||
|
"""Test language support check."""
|
||||||
|
assert LanguageConfig.is_supported("python") is True
|
||||||
|
assert LanguageConfig.is_supported("rust") is True
|
||||||
|
assert LanguageConfig.is_supported("cobol") is False
|
||||||
|
|
||||||
|
def test_get_extension(self):
|
||||||
|
"""Test file extension retrieval."""
|
||||||
|
assert LanguageConfig.get_extension("python") == ".py"
|
||||||
|
assert LanguageConfig.get_extension("javascript") == ".js"
|
||||||
|
assert LanguageConfig.get_extension("go") == ".go"
|
||||||
|
|
||||||
|
def test_get_comment_style(self):
|
||||||
|
"""Test comment style retrieval."""
|
||||||
|
assert LanguageConfig.get_comment_style("python") == "#"
|
||||||
|
assert LanguageConfig.get_comment_style("javascript") == "//"
|
||||||
|
assert LanguageConfig.get_comment_style("rust") == "//"
|
||||||
|
|
||||||
|
def test_get_config(self):
|
||||||
|
"""Test language configuration retrieval."""
|
||||||
|
config = LanguageConfig.get_config("python")
|
||||||
|
assert config.extension == ".py"
|
||||||
|
assert config.testing_framework == "pytest"
|
||||||
Reference in New Issue
Block a user