PythonSIFT icon indicating copy to clipboard operation
PythonSIFT copied to clipboard

feat: add comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

Add Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the pysift project using Poetry for dependency management and pytest for testing.

Changes Made

1. Package Management

  • Poetry Setup: Created pyproject.toml with project metadata and dependencies
  • Dependency Migration: Migrated dependencies from README to Poetry configuration
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

2. Testing Configuration

  • pytest Configuration:

    • Configured test discovery patterns
    • Set up coverage reporting with HTML and XML output
    • Added custom markers: unit, integration, slow, performance
    • Enabled strict mode and verbose output
    • Coverage threshold set to 0% (should be changed to 80% when actual tests are added)
  • Coverage Configuration:

    • Source directory set to pysift
    • Branch coverage enabled
    • Exclusion patterns for non-testable code
    • HTML and XML report generation

3. Testing Structure

tests/
├── __init__.py
├── conftest.py              # Shared pytest fixtures
├── test_setup_validation.py # Validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

4. Pytest Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir: Temporary directory for test files
  • sample_image: Color test image (100x100)
  • grayscale_image: Grayscale test image
  • sample_keypoints: OpenCV KeyPoint objects
  • sample_descriptors: Mock SIFT descriptors
  • mock_config: Configuration dictionary
  • test_image_path: Saved test image path
  • capture_stdout: Stdout capture utility
  • mock_sift_detector: Mocked SIFT detector

5. Poetry Scripts

Added convenient test commands:

  • poetry run test - Run all tests with coverage
  • poetry run tests - Alternative command (both work)

6. Additional Changes

  • Created .gitignore with comprehensive Python patterns
  • Added validation tests to verify the infrastructure works
  • Used opencv-python-headless to avoid GUI dependencies in tests

How to Use

  1. Install dependencies:

    poetry install
    
  2. Run tests:

    poetry run test        # or
    poetry run tests       # or
    poetry run pytest      # with custom options
    
  3. Run specific test categories:

    poetry run pytest -m unit              # Unit tests only
    poetry run pytest -m integration       # Integration tests only
    poetry run pytest -m "not slow"        # Exclude slow tests
    
  4. View coverage report:

    # After running tests, open htmlcov/index.html in a browser
    

Notes

  • The coverage threshold is currently set to 0% to allow the infrastructure to be merged without actual tests. This should be changed to 80% in pyproject.toml once unit tests are added.
  • All validation tests pass, confirming the infrastructure is properly configured.
  • The project uses opencv-python-headless to avoid GUI dependencies in CI/testing environments.
  • Poetry lock file is created and should be committed to ensure reproducible builds.

Next Steps

With this infrastructure in place, developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures for common testing needs
  4. Run tests with coverage to ensure code quality

llbbl avatar Jun 18 '25 00:06 llbbl