CNNIQAplusplus icon indicating copy to clipboard operation
CNNIQAplusplus copied to clipboard

feat: Set up comprehensive testing infrastructure

Open llbbl opened this issue 3 months ago • 0 comments

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.toml with 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_*.py and *_test.py files
    • Custom markers: unit, integration, slow for test categorization
    • Strict configuration options for robust testing
  • 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_seeds for reproducible testing, mock_cuda for 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 test and poetry run tests commands
  • 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/)

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.lock file ensures reproducible installations across environments
  • The testing infrastructure is framework-agnostic and ready for immediate use
  • Coverage thresholds can be adjusted in pyproject.toml as needed
  • Additional fixtures can be easily added to conftest.py for project-specific needs

🤖 Generated with Claude Code

llbbl avatar Sep 02 '25 14:09 llbbl