SublimeAllAutocomplete icon indicating copy to clipboard operation
SublimeAllAutocomplete copied to clipboard

feat: Add comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

Add Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the All Autocomplete Sublime Text plugin using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • No Migration Needed: No existing requirements.txt or setup.py files were found

Testing Dependencies

Added as development dependencies:

  • pytest ^8.0.0 - Core testing framework
  • pytest-cov ^5.0.0 - Coverage reporting
  • pytest-mock ^3.14.0 - Mocking utilities

Testing Configuration

Configured in pyproject.toml:

  • pytest settings:

    • Test discovery patterns for test_*.py and *_test.py
    • Coverage threshold set to 80%
    • HTML and XML coverage reports
    • Custom markers: unit, integration, slow
    • Strict mode enabled for markers and configuration
  • coverage settings:

    • Source includes all_views_completions.py
    • Excludes test files, cache, and virtual environments
    • Branch coverage enabled
    • Multiple report formats (terminal, HTML, XML)

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures for Sublime Text mocking
├── test_infrastructure.py  # Validation tests
├── unit/
│   ├── __init__.py
│   └── test_example.py  # Example test demonstrating usage
└── integration/
    └── __init__.py

Test Fixtures

Created comprehensive fixtures in conftest.py:

  • mock_sublime - Mocks the sublime module
  • mock_sublime_plugin - Mocks the sublime_plugin module
  • temp_dir - Temporary directory for test files
  • mock_settings - Mock Sublime Text settings
  • mock_view - Mock Sublime Text view object
  • mock_window - Mock Sublime Text window object
  • sample_completions - Sample completion data
  • plugin_settings_file - Temporary settings file
  • mock_region - Mock Region object
  • reset_modules - Auto-cleanup fixture

Development Commands

Configured Poetry scripts:

  • poetry run test - Run all tests
  • poetry run tests - Alternative command (both work)

Additional Setup

  • Updated .gitignore with:
    • Python artifacts (__pycache__/, *.pyc, etc.)
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, coverage.xml)
    • Claude settings (.claude/*)
    • Virtual environments and IDE files
    • Note: poetry.lock is not ignored (should be committed)

How to Use

  1. Install Poetry (if not already installed):

    curl -sSL https://install.python-poetry.org | python3 -
    
  2. Install dependencies:

    poetry install
    
  3. Run tests:

    # Run all tests with coverage
    poetry run test
    
    # Run specific test file
    poetry run test tests/unit/test_example.py
    
    # Run tests without coverage
    poetry run test --no-cov
    
    # Run tests with specific markers
    poetry run test -m unit
    poetry run test -m "not slow"
    
  4. View coverage reports:

    • Terminal: Shown automatically after test run
    • HTML: Open htmlcov/index.html in browser
    • XML: Available at coverage.xml for CI integration

Validation

The infrastructure has been validated with:

  • All dependencies properly installed
  • Test discovery working correctly
  • Coverage reporting functional
  • Custom markers configured
  • Example tests passing
  • Both test and tests commands working

Notes

  • The 80% coverage threshold is configured but won't be enforced until actual tests are written
  • The example test in tests/unit/test_example.py demonstrates how to properly mock Sublime Text APIs
  • The infrastructure is ready for immediate test development
  • No actual unit tests for the plugin code were written (as requested)

llbbl avatar Jun 26 '25 17:06 llbbl