Recipes icon indicating copy to clipboard operation
Recipes copied to clipboard

feat: Add comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the project using Poetry as the package manager and pytest as the testing framework. The infrastructure provides a solid foundation for writing and running tests with proper coverage reporting and test organization.

Changes Made

Package Management

  • ✅ Added pyproject.toml with Poetry configuration
  • ✅ Configured project metadata and dependencies
  • ✅ Set up development dependencies for testing

Testing Framework

  • ✅ Installed pytest as the main testing framework
  • ✅ Added pytest-cov for coverage reporting
  • ✅ Added pytest-mock for mocking utilities
  • ✅ Configured pytest settings in pyproject.toml

Test Configuration

  • ✅ Set up coverage reporting with 80% minimum threshold
  • ✅ Configured HTML and XML coverage report generation
  • ✅ Added test markers: unit, integration, and slow
  • ✅ Set up Poetry scripts: poetry run test and poetry run tests

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures and configuration
├── test_setup_validation.py # Infrastructure validation tests
├── README.md               # Testing documentation
├── unit/                   # Unit tests directory
│   └── __init__.py
└── integration/           # Integration tests directory
    └── __init__.py

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • mock_model: Mock Lasagne model
  • mock_layer: Mock Lasagne layer
  • sample_input_data: Sample neural network input
  • sample_labels: Sample labels
  • mock_config: Configuration dictionary
  • mock_weights_file: Mock weights file
  • mock_dataset: Mock dataset object
  • mock_theano_function: Mock Theano function
  • disable_gpu: Force CPU execution
  • Session-scoped test directories

Additional Updates

  • ✅ Updated .gitignore with testing artifacts and Claude settings
  • ✅ Created validation tests to verify the infrastructure
  • ✅ Added comprehensive testing documentation

How to Use

  1. Install dependencies:

    poetry install
    
  2. Run all tests:

    poetry run test
    # or
    poetry run tests
    
  3. Run specific test types:

    # Unit tests only
    poetry run pytest -m unit
    
    # Integration tests only
    poetry run pytest -m integration
    
    # Exclude slow tests
    poetry run pytest -m "not slow"
    
  4. View coverage report:

    • Terminal: Automatically shown after test run
    • HTML: Open htmlcov/index.html in browser
    • XML: Available at coverage.xml

Validation

The infrastructure has been validated with 13 passing tests that verify:

  • pytest is working correctly
  • All fixtures are accessible and functional
  • Test markers work as expected
  • Coverage reporting is properly configured
  • Both poetry run test and poetry run tests commands work

Notes

  • The project dependencies (lasagne, theano, numpy) were inferred from the codebase
  • Coverage is currently configured to only track test files for infrastructure validation
  • When writing actual tests, update the coverage configuration to track the appropriate source modules
  • The poetry.lock file should be committed to ensure reproducible builds

llbbl avatar Jun 26 '25 12:06 llbbl