Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 26, 2025

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)

- Set up Poetry as package manager with pyproject.toml configuration
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting (80% threshold)
- Create test directory structure (unit/integration)
- Add shared fixtures for Sublime Text plugin testing
- Update .gitignore with testing and Claude artifacts
- Include validation tests to verify infrastructure setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant