Add test files
Some checks failed
CI / test (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / type-check (push) Has been cancelled

This commit is contained in:
2026-02-04 11:03:02 +00:00
parent 380b30934e
commit 744410285f

43
tests/test_explainer.py Normal file
View 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"