PaddleOCR2Pytorch icon indicating copy to clipboard operation
PaddleOCR2Pytorch copied to clipboard

feat: Set up comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

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.toml with 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 test and poetry run tests commands for easy test execution

Testing Framework

  • pytest Configuration:
    • Configured test discovery patterns for test_*.py and *_test.py files
    • Set up strict markers and configuration options
    • Added custom markers: unit, integration, and slow
    • Configured coverage reporting with 80% threshold requirement

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 management
  • sample_image: Test image generation
  • sample_numpy_image: NumPy array image fixtures
  • sample_tensor_image: PyTorch tensor fixtures
  • mock_config: Configuration dictionary fixtures
  • mock_yaml_config: YAML configuration file fixtures
  • mock_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 test and poetry run tests commands are available for flexibility

llbbl avatar Jun 23 '25 23:06 llbbl