SublimeAllAutocomplete
SublimeAllAutocomplete copied to clipboard
feat: Add comprehensive Python testing infrastructure with Poetry
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.tomlwith Poetry configuration - No Migration Needed: No existing
requirements.txtorsetup.pyfiles were found
Testing Dependencies
Added as development dependencies:
pytest ^8.0.0- Core testing frameworkpytest-cov ^5.0.0- Coverage reportingpytest-mock ^3.14.0- Mocking utilities
Testing Configuration
Configured in pyproject.toml:
-
pytest settings:
- Test discovery patterns for
test_*.pyand*_test.py - Coverage threshold set to 80%
- HTML and XML coverage reports
- Custom markers:
unit,integration,slow - Strict mode enabled for markers and configuration
- Test discovery patterns for
-
coverage settings:
- Source includes
all_views_completions.py - Excludes test files, cache, and virtual environments
- Branch coverage enabled
- Multiple report formats (terminal, HTML, XML)
- Source includes
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 modulemock_sublime_plugin- Mocks the sublime_plugin moduletemp_dir- Temporary directory for test filesmock_settings- Mock Sublime Text settingsmock_view- Mock Sublime Text view objectmock_window- Mock Sublime Text window objectsample_completions- Sample completion dataplugin_settings_file- Temporary settings filemock_region- Mock Region objectreset_modules- Auto-cleanup fixture
Development Commands
Configured Poetry scripts:
poetry run test- Run all testspoetry run tests- Alternative command (both work)
Additional Setup
- Updated
.gitignorewith:- Python artifacts (
__pycache__/,*.pyc, etc.) - Testing artifacts (
.pytest_cache/,.coverage,htmlcov/,coverage.xml) - Claude settings (
.claude/*) - Virtual environments and IDE files
- Note:
poetry.lockis not ignored (should be committed)
- Python artifacts (
How to Use
-
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 - -
Install dependencies:
poetry install -
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" -
View coverage reports:
- Terminal: Shown automatically after test run
- HTML: Open
htmlcov/index.htmlin browser - XML: Available at
coverage.xmlfor 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
testandtestscommands 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.pydemonstrates 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)