PaddleOCR2Pytorch
PaddleOCR2Pytorch copied to clipboard
feat: Set up comprehensive Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the PaddleOCR2Pytorch project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry Configuration: Added
pyproject.tomlwith complete project metadata and dependencies - Development Dependencies: Included testing tools (pytest, pytest-cov, pytest-mock) and code quality tools (black, isort, flake8, mypy)
- Script Commands: Configured
poetry run testandpoetry run testscommands for easy test execution
Testing Framework
- pytest Configuration:
- Configured test discovery patterns for
test_*.pyand*_test.pyfiles - Set up strict markers and configuration options
- Added custom markers:
unit,integration, andslow - Configured coverage reporting with 80% threshold requirement
- Configured test discovery patterns for
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── unit/ # Unit tests directory
│ └── __init__.py
├── integration/ # Integration tests directory
│ └── __init__.py
└── test_setup_validation.py # Validation tests
Testing Fixtures (conftest.py)
temp_dir: Temporary directory managementsample_image: Test image generationsample_numpy_image: NumPy array image fixturessample_tensor_image: PyTorch tensor fixturesmock_config: Configuration dictionary fixturesmock_yaml_config: YAML configuration file fixturesmock_model_path: Model file path fixtures- Various OCR-specific fixtures for testing
Coverage Configuration
- Source directories: pytorchocr, ptstructure, converter, misc, tools
- Output formats: Terminal, HTML (htmlcov/), XML (coverage.xml)
- Coverage threshold: 80% (enforced)
- Branch coverage enabled
Code Quality Tools
- Black: Code formatting (line length: 120)
- isort: Import sorting (compatible with Black)
- flake8: Linting
- mypy: Type checking
Updated .gitignore
Added entries for:
- Testing artifacts (.coverage, htmlcov/, pytest_cache/)
- Claude-specific files (.claude/*)
- Poetry lock file (poetry.lock)
- IDE and temporary files
How to Use
Installation
# Install all dependencies including dev dependencies
poetry install --with dev
Running Tests
# Run all tests with coverage
poetry run test
# Alternative command
poetry run tests
# Run specific test file
poetry run pytest tests/test_setup_validation.py
# Run tests with specific markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"
# Run tests in parallel
poetry run pytest -n auto
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 (test_setup_validation.py) that verify:
- All testing dependencies are properly installed
- Project structure is correctly set up
- Fixtures are working as expected
- Custom markers are registered
- Coverage is configured correctly
All validation tests pass successfully.
Notes
- The testing infrastructure is ready for immediate use
- Developers can start writing unit and integration tests in the respective directories
- The 80% coverage threshold will be enforced on all test runs
- Both
poetry run testandpoetry run testscommands are available for flexibility