NumPyCNN
NumPyCNN copied to clipboard
feat: Add comprehensive Python testing infrastructure with Poetry
Add Complete Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the PyGAD CNN project, providing a solid foundation for test-driven development and continuous integration.
Changes Made
Package Management
- Poetry Setup: Configured Poetry as the primary package manager via
pyproject.toml - Dependency Migration: Migrated existing dependencies from
requirements.txtto Poetry - Lock File: Generated
poetry.lockfor reproducible builds
Testing Framework
- pytest: Added as the main testing framework with extensive configuration
- pytest-cov: Integrated for code coverage reporting
- pytest-mock: Included for advanced mocking capabilities
Project Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── test_setup_validation.py # Infrastructure validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Configuration (pyproject.toml)
- Test Discovery: Configured patterns for test files and functions
- Coverage Settings:
- 80% minimum coverage threshold
- HTML and XML report generation
- Exclusions for test files and virtual environments
- Custom Markers:
@pytest.mark.unit,@pytest.mark.integration,@pytest.mark.slow - Script Commands: Both
poetry run testandpoetry run testswork
Shared Fixtures (conftest.py)
temp_dir: Temporary directory managementsample_input_data&sample_output_data: CNN test datamock_config: Configuration dictionary for testingsample_conv_layer&sample_pool_layer: Layer configurationsreset_random_seed: Ensures reproducible testscapture_stdout: For testing print statementsmock_file_operations: File I/O mocking
Development Environment
- Updated .gitignore: Added Python-specific patterns, testing artifacts, and Claude settings
- Coverage Reports: Automatically generated in
htmlcov/andcoverage.xml
Running Tests
Install Dependencies
poetry install
Run All Tests
poetry run test
# or
poetry run tests
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"
View Coverage Report
# Generate and open HTML coverage report
poetry run test
open htmlcov/index.html
Notes
- The validation tests confirm all infrastructure components work correctly
- Coverage is currently low (13.65%) as only validation tests exist - this is expected
- The 80% coverage threshold will encourage comprehensive testing as the codebase grows
- Poetry.lock is tracked in git for reproducible environments across developers
Next Steps
Developers can now immediately start writing unit and integration tests for the CNN implementation using the established infrastructure.