MasterDuelSimpleTranslateTool icon indicating copy to clipboard operation
MasterDuelSimpleTranslateTool copied to clipboard

feat: Set up comprehensive Python testing infrastructure

Open llbbl opened this issue 3 months ago • 0 comments

Set up Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the card image checking project, providing developers with a ready-to-use testing environment.

Key Changes Made

  • Package Management: Migrated from requirements.txt to Poetry with pyproject.toml

    • Converted all existing dependencies to Poetry format
    • Separated development dependencies (testing tools) from production dependencies
    • Fixed Python version compatibility issues
  • Testing Framework Setup:

    • Added pytest as the primary testing framework
    • Integrated pytest-cov for coverage reporting with 80% threshold
    • Added pytest-mock for enhanced mocking capabilities
  • Testing Configuration (pyproject.toml):

    • Configured test discovery patterns and output formatting
    • Set up coverage reporting (HTML, XML, and terminal)
    • Added custom markers: unit, integration, slow
    • Enabled strict configuration and warnings filtering
  • Directory Structure:

    tests/
    ├── __init__.py
    ├── conftest.py          # Shared fixtures
    ├── test_infrastructure.py  # Validation tests
    ├── unit/
    │   └── __init__.py
    └── integration/
        └── __init__.py
    
  • Comprehensive Fixtures (tests/conftest.py):

    • temp_dir: Temporary directory for test files
    • sample_image_path: Mock image file for testing
    • mock_config: Mock configuration object
    • mock_cv2, mock_keyboard, mock_pillow_image: Module mocks
    • sample_card_data: Test data for card objects
    • capture_stdout, mock_file_system: Testing utilities
  • Updated .gitignore:

    • Added testing artifacts (.pytest_cache/, .coverage, htmlcov/)
    • Included virtual environment and IDE files
    • Added OS-specific and Claude Code entries

Testing Commands

After this PR is merged, developers can run tests using:

# Install dependencies
poetry install

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov

# Run specific test types
poetry run pytest -m unit        # Unit tests only
poetry run pytest -m integration # Integration tests only
poetry run pytest -m "not slow"  # Skip slow tests

# Run specific test files
poetry run pytest tests/unit/
poetry run pytest tests/integration/

Infrastructure Validation

The PR includes comprehensive validation tests (tests/test_infrastructure.py) that verify:

  • All testing dependencies are properly installed
  • Project structure is correctly set up
  • Fixtures are working as expected
  • Custom pytest markers are available
  • Poetry commands function properly

Notes

  • Python Version: Set to >=3.8,<3.12 for compatibility with existing dependencies
  • Build Tools: Removed PyInstaller from main dependencies to avoid version conflicts (can be added back as dev dependency if needed for building executables)
  • Coverage: HTML coverage reports are generated in htmlcov/ directory
  • Lock File: poetry.lock is included to ensure consistent dependency versions

Next Steps

With this infrastructure in place, developers can immediately start writing tests for the existing codebase. The shared fixtures provide everything needed to test image processing, configuration management, and user interactions.

llbbl avatar Sep 03 '25 21:09 llbbl