sublime-filterlines icon indicating copy to clipboard operation
sublime-filterlines copied to clipboard

feat: Add comprehensive Python testing infrastructure

Open llbbl opened this issue 5 months ago • 0 comments

Add Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the Filter Lines Sublime Text plugin, enabling developers to write and run unit and integration tests with proper mocking of Sublime Text APIs.

Changes Made

Package Management

  • Added pyproject.toml with Poetry configuration
  • Configured Poetry with package-mode = false for Sublime Text plugin compatibility
  • Added testing dependencies: pytest, pytest-cov, and pytest-mock

Testing Configuration

  • Configured pytest with:
    • Coverage reporting with 80% threshold
    • HTML and XML coverage report generation
    • Custom test markers: unit, integration, slow
    • Strict mode for better error detection

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures
├── test_setup_validation.py  # Infrastructure validation
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Test Fixtures

Created comprehensive fixtures in conftest.py:

  • mock_sublime - Mocked sublime module with constants and Region class
  • mock_sublime_plugin - Mocked sublime_plugin module
  • mock_view - Full mock of Sublime Text view object
  • mock_window - Mock of Sublime Text window object
  • temp_dir / temp_file - Temporary file handling
  • sample_text_lines - Sample data for testing
  • sample_config - Sample configuration settings

Additional Files

  • Updated .gitignore with testing, IDE, and build artifacts
  • Added TESTING.md with comprehensive testing guidelines
  • Created validation tests to verify the infrastructure works correctly

How to Use

  1. Install dependencies:

    poetry install --no-root
    
  2. Run tests:

    # Run all tests
    poetry run pytest
    
    # Run with verbose output
    poetry run pytest -v
    
    # Run only unit tests
    poetry run pytest -m unit
    
  3. View coverage:

    # Terminal report
    poetry run pytest --cov-report=term
    
    # HTML report
    poetry run pytest --cov-report=html
    open htmlcov/index.html
    

Notes

  • The infrastructure is ready for developers to start writing tests
  • All 15 validation tests pass successfully
  • Coverage is currently low (13.25%) as no actual unit tests have been written yet
  • The mocking infrastructure properly handles Sublime Text's API dependencies
  • Tests can be marked as unit, integration, or slow for selective execution

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures to mock Sublime Text APIs
  4. Achieve the 80% coverage threshold by testing the plugin functionality

llbbl avatar Jul 01 '25 03:07 llbbl