From 55fb44875c85d1c91dcb19c0edc0c21422c6611b Mon Sep 17 00:00:00 2001 From: "James H. Nguyen" Date: Tue, 15 Apr 2025 10:51:06 -0700 Subject: [PATCH] Update test directory references from test_dir to tests --- .coveragerc | 7 +++---- docs/TESTING.md | 13 +++++------- pyproject.toml | 14 ++++++------- scripts/run_core_tests.sh | 24 +++++++++++------------ scripts/run_coverage.sh | 10 +++++----- tests/models/test_ollama_model_context.py | 8 ++++---- tests/tools/test_tree_tool_edge_cases.py | 10 +++++----- 7 files changed, 41 insertions(+), 45 deletions(-) diff --git a/.coveragerc b/.coveragerc index 0d476dc..65d5e7a 100644 --- a/.coveragerc +++ b/.coveragerc @@ -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/* @@ -38,4 +37,4 @@ directory = coverage_html title = CLI Code Coverage Report [xml] -output = coverage.xml \ No newline at end of file +output = coverage.xml diff --git a/docs/TESTING.md b/docs/TESTING.md index 7229dda..2e4be3a 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -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`). Test file naming follows these conventions: @@ -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` @@ -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 @@ -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 @@ -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. \ No newline at end of file + - When updating these tests, ensure you maintain the adjusted structure until the underlying issues are resolved. diff --git a/pyproject.toml b/pyproject.toml index f083bd3..9578610 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,11 +69,11 @@ package-dir = {"" = "src"} exclude = [ ".git", ".env", - "env", ".venv", - "venv", ".vscode", ".rules", + "env", + "venv", "docs", "__pycache__", ] @@ -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_*" @@ -106,11 +106,11 @@ source = ["cli_code"] omit = [ "*/.rules/*", "*/.venv/*", + "*/.pytest_cache/*", "*/docs/*", - "*/test_*", - "*/__pycache__/*", + "tests/*", "*/venv/*", - "*/.pytest_cache/*", + "*/__pycache__/*", "*/site-packages/*", ] diff --git a/scripts/run_core_tests.sh b/scripts/run_core_tests.sh index 7df7dee..dbe7b91 100755 --- a/scripts/run_core_tests.sh +++ b/scripts/run_core_tests.sh @@ -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=$? @@ -29,4 +29,4 @@ else echo -e "\n\033[31mSome core tests failed. See details above. ✗\033[0m" fi -exit $exit_code \ No newline at end of file +exit $exit_code diff --git a/scripts/run_coverage.sh b/scripts/run_coverage.sh index 4d8d8e9..1b4cdc6 100755 --- a/scripts/run_coverage.sh +++ b/scripts/run_coverage.sh @@ -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 @@ -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}" @@ -67,4 +67,4 @@ if [ -f coverage.xml ]; then fi else echo -e "\n${RED}No coverage report generated!${NC}" -fi \ No newline at end of file +fi diff --git a/tests/models/test_ollama_model_context.py b/tests/models/test_ollama_model_context.py index 4e6b616..6e98775 100644 --- a/tests/models/test_ollama_model_context.py +++ b/tests/models/test_ollama_model_context.py @@ -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" diff --git a/tests/tools/test_tree_tool_edge_cases.py b/tests/tools/test_tree_tool_edge_cases.py index cb66b08..f8d072d 100644 --- a/tests/tools/test_tree_tool_edge_cases.py +++ b/tests/tools/test_tree_tool_edge_cases.py @@ -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"