MGeo icon indicating copy to clipboard operation
MGeo copied to clipboard

feat: add comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 3 months ago • 0 comments

Add Comprehensive Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the geo-multimodal-retrieval project using Poetry as the package manager. The infrastructure provides a robust foundation for writing and running tests across the entire codebase.

Changes Made

Package Management

  • Created pyproject.toml with Poetry configuration
  • Migrated all dependencies from requirements.txt to Poetry format with compatible versions
  • Added development dependencies: pytest, pytest-cov, pytest-mock

Testing Configuration

  • Comprehensive pytest configuration in pyproject.toml including:
    • Test discovery patterns for files, classes, and functions
    • Custom markers: unit, integration, slow
    • Coverage settings with 80% threshold
    • HTML and XML coverage reports (htmlcov/, coverage.xml)
    • Strict configuration and verbose output

Directory Structure

  • Created organized test structure:
    tests/
    ├── __init__.py
    ├── conftest.py          # Shared fixtures
    ├── test_infrastructure.py  # Validation tests
    ├── unit/
    │   └── __init__.py
    └── integration/
        └── __init__.py
    

Shared Fixtures (conftest.py)

  • temp_dir - Temporary directory management
  • mock_config - Mock configuration objects
  • sample_data - Sample datasets for testing
  • mock_model - Mock PyTorch models
  • mock_tokenizer - Mock tokenization utilities
  • sample_tensor - Sample tensor data
  • cleanup_files - File cleanup management
  • test_data_dir - Session-scoped test data directory
  • mock_yaml_config - Mock YAML configuration

Scripts and Commands

  • Poetry scripts for easy test execution:
    • poetry run test - Run all tests
    • poetry run tests - Alternative test command
  • Standard pytest commands remain available

Additional Setup

  • Updated .gitignore with testing artifacts and Claude Code settings
  • Created validation tests to verify infrastructure functionality
  • Coverage configuration with source code inclusion and exclusion patterns

Testing Instructions

Install Dependencies

poetry install

Run All Tests

poetry run pytest
# or
poetry run test
# or  
poetry run tests

Run Specific Test Categories

poetry run pytest -m unit          # Unit tests only
poetry run pytest -m integration   # Integration tests only
poetry run pytest -m slow          # Slow tests only

Coverage Reports

poetry run pytest --cov-report=html  # Generate HTML coverage report
poetry run pytest --cov-report=term  # Terminal coverage report

Run Validation Tests

poetry run pytest tests/test_infrastructure.py -v

Infrastructure Validation

All validation tests pass successfully, confirming:

  • ✅ Python version compatibility (3.8+)
  • ✅ Pytest markers are properly configured
  • ✅ Project structure is correctly set up
  • ✅ All fixtures are working as expected
  • ✅ Test discovery and execution function properly
  • ✅ Coverage reporting generates correctly

Next Steps

Developers can now immediately start writing tests:

  1. Unit tests in tests/unit/ for individual functions/classes
  2. Integration tests in tests/integration/ for component interactions
  3. Use the provided fixtures in conftest.py for common testing scenarios
  4. Follow the established patterns in test_infrastructure.py

Notes

  • Poetry lock file will be generated after successful dependency installation
  • Coverage threshold is set to 80% - adjust in pyproject.toml if needed
  • Some dependencies (like PyTorch) may require platform-specific installation
  • Testing dependencies are isolated in the [tool.poetry.group.test.dependencies] section

llbbl avatar Sep 03 '25 21:09 llbbl