morpholib icon indicating copy to clipboard operation
morpholib copied to clipboard

feat: Add comprehensive Python testing infrastructure

Open llbbl opened this issue 5 months ago • 0 comments

Add Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the morpholib project, providing all the necessary tools and configuration for developers to write and run tests effectively.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration as the package manager
  • Dependencies:
    • Added numpy as a core dependency (required by morpholib)
    • Added testing dependencies: pytest, pytest-cov, pytest-mock as development dependencies

Testing Configuration

  • pytest Configuration in pyproject.toml:

    • Test discovery patterns for flexible test file naming
    • Coverage reporting with HTML and XML output
    • 80% coverage threshold (configurable)
    • Strict markers and verbose output
    • Custom test markers: unit, integration, slow
  • Coverage Configuration:

    • Source directory: morpholib
    • Excluded files: tests, dev tools, sample code
    • HTML report directory: htmlcov/
    • XML report: coverage.xml

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • sample_config: Sample configuration dictionary
  • mock_cairo_context: Mocked Cairo graphics context
  • mock_surface: Mocked Cairo surface
  • sample_animation_data: Sample animation data structure
  • sample_figure_data: Sample figure data structure
  • cleanup_files: File cleanup tracker
  • mock_ffmpeg: Mocked FFmpeg subprocess
  • isolated_morpholib_import: Isolated import environment

Development Commands

Both commands work identically and run the full test suite:

  • poetry run test
  • poetry run tests

Updated .gitignore

Added entries for:

  • Testing artifacts (.pytest_cache/, coverage.xml, htmlcov/)
  • Claude settings (.claude/*)
  • IDE files (.vscode/, .idea/, swap files)
  • OS files (.DS_Store, Thumbs.db)

Running Tests

  1. Install dependencies:

    poetry install
    
  2. Run all tests:

    poetry run test
    # or
    poetry run tests
    
  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 set to 80% but can be adjusted in pyproject.toml
  • The validation test skips morpholib import if optional dependencies (pyglet, PIL) are missing
  • Poetry lock file (poetry.lock) is tracked in version control for reproducible builds
  • The infrastructure is ready for immediate test development - no actual unit tests for the codebase were written, only infrastructure validation tests

llbbl avatar Jul 01 '25 03:07 llbbl