morpholib
morpholib copied to clipboard
feat: Add comprehensive Python testing infrastructure
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.tomlwith Poetry configuration as the package manager - Dependencies:
- Added
numpyas a core dependency (required by morpholib) - Added testing dependencies:
pytest,pytest-cov,pytest-mockas development dependencies
- Added
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
- Source directory:
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 filessample_config: Sample configuration dictionarymock_cairo_context: Mocked Cairo graphics contextmock_surface: Mocked Cairo surfacesample_animation_data: Sample animation data structuresample_figure_data: Sample figure data structurecleanup_files: File cleanup trackermock_ffmpeg: Mocked FFmpeg subprocessisolated_morpholib_import: Isolated import environment
Development Commands
Both commands work identically and run the full test suite:
poetry run testpoetry 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
-
Install dependencies:
poetry install -
Run all tests:
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 "not slow" # Exclude slow tests -
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