From 555fe3fca34fe83831ae50401ba196bd3c401437 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Wed, 4 Feb 2026 11:22:14 +0000 Subject: [PATCH] fix: remove unused imports from test files --- .tests/test_explainer.py | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .tests/test_explainer.py diff --git a/.tests/test_explainer.py b/.tests/test_explainer.py new file mode 100644 index 0000000..5a315a1 --- /dev/null +++ b/.tests/test_explainer.py @@ -0,0 +1,81 @@ +"""Tests for ShellGenius explainer module.""" + +from shellgenius.explainer import ShellExplainer, explain_script + + +class TestShellExplainer: + """Test shell script explainer.""" + + def test_explainer_initialization(self): + """Test explainer creates properly.""" + explainer = ShellExplainer() + assert explainer.parser is not None + + def test_basic_explain(self): + """Test basic script explanation.""" + script = "#!/bin/bash +echo \"Hello, World!\" +ls -la +" + result = explain_script(script, detailed=False) + + assert result.shell_type == "bash" + assert len(result.line_explanations) > 0 + assert result.overall_purpose != "" + + def test_detect_keywords(self): + """Test keyword detection.""" + explainer = ShellExplainer() + + if_explanation = explainer._explain_line_basic("if [ -f file ]; then") + assert "conditional" in if_explanation.lower() + + for_explanation = explainer._explain_line_basic("for i in 1 2 3; do") + assert "loop" in for_explanation.lower() + + def test_common_patterns(self): + """Test common pattern detection.""" + explainer = ShellExplainer() + + shebang_explanation = explainer._explain_line_basic("#!/bin/bash") + assert "shebang" in shebang_explanation.lower() + + pipe_explanation = explainer._explain_line_basic("cat file | grep pattern") + assert "pipe" in pipe_explanation.lower() + + def test_generate_summary(self): + """Test summary generation.""" + explainer = ShellExplainer() + + from shellgenius.explainer import LineExplanation + + explanations = [ + LineExplanation(1, "cmd1", "command", True), + LineExplanation(2, "cmd2", "command", True), + LineExplanation(3, "function test()", "function", True), + ] + + summary = explainer._generate_summary(explanations, "bash") + assert "bash" in summary + assert "function" in summary.lower() + + def test_detect_purpose(self): + """Test purpose detection.""" + explainer = ShellExplainer() + + from shellgenius.explainer import LineExplanation + + git_explanations = [ + LineExplanation(1, "git status", "command", True), + LineExplanation(2, "git commit -m", "command", True), + ] + + purpose = explainer._detect_purpose(git_explanations) + assert "Git" in purpose + + def test_explain_script_function(self): + """Test convenience function.""" + result = explain_script("echo test", detailed=False) + assert result is not None + assert hasattr(result, "shell_type") + assert hasattr(result, "line_explanations")