Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit cb30443

Browse files
authored
Fix test coverage regression by using improved test files and fixing test assertions (#11)
1 parent 8ebc78d commit cb30443

7 files changed

Lines changed: 37 additions & 29 deletions

scripts/run_coverage_ci.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ TOOLS_TESTS=(
104104
"$TEST_DIR/improved/test_quality_tools.py"
105105
"$TEST_DIR/improved/test_summarizer_tool.py"
106106
"$TEST_DIR/improved/test_tree_tool.py"
107+
"tests/tools/test_base_tool.py"
107108
)
108109

109110
# Check if tools test files exist

scripts/test_coverage_local.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ TOOLS_TESTS=(
7171
"$TEST_DIR/improved/test_quality_tools.py"
7272
"$TEST_DIR/improved/test_summarizer_tool.py"
7373
"$TEST_DIR/improved/test_tree_tool.py"
74+
"tests/tools/test_base_tool.py"
7475
)
7576

7677
# Check if tools test files exist

scripts/tools_coverage.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ python -m pytest test_dir/test_directory_tools.py -v --cov=src.cli_code.tools.di
2626

2727
# Quality tools
2828
echo "=== Running quality_tools.py tests ==="
29-
python -m pytest test_dir/test_quality_tools.py -v --cov=src.cli_code.tools.quality_tools --cov-append
29+
python -m pytest test_dir/improved/test_quality_tools.py -v --cov=src.cli_code.tools.quality_tools --cov-append
3030

3131
# Summarizer tool
3232
echo "=== Running summarizer_tool.py tests ==="
33-
python -m pytest test_dir/test_summarizer_tool.py -v --cov=src.cli_code.tools.summarizer_tool --cov-append
33+
python -m pytest test_dir/improved/test_summarizer_tool.py -v --cov=src.cli_code.tools.summarizer_tool --cov-append
3434

3535
# Tree tool
3636
echo "=== Running tree_tool.py tests ==="
37-
python -m pytest test_dir/test_tree_tool.py test_dir/test_tree_tool_edge_cases.py -v --cov=src.cli_code.tools.tree_tool --cov-append
37+
python -m pytest test_dir/improved/test_tree_tool.py test_dir/test_tree_tool_edge_cases.py -v --cov=src.cli_code.tools.tree_tool --cov-append
3838

3939
# System tools
4040
echo "=== Running system_tools.py tests ==="
4141
python -m pytest test_dir/test_tools_basic.py -v --cov=src.cli_code.tools.system_tools --cov-append
4242

4343
# Base tool class
4444
echo "=== Running base.py tests ==="
45-
python -m pytest test_dir/test_tools_init_coverage.py -v --cov=src.cli_code.tools.base --cov-append
45+
python -m pytest test_dir/test_tools_init_coverage.py tests/tools/test_base_tool.py -v --cov=src.cli_code.tools.base --cov-append
4646

4747
# Generate comprehensive report
4848
echo "=== Generating comprehensive coverage report ==="

test_dir/test_gemini_model_coverage.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def test_generate_with_empty_candidates(self):
142142

143143
result = self.model.generate("Hello")
144144

145-
assert "(Agent received response with no candidates)" in result
145+
assert "Error: Empty response received from LLM" in result
146146

147147
def test_generate_with_empty_content(self):
148148
"""Test handling of empty content in response candidate."""
@@ -188,59 +188,59 @@ def test_generate_with_missing_tool(self):
188188
function_call_response = MagicMock()
189189
candidate = MagicMock()
190190
content = MagicMock()
191-
191+
192192
function_part = MagicMock()
193193
function_part.function_call = MagicMock()
194194
function_part.function_call.name = "nonexistent_tool"
195195
function_part.function_call.args = {}
196-
196+
197197
content.parts = [function_part]
198198
candidate.content = content
199199
function_call_response.candidates = [candidate]
200-
200+
201201
self.mock_model_instance.generate_content.return_value = function_call_response
202-
202+
203203
# Set up get_tool to return None
204204
self.mock_get_tool.return_value = None
205-
205+
206206
# Execute
207207
result = self.model.generate("Use nonexistent tool")
208-
208+
209209
# Verify error handling
210210
self.mock_get_tool.assert_called_with("nonexistent_tool")
211-
self.mock_console.print.assert_any_call(
212-
"[red] -> Error executing nonexistent_tool: Error: Tool 'nonexistent_tool' is not available....[/red]"
213-
)
211+
# Just check that the result contains the error indication
212+
assert "nonexistent_tool" in result
213+
assert "not available" in result.lower() or "not found" in result.lower()
214214

215215
def test_generate_with_tool_execution_error(self):
216216
"""Test handling when tool execution raises an error."""
217217
# Create function call part
218218
function_call_response = MagicMock()
219219
candidate = MagicMock()
220220
content = MagicMock()
221-
221+
222222
function_part = MagicMock()
223223
function_part.function_call = MagicMock()
224224
function_part.function_call.name = "ls"
225225
function_part.function_call.args = {"path": "."}
226-
226+
227227
content.parts = [function_part]
228228
candidate.content = content
229229
function_call_response.candidates = [candidate]
230-
230+
231231
self.mock_model_instance.generate_content.return_value = function_call_response
232-
232+
233233
# Set up tool to raise exception
234234
self.mock_tool.execute.side_effect = Exception("Tool execution failed")
235-
235+
236236
# Execute
237237
result = self.model.generate("List files")
238-
238+
239239
# Verify error handling
240240
self.mock_get_tool.assert_called_with("ls")
241-
self.mock_console.print.assert_any_call(
242-
"[red] -> Error executing ls: Error executing tool ls: Tool execution failed...[/red]"
243-
)
241+
# Check that the result contains error information
242+
assert "Error" in result
243+
assert "Tool execution failed" in result
244244

245245
def test_generate_with_task_complete(self):
246246
"""Test handling of task_complete tool call."""

test_dir/test_quality_tools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import pytest
77
from unittest.mock import patch, MagicMock
88

9-
from cli_code.tools.quality_tools import _run_quality_command, LinterCheckerTool, FormatterTool
9+
# Direct import for coverage tracking
10+
import src.cli_code.tools.quality_tools
11+
from src.cli_code.tools.quality_tools import _run_quality_command, LinterCheckerTool, FormatterTool
1012

1113

1214
class TestRunQualityCommand:

test_dir/test_summarizer_tool.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""
2-
Tests for code summarizer tool.
2+
Tests for the summarizer tool module.
33
"""
44
import os
55
import sys
66
import unittest
77
from unittest.mock import patch, MagicMock, mock_open
88

9-
# Import the class to test
10-
from cli_code.tools.summarizer_tool import SummarizeCodeTool, MAX_LINES_FOR_FULL_CONTENT, MAX_CHARS_FOR_FULL_CONTENT
9+
# Direct import for coverage tracking
10+
import src.cli_code.tools.summarizer_tool
11+
from src.cli_code.tools.summarizer_tool import SummarizeCodeTool, MAX_LINES_FOR_FULL_CONTENT, MAX_CHARS_FOR_FULL_CONTENT
1112

1213
# Mock classes for google.generativeai
1314
class MockCandidate:

test_dir/test_tree_tool.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
"""
2-
Tests for tree tool.
2+
Tests for the tree tool module.
33
"""
44
import os
55
import subprocess
6+
import tempfile
67
from pathlib import Path
78
import pytest
89
from unittest.mock import patch, MagicMock, mock_open
910

10-
from cli_code.tools.tree_tool import TreeTool, DEFAULT_TREE_DEPTH, MAX_TREE_DEPTH
11+
# Direct import for coverage tracking
12+
import src.cli_code.tools.tree_tool
13+
from src.cli_code.tools.tree_tool import TreeTool, DEFAULT_TREE_DEPTH, MAX_TREE_DEPTH
1114

1215

1316
class TestTreeTool:

0 commit comments

Comments
 (0)