Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/run_coverage_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ TOOLS_TESTS=(
"$TEST_DIR/improved/test_quality_tools.py"
"$TEST_DIR/improved/test_summarizer_tool.py"
"$TEST_DIR/improved/test_tree_tool.py"
"tests/tools/test_base_tool.py"
)

# Check if tools test files exist
Expand Down
1 change: 1 addition & 0 deletions scripts/test_coverage_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ TOOLS_TESTS=(
"$TEST_DIR/improved/test_quality_tools.py"
"$TEST_DIR/improved/test_summarizer_tool.py"
"$TEST_DIR/improved/test_tree_tool.py"
"tests/tools/test_base_tool.py"
)

# Check if tools test files exist
Expand Down
8 changes: 4 additions & 4 deletions scripts/tools_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ python -m pytest test_dir/test_directory_tools.py -v --cov=src.cli_code.tools.di

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

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

# Tree tool
echo "=== Running tree_tool.py tests ==="
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
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

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

# Base tool class
echo "=== Running base.py tests ==="
python -m pytest test_dir/test_tools_init_coverage.py -v --cov=src.cli_code.tools.base --cov-append
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

# Generate comprehensive report
echo "=== Generating comprehensive coverage report ==="
Expand Down
38 changes: 19 additions & 19 deletions test_dir/test_gemini_model_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_generate_with_empty_candidates(self):

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding more context to the assertion message to indicate what the expected behavior is when an empty response is received from the LLM. This will help in debugging if the test fails in the future.

assert "Error: Empty response received from LLM" in result, "Should return an error message when LLM provides an empty response"


def test_generate_with_empty_content(self):
"""Test handling of empty content in response candidate."""
Expand Down Expand Up @@ -188,59 +188,59 @@ def test_generate_with_missing_tool(self):
function_call_response = MagicMock()
candidate = MagicMock()
content = MagicMock()

function_part = MagicMock()
function_part.function_call = MagicMock()
function_part.function_call.name = "nonexistent_tool"
function_part.function_call.args = {}

content.parts = [function_part]
candidate.content = content
function_call_response.candidates = [candidate]

self.mock_model_instance.generate_content.return_value = function_call_response

# Set up get_tool to return None
self.mock_get_tool.return_value = None

# Execute
result = self.model.generate("Use nonexistent tool")

# Verify error handling
self.mock_get_tool.assert_called_with("nonexistent_tool")
self.mock_console.print.assert_any_call(
"[red] -> Error executing nonexistent_tool: Error: Tool 'nonexistent_tool' is not available....[/red]"
)
# Just check that the result contains the error indication
assert "nonexistent_tool" in result
assert "not available" in result.lower() or "not found" in result.lower()
Comment on lines +211 to +213

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The original code used self.mock_console.print.assert_any_call to verify that the error message was printed to the console. The updated code directly asserts that the error message is present in the result string. While this simplifies the test, it might be beneficial to retain the mock to verify that the console print is actually called under certain error conditions. If the intention is to only check the final result, this change is acceptable.


def test_generate_with_tool_execution_error(self):
"""Test handling when tool execution raises an error."""
# Create function call part
function_call_response = MagicMock()
candidate = MagicMock()
content = MagicMock()

function_part = MagicMock()
function_part.function_call = MagicMock()
function_part.function_call.name = "ls"
function_part.function_call.args = {"path": "."}

content.parts = [function_part]
candidate.content = content
function_call_response.candidates = [candidate]

self.mock_model_instance.generate_content.return_value = function_call_response

# Set up tool to raise exception
self.mock_tool.execute.side_effect = Exception("Tool execution failed")

# Execute
result = self.model.generate("List files")

# Verify error handling
self.mock_get_tool.assert_called_with("ls")
self.mock_console.print.assert_any_call(
"[red] -> Error executing ls: Error executing tool ls: Tool execution failed...[/red]"
)
# Check that the result contains error information
assert "Error" in result
assert "Tool execution failed" in result

def test_generate_with_task_complete(self):
"""Test handling of task_complete tool call."""
Expand Down
4 changes: 3 additions & 1 deletion test_dir/test_quality_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import pytest
from unittest.mock import patch, MagicMock

from cli_code.tools.quality_tools import _run_quality_command, LinterCheckerTool, FormatterTool
# Direct import for coverage tracking
import src.cli_code.tools.quality_tools
from src.cli_code.tools.quality_tools import _run_quality_command, LinterCheckerTool, FormatterTool


class TestRunQualityCommand:
Expand Down
7 changes: 4 additions & 3 deletions test_dir/test_summarizer_tool.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""
Tests for code summarizer tool.
Tests for the summarizer tool module.
"""
import os
import sys
import unittest
from unittest.mock import patch, MagicMock, mock_open

# Import the class to test
from cli_code.tools.summarizer_tool import SummarizeCodeTool, MAX_LINES_FOR_FULL_CONTENT, MAX_CHARS_FOR_FULL_CONTENT
# Direct import for coverage tracking
import src.cli_code.tools.summarizer_tool
from src.cli_code.tools.summarizer_tool import SummarizeCodeTool, MAX_LINES_FOR_FULL_CONTENT, MAX_CHARS_FOR_FULL_CONTENT

# Mock classes for google.generativeai
class MockCandidate:
Expand Down
7 changes: 5 additions & 2 deletions test_dir/test_tree_tool.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""
Tests for tree tool.
Tests for the tree tool module.
"""
import os
import subprocess
import tempfile
from pathlib import Path
import pytest
from unittest.mock import patch, MagicMock, mock_open

from cli_code.tools.tree_tool import TreeTool, DEFAULT_TREE_DEPTH, MAX_TREE_DEPTH
# Direct import for coverage tracking
import src.cli_code.tools.tree_tool
from src.cli_code.tools.tree_tool import TreeTool, DEFAULT_TREE_DEPTH, MAX_TREE_DEPTH


class TestTreeTool:
Expand Down