yolo-tiling
yolo-tiling copied to clipboard
feat: set up comprehensive Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure with Poetry
Summary
This PR establishes a comprehensive testing infrastructure for the YOLO tiling tool project using Poetry as the package manager. The setup provides a complete testing environment ready for immediate use by developers.
Changes Made
Package Management & Dependencies
- ✅ Poetry Setup: Created
pyproject.tomlwith complete Poetry configuration - ✅ Dependency Migration: Migrated existing dependencies from
requirements.txtto Poetry- numpy ^1.21.0
- pandas ^1.3.0
- Pillow ^8.0.0
- Shapely ^1.8.0
- ✅ Testing Dependencies: Added development dependencies
- pytest ^7.0.0
- pytest-cov ^4.0.0
- pytest-mock ^3.10.0
Testing Configuration
-
✅ Pytest Configuration: Comprehensive setup in
pyproject.toml- Test discovery patterns for files, classes, and functions
- Coverage reporting with 80% threshold
- HTML and XML coverage reports
- Strict configuration and custom markers (
unit,integration,slow) - Warning filters for clean test output
-
✅ Coverage Configuration: Detailed coverage settings
- Source code inclusion with appropriate exclusions
- Branch coverage enabled
- Multiple output formats (HTML in
htmlcov/, XML incoverage.xml)
Directory Structure
- ✅ Test Directories: Created organized test structure
tests/ ├── __init__.py ├── conftest.py (shared fixtures) ├── unit/ │ └── __init__.py ├── integration/ │ └── __init__.py └── test_setup_validation.py
Shared Testing Utilities
- ✅ Fixtures in conftest.py: Comprehensive shared fixtures including:
-
temp_dir: Temporary directory management -
sample_image_data: Generated test image data (416x416 RGB) -
sample_labels_data: YOLO format label data -
sample_dataset_structure: Complete dataset structure for testing -
mock_args: Mock command line arguments -
mock_file_system: File system operation mocking -
mock_image_operations: PIL Image operation mocking
-
Development Environment
- ✅ Updated .gitignore: Added comprehensive exclusions for:
- Testing artifacts (
.pytest_cache/,.coverage,htmlcov/,coverage.xml) - Python artifacts (
__pycache__/,*.pyc, build artifacts) - Virtual environments and IDE files
- Claude Code settings
- Testing artifacts (
Validation & Verification
- ✅ Validation Tests: Created
test_setup_validation.pywith tests for:- Testing framework availability
- Dependency verification
- Project structure validation
- Fixture accessibility
- Test markers functionality
- Main module import (with graceful handling of system dependencies)
How to Use
Install Dependencies
poetry install
Run Tests
# Run all tests with coverage
poetry run pytest
# Run tests without coverage
poetry run pytest --no-cov
# Run specific test markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow
# Run tests with verbose output
poetry run pytest -v
# Generate coverage report only
poetry run pytest --cov-report=html
Test Commands Verified
- ✅
poetry run pytest- Standard test execution - ✅
python -m pytest- Alternative execution method - ✅ Coverage reporting generates HTML and XML outputs
- ✅ All test markers work correctly
- ✅ Fixtures are accessible across test modules
Testing Infrastructure Features
- Ready-to-Use Environment: Developers can immediately start writing tests
- Flexible Test Organization: Separate directories for unit and integration tests
- Comprehensive Fixtures: Common testing scenarios pre-built
- Coverage Enforcement: 80% coverage threshold with detailed reporting
- Multiple Test Types: Support for unit, integration, and slow test markers
- System Dependency Handling: Graceful handling of missing system libraries
Notes
-
Poetry Lock File: The
poetry.lockfile is intentionally tracked to ensure reproducible builds - System Dependencies: Some tests may skip if system dependencies (like GEOS for Shapely) are unavailable in CI environments
- Coverage Configuration: Main module excluded from infrastructure validation tests but included for actual unit tests
- Test Isolation: Each test gets fresh temporary directories and mocked dependencies
Next Steps
Developers can now:
- Write unit tests in
tests/unit/ - Write integration tests in
tests/integration/ - Use the provided fixtures for common scenarios
- Run tests with confidence using the configured commands
- Monitor code coverage through generated reports
The testing infrastructure is complete and ready for development teams to begin writing comprehensive tests for the YOLO tiling functionality.