Add test files
This commit is contained in:
43
tests/test_explainer.py
Normal file
43
tests/test_explainer.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""Tests for script explainer module."""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from shellgenius.explainer import ShellExplainer, explain_script, LineExplanation, ScriptExplanation
|
||||
|
||||
|
||||
class TestShellExplainer:
|
||||
def test_basic_explanation(self):
|
||||
"""Test basic script explanation."""
|
||||
with patch('shellgenius.explainer.get_ollama_client') as mock_client:
|
||||
mock_client.return_value.generate.return_value = {"success": False}
|
||||
|
||||
explainer = ShellExplainer()
|
||||
result = explainer.explain("echo hello", detailed=False)
|
||||
|
||||
assert result.shell_type == "bash"
|
||||
assert len(result.line_explanations) >= 1
|
||||
|
||||
def test_detect_shell_purpose(self):
|
||||
"""Test detection of script purpose."""
|
||||
with patch('shellgenius.explainer.get_ollama_client') as mock_client:
|
||||
mock_client.return_value.generate.return_value = {"success": False}
|
||||
|
||||
explainer = ShellExplainer()
|
||||
|
||||
git_script = "git clone repo\ngit status"
|
||||
result = explainer.explain(git_script, detailed=False)
|
||||
|
||||
assert "Git" in result.overall_purpose or "git" in result.overall_purpose.lower()
|
||||
|
||||
|
||||
class TestExplainScript:
|
||||
def test_convenience_function(self):
|
||||
"""Test the convenience function for explaining scripts."""
|
||||
with patch('shellgenius.explainer.get_ollama_client') as mock_client:
|
||||
mock_client.return_value.generate.return_value = {"success": False}
|
||||
|
||||
result = explain_script("echo hello", detailed=False)
|
||||
|
||||
assert isinstance(result, ScriptExplanation)
|
||||
assert result.shell_type == "bash"
|
||||
Reference in New Issue
Block a user