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

Commit 5fd6c14

Browse files
committed
Test improvements and coverage updates
1 parent 6bd13bf commit 5fd6c14

4 files changed

Lines changed: 93 additions & 67 deletions

File tree

run_targeted_coverage.sh

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,37 @@ set -e
66

77
echo "Running coverage for key modules..."
88

9-
# Tools modules
10-
echo "==== Testing test_runner.py ===="
11-
python -m pytest tests/tools/test_test_runner_tool.py --cov=src.cli_code.tools.test_runner --cov-report=term
9+
# Test runner tool - Run test files separately to avoid import conflicts
10+
echo "==== Testing test_runner.py (test_dir tests) ===="
11+
python -m pytest test_dir/test_test_runner_tool.py -v --cov=src.cli_code.tools.test_runner --cov-report=term
1212

13-
echo "==== Testing system_tools.py ===="
14-
python -m pytest test_dir/test_system_tools.py --cov=src.cli_code.tools.system_tools --cov-report=term
13+
echo "==== Testing test_runner.py (tests/tools tests) ===="
14+
python -m pytest tests/tools/test_test_runner_tool.py -v --cov=src.cli_code.tools.test_runner --cov-append --cov-report=term
1515

16-
echo "==== Testing task_complete_tool.py ===="
17-
python -m pytest tests/tools/test_task_complete_tool.py --cov=src.cli_code.tools.task_complete_tool --cov-report=term
16+
# Gemini model
17+
echo "==== Testing gemini.py ===="
18+
python -m pytest test_dir/test_gemini_model*.py -v --cov=src.cli_code.models.gemini --cov-report=term
19+
20+
# Ollama model
21+
echo "==== Testing ollama.py ===="
22+
python -m pytest test_dir/test_ollama_model*.py -v --cov=src.cli_code.models.ollama --cov-report=term
1823

19-
# Models modules
20-
echo "==== Testing models/base.py ===="
21-
python -m pytest test_dir/test_models_base.py --cov=src.cli_code.models.base --cov-report=term
24+
# File tools
25+
echo "==== Testing file_tools.py ===="
26+
python -m pytest test_dir/test_file_tools.py -v --cov=src.cli_code.tools.file_tools --cov-report=term
2227

23-
# Gemini model tests (excluding the failing test)
24-
echo "==== Testing Gemini model error handling (with skipped test_generate_with_quota_error_and_fallback_returns_success) ===="
25-
python -m pytest test_dir/test_gemini_model_error_handling.py -k "not test_generate_with_quota_error_and_fallback_returns_success" --cov=src.cli_code.models.gemini --cov-report=term
28+
# Tree tool
29+
echo "==== Testing tree_tool.py ===="
30+
python -m pytest test_dir/test_tree_tool.py -v --cov=src.cli_code.tools.tree_tool --cov-report=term
31+
python -m pytest test_dir/test_tree_tool_edge_cases.py -v --cov=src.cli_code.tools.tree_tool --cov-append --cov-report=term
32+
33+
# Task complete tool
34+
echo "==== Testing task_complete_tool.py ===="
35+
python -m pytest test_dir/test_task_complete_tool.py -v --cov=src.cli_code.tools.task_complete_tool --cov-report=term
36+
python -m pytest tests/tools/test_task_complete_tool.py -v --cov=src.cli_code.tools.task_complete_tool --cov-append --cov-report=term
2637

27-
# Add more modules as needed
28-
# python -m pytest path/to/test --cov=src.cli_code.module --cov-report=term
38+
# Run tests for all remaining tools to get comprehensive coverage
39+
echo "==== Testing other tools ===="
40+
python -m pytest test_dir/test_tools_basic.py test_dir/test_tools_init_coverage.py test_dir/test_directory_tools.py test_dir/test_quality_tools.py test_dir/test_summarizer_tool.py -v --cov=src.cli_code.tools --cov-report=term
2941

3042
echo "Targeted coverage complete!"

test_dir/test_file_tools.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
"""
22
Tests for file operation tools.
33
"""
4+
import pytest
45
import os
6+
import tempfile
57
import re
68
import glob
7-
import pytest
8-
from unittest.mock import patch, mock_open, MagicMock, call
9+
from unittest.mock import patch, MagicMock, mock_open, call
10+
import shutil
11+
import sys
12+
from pathlib import Path
13+
14+
# Add the src directory to the path for imports
15+
sys.path.insert(0, str(Path(__file__).parent.parent))
916

10-
from cli_code.tools.file_tools import ViewTool, EditTool, GrepTool, GlobTool, MAX_CHARS_FOR_FULL_CONTENT
17+
# Import the classes and functions directly for better coverage tracking
18+
from src.cli_code.tools.file_tools import ViewTool, EditTool, GrepTool, GlobTool, MAX_CHARS_FOR_FULL_CONTENT
1119

1220

1321
class TestViewTool:

test_dir/test_gemini_model.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@
88
import unittest
99
from unittest.mock import patch, MagicMock, mock_open, call
1010
import pytest
11+
from pathlib import Path
12+
13+
# Add the src directory to the path for imports
14+
sys.path.insert(0, str(Path(__file__).parent.parent))
1115

1216
# Check if running in CI
1317
IN_CI = os.environ.get('CI', 'false').lower() == 'true'
1418

1519
# Handle imports
1620
try:
17-
from cli_code.models.gemini import GeminiModel
1821
from rich.console import Console
1922
import google.generativeai as genai
23+
from src.cli_code.models.gemini import GeminiModel
24+
from src.cli_code.tools.base import BaseTool
25+
from src.cli_code.tools import AVAILABLE_TOOLS
2026
IMPORTS_AVAILABLE = True
2127
except ImportError:
2228
IMPORTS_AVAILABLE = False
@@ -52,7 +58,7 @@ def setup_method(self):
5258
self.mock_console = MagicMock(spec=Console)
5359

5460
# Keep get_tool patch here if needed by other tests, or move into tests
55-
self.get_tool_patch = patch('cli_code.models.gemini.get_tool')
61+
self.get_tool_patch = patch('src.cli_code.models.gemini.get_tool')
5662
self.mock_get_tool = self.get_tool_patch.start()
5763
# Configure default mock tool behavior if needed by other tests
5864
self.mock_tool = MagicMock()
@@ -186,7 +192,7 @@ def test_get_initial_context_with_ls_fallback(self, tmp_path):
186192

187193
# Act: Patch get_tool locally
188194
# Note: GeminiModel imports get_tool directly
189-
with patch('cli_code.models.gemini.get_tool') as mock_get_tool:
195+
with patch('src.cli_code.models.gemini.get_tool') as mock_get_tool:
190196
mock_get_tool.return_value = mock_ls_tool
191197
model = GeminiModel("fake-api-key", self.mock_console, "gemini-pro")
192198
context = model._get_initial_context()
@@ -203,7 +209,7 @@ def test_get_initial_context_with_ls_fallback(self, tmp_path):
203209
def test_create_tool_definitions(self):
204210
"""Test creation of tool definitions for Gemini."""
205211
# Create a mock for AVAILABLE_TOOLS
206-
with patch('cli_code.models.gemini.AVAILABLE_TOOLS') as mock_available_tools:
212+
with patch('src.cli_code.models.gemini.AVAILABLE_TOOLS') as mock_available_tools:
207213
# Sample tool definition
208214
mock_available_tools.return_value = {
209215
"test_tool": {

0 commit comments

Comments
 (0)