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
7 changes: 3 additions & 4 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[run]
source = src.cli_code
include =
include =
*/src/cli_code/*.py
*/src/cli_code/*/*.py
*/src/cli_code/*/*/*.py
omit =
omit =
*/.rules/*
*/.venv/*
*/docs/*
*/test_dir/*
*/tests/*
*/__pycache__/*
*/venv/*
Expand Down Expand Up @@ -38,4 +37,4 @@ directory = coverage_html
title = CLI Code Coverage Report

[xml]
output = coverage.xml
output = coverage.xml
13 changes: 5 additions & 8 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ This document provides guidelines and best practices for writing and maintaining

## Testing Structure

Tests are organized in two main directories:

- `test_dir/`: Contains most test files
- `tests/`: Contains all test files, organized by module (e.g., `tests/models`, `tests/tools`).
Tests are organized in the `tests/` directory, organized by module (e.g., `tests/models`, `tests/tools`).

Choose a reason for hiding this comment

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

medium

Consider rephrasing this sentence for better readability. For example, 'Tests are organized within the tests/ directory, categorized by module (e.g., tests/models, tests/tools).'


Test file naming follows these conventions:

Expand Down Expand Up @@ -110,7 +107,7 @@ mock_confirm = mocker.patch("path.to.questionary.confirm", return_value=mock_con

External APIs evolve over time, which can break tests. Follow these practices to make tests more resilient:

1. Use loose coupling to implementation details
1. Use loose coupling to implementation details
2. Avoid importing classes directly from unstable APIs when possible
3. For required imports, use try/except blocks to handle missing imports
4. Consider using conditional test execution with `@pytest.mark.skipif`
Expand Down Expand Up @@ -140,7 +137,7 @@ Recent work with the Google Generative AI (Gemini) API highlighted several key l

2. **Import Strategies**:
- Import specifically from submodules rather than top-level packages
- Use alternative imports when direct imports aren't available:
- Use alternative imports when direct imports aren't available:
```python
# Instead of
from google.generativeai.types import Candidate
Expand Down Expand Up @@ -170,7 +167,7 @@ Recent work with the Google Generative AI (Gemini) API highlighted several key l

3. **Regular Updates**: Update tests when APIs change, focusing on the behavior rather than the exact implementation.

4. **Error Handling**: Include proper error handling in tests to make them more robust against changes.
4. **Error Handling**: Include proper error handling in tests to make them more robust against changes.

### Known Test Workarounds

Expand All @@ -183,4 +180,4 @@ Recent work with the Google Generative AI (Gemini) API highlighted several key l

2. **Mock API Response Structure**: Some tests may have extra or adjusted mock structures to handle the model's specific response processing.
- Look for comments like `# Mock response adapted for agent loop` to identify these cases.
- When updating these tests, ensure you maintain the adjusted structure until the underlying issues are resolved.
- When updating these tests, ensure you maintain the adjusted structure until the underlying issues are resolved.
14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ package-dir = {"" = "src"}
exclude = [
".git",
".env",
"env",
".venv",
"venv",
".vscode",
".rules",
"env",
"venv",
"docs",
"__pycache__",
]
Expand All @@ -92,11 +92,11 @@ unfixable = []

# Ignore 'import' errors for pytest in test files
[tool.ruff.lint.per-file-ignores]
"test_dir/*" = ["F401", "F811", "E402", "F811", "F403", "F405", "E711", "E712", "F821"]
"tests/*" = ["F401", "F811", "E402", "F811", "F403", "F405", "E711", "E712", "F821"]

# Add pytest and pytest-cov configuration
[tool.pytest.ini_options]
testpaths = ["test_dir"]
testpaths = ["tests"]
python_files = "test_*.py"
python_classes = "Test*"
python_functions = "test_*"
Expand All @@ -106,11 +106,11 @@ source = ["cli_code"]
omit = [
"*/.rules/*",
"*/.venv/*",
"*/.pytest_cache/*",
"*/docs/*",
"*/test_*",
"*/__pycache__/*",
"tests/*",
"*/venv/*",
"*/.pytest_cache/*",
"*/__pycache__/*",
"*/site-packages/*",
]

Expand Down
24 changes: 12 additions & 12 deletions scripts/run_core_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ echo "Running core tests (tests that don't require API access)..."

# Run tests excluding those that require external API calls
python -m pytest \
test_dir/test_tree_tool_edge_cases.py \
test_dir/test_ollama_model_context.py \
test_dir/test_basic_functions.py \
test_dir/test_config.py \
test_dir/test_config_edge_cases.py::TestConfigNullHandling \
test_dir/test_config_edge_cases.py::TestConfigEdgeCases \
test_dir/test_file_tools.py \
test_dir/test_directory_tools.py \
test_dir/test_tree_tool.py \
test_dir/test_utils.py \
test_dir/test_tools_base.py \
tests/tools/test_tree_tool_edge_cases.py \
tests/models/test_ollama_model_context.py \
tests/test_basic_functions.py \
tests/test_config.py \
tests/test_config_edge_cases.py::TestConfigNullHandling \
tests/test_config_edge_cases.py::TestConfigEdgeCases \
tests/tools/test_file_tools.py \
tests/tools/test_directory_tools.py \
tests/tools/test_tree_tool.py \
tests/test_utils.py \
tests/tools/test_tools_base.py \
-v

exit_code=$?
Expand All @@ -29,4 +29,4 @@ else
echo -e "\n\033[31mSome core tests failed. See details above. ✗\033[0m"
fi

exit $exit_code
exit $exit_code
10 changes: 5 additions & 5 deletions scripts/run_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ rm -rf .coverage coverage.xml coverage_html/

# Run pytest with coverage
echo -e "${YELLOW}Running pytest with coverage...${NC}"
python -m pytest --cov=src/cli_code --cov-report=term --cov-report=xml --cov-report=html --verbose test_dir/ "$@"
python -m pytest --cov=src/cli_code --cov-report=term --cov-report=xml --cov-report=html --verbose tests/ "$@"

# Check if the tests were successful
if [ $? -eq 0 ]; then
Expand All @@ -46,18 +46,18 @@ fi
if [ -f coverage.xml ]; then
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); print(f\"{float(root.attrib['line-rate'])*100:.2f}\")")
echo -e "\n${YELLOW}Overall coverage: ${GREEN}${COVERAGE}%${NC}"

# Check if coverage meets the minimum threshold (60%)
if (( $(echo "$COVERAGE < 60" | bc -l) )); then
echo -e "${RED}Coverage is below the minimum threshold of 60%!${NC}"
else
echo -e "${GREEN}Coverage meets or exceeds the minimum threshold of 60%!${NC}"
fi

echo -e "\n${YELLOW}Coverage reports generated:${NC}"
echo -e "XML Report: ${GREEN}coverage.xml${NC}"
echo -e "HTML Report: ${GREEN}coverage_html/index.html${NC}"

# Open HTML report if on macOS
if [[ "$OSTYPE" == "darwin"* ]]; then
echo -e "\n${YELLOW}Opening HTML report...${NC}"
Expand All @@ -67,4 +67,4 @@ if [ -f coverage.xml ]; then
fi
else
echo -e "\n${RED}No coverage report generated!${NC}"
fi
fi
8 changes: 4 additions & 4 deletions tests/models/test_ollama_model_context.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
Tests for the Ollama Model context management functionality.
Tests for the OllamaModel context management capabilities.

To run these tests specifically:
python -m pytest test_dir/test_ollama_model_context.py
To run this file:
python -m pytest tests/models/test_ollama_model_context.py

To run a specific test:
python -m pytest test_dir/test_ollama_model_context.py::TestOllamaModelContext::test_manage_ollama_context_truncation_needed
python -m pytest tests/models/test_ollama_model_context.py::TestOllamaModelContext::test_manage_ollama_context_truncation_needed

To run all tests related to context management:
python -m pytest -k "ollama_context"
Expand Down
10 changes: 5 additions & 5 deletions tests/tools/test_tree_tool_edge_cases.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
Tests for edge cases in the TreeTool functionality.
Tests for edge cases of the TreeTool.

To run these tests specifically:
python -m pytest test_dir/test_tree_tool_edge_cases.py
To run just this test file:
python -m pytest tests/tools/test_tree_tool_edge_cases.py

To run a specific test:
python -m pytest test_dir/test_tree_tool_edge_cases.py::TestTreeToolEdgeCases::test_tree_empty_result
To run a specific test function:
python -m pytest tests/tools/test_tree_tool_edge_cases.py::TestTreeToolEdgeCases::test_tree_empty_result

To run all tests related to tree tool:
python -m pytest -k "tree_tool"
Expand Down