CNNIQAplusplus
CNNIQAplusplus copied to clipboard
feat: Set up comprehensive testing infrastructure
Set up comprehensive testing infrastructure
Summary
This PR establishes a complete testing infrastructure for the PyTorch Image Quality Assessment project using modern Python tooling and best practices.
Changes Made
Package Management
- Added Poetry configuration in
pyproject.tomlwith proper dependency management - Migrated from requirements.txt to Poetry for better dependency resolution and virtual environment handling
- Updated Python version requirement to ^3.9 for compatibility with modern packages
Testing Framework
- Configured pytest with comprehensive settings including:
- Test discovery patterns for
test_*.pyand*_test.pyfiles - Custom markers:
unit,integration,slowfor test categorization - Strict configuration options for robust testing
- Test discovery patterns for
- Added pytest-cov for coverage reporting with multiple output formats
- Added pytest-mock for enhanced mocking capabilities
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and test utilities
├── unit/ # Unit tests
│ └── __init__.py
├── integration/ # Integration tests
│ └── __init__.py
└── test_setup_validation.py # Infrastructure validation tests
Shared Testing Utilities
Created comprehensive fixtures in conftest.py:
- File system fixtures:
temp_dir,sample_image_path - Data fixtures:
sample_image,sample_tensor,sample_patches,sample_labels - Mock objects:
mock_config,mock_dataset,mock_dataloader,mock_h5py_file,mock_yaml_config - Environment setup:
set_random_seedsfor reproducible testing,mock_cudafor CI/CD
Coverage Configuration
- HTML reports generated in
htmlcov/directory - XML reports for CI/CD integration (
coverage.xml) - Terminal output with missing line indicators
- Exclusion rules for common non-testable code patterns
- Configurable thresholds for coverage requirements
Development Workflow
- Poetry scripts:
poetry run testandpoetry run testscommands - Marker-based testing: Run specific test categories with
-m unit,-m integration,-m slow - Coverage integration: Automatic coverage reporting with all test runs
Infrastructure Improvements
- Updated .gitignore with comprehensive rules for:
- Python artifacts (
__pycache__/,*.pyc, etc.) - Testing artifacts (
.pytest_cache/,.coverage,htmlcov/) - Virtual environments and IDE files
- Machine learning specific files (
.h5,models/,logs/) - Claude Code configuration (
.claude/)
- Python artifacts (
Running Tests
Basic Usage
# Install dependencies
poetry install
# Run all tests
poetry run pytest
# Run tests without coverage
poetry run pytest --no-cov
# Run specific test categories
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow
Coverage Reports
# Generate HTML coverage report
poetry run pytest --cov-report=html
# View coverage in terminal
poetry run pytest --cov-report=term-missing
Validation
The setup includes validation tests (tests/test_setup_validation.py) that verify:
- ✅ pytest is working correctly
- ✅ All fixtures are available and functional
- ✅ PyTorch and NumPy are properly installed
- ✅ File creation and mocking utilities work
- ✅ Coverage reporting is functional
- ✅ Test markers are properly configured
All validation tests pass, confirming the infrastructure is ready for development.
Dependencies Updated
Updated from legacy versions in requirements.txt to modern, compatible versions:
- Python: ^3.9 (increased from ^3.8 for scipy compatibility)
- Core dependencies: h5py, PyYAML, Pillow, numpy, scipy, torch
- Testing dependencies: pytest ^7.4.0, pytest-cov ^4.1.0, pytest-mock ^3.11.1
Notes
- The
poetry.lockfile ensures reproducible installations across environments - The testing infrastructure is framework-agnostic and ready for immediate use
- Coverage thresholds can be adjusted in
pyproject.tomlas needed - Additional fixtures can be easily added to
conftest.pyfor project-specific needs
🤖 Generated with Claude Code