micro-jpeg-visualizer
micro-jpeg-visualizer copied to clipboard
feat: Add comprehensive Python testing infrastructure with Poetry
Add Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the micro-jpeg-visualizer Python project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry Setup: Configured Poetry as the package manager with
pyproject.toml - Package Mode: Set to false since this is a standalone script project
- Dependencies: Added Pillow as a production dependency (was already used in code)
Testing Framework
- pytest: Main testing framework with extensive configuration
- pytest-cov: Coverage reporting with HTML and XML output
- pytest-mock: Mocking utilities for unit tests
- Custom Markers: Added
unit,integration, andslowtest markers
Project Structure
/workspace/
├── pyproject.toml # Poetry and pytest configuration
├── poetry.lock # Locked dependencies
├── .gitignore # Updated with testing entries
├── run_tests.sh # Helper script for running tests
└── tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_setup_validation.py # Infrastructure validation
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Test Configuration
Coverage Settings
- Source directory: Project root
- Excluded: test files, virtual environments, cache directories
- Report formats: Terminal, HTML (
htmlcov/), XML (coverage.xml) - Coverage threshold: Removed from CI to allow initial setup
Test Discovery
- Test paths:
tests/directory - File patterns:
test_*.py,*_test.py - Class patterns:
Test* - Function patterns:
test_*
Fixtures Available
The conftest.py file provides comprehensive fixtures for testing:
-
File System:
temp_dir: Temporary directory with automatic cleanuptemp_file: Temporary file for testingsample_jpeg_path: Path to sample JPEG image
-
Mocking:
mock_config: Configuration dictionarymock_logger: Mock logger with all standard methodsmock_file_system: Mock file system operationsmock_argv: Mock command line arguments
-
Data:
sample_binary_data: Sample binary data for JPEG testingmock_image_data: Mock image data structurezigzag_data: JPEG zigzag pattern data
-
Utilities:
captured_output: Capture stdout/stderrperformance_timer: Simple timer for performance testsreset_modules: Auto-reset modules between tests
How to Run Tests
Using Poetry directly:
# Run all tests
poetry run pytest
# Run with coverage
poetry run pytest --cov
# Run specific marker
poetry run pytest -m unit
poetry run pytest -m integration
# Run without slow tests
poetry run pytest -m "not slow"
# Run specific test file
poetry run pytest tests/test_setup_validation.py
Using the helper script:
# Make executable (one time)
chmod +x run_tests.sh
# Run tests
./run_tests.sh
./run_tests.sh -v # verbose
./run_tests.sh --no-cov # without coverage
Installation
-
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 - -
Install dependencies:
poetry install -
Run validation tests:
poetry run pytest tests/test_setup_validation.py
Next Steps
With this infrastructure in place, developers can now:
- Write unit tests for individual functions in
tests/unit/ - Write integration tests in
tests/integration/ - Use the provided fixtures for common testing needs
- Run tests with coverage to track code quality
- Use markers to organize and selectively run tests
Notes
- The project uses package-mode = false in Poetry since it's a standalone script
- All test dependencies are in the dev group to keep production dependencies minimal
- The validation test suite confirms all infrastructure components work correctly
- Coverage reporting is configured but the threshold is not enforced in CI initially