CTags icon indicating copy to clipboard operation
CTags copied to clipboard

feat: Set up comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the ANSI Color Build Sublime Text plugin using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Set up Poetry as the package manager (created pyproject.toml)
  • Added testing dependencies as development dependencies:
    • pytest - Main testing framework
    • pytest-cov - Coverage reporting
    • pytest-mock - Mocking utilities

Testing Configuration

  • Configured pytest in pyproject.toml with:
    • Test discovery patterns for test_*.py and *_test.py
    • Coverage settings with 80% threshold
    • HTML and XML coverage report generation
    • Custom test markers: unit, integration, slow
    • Strict mode with verbose output

Directory Structure

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

Development Commands

Both of these commands work to run tests:

  • poetry run test
  • poetry run tests

Shared Fixtures (conftest.py)

Created comprehensive fixtures for testing Sublime Text plugins:

  • temp_dir - Temporary directory management
  • temp_file - Temporary file creation
  • mock_sublime - Mock sublime module with all constants and methods
  • mock_sublime_plugin - Mock sublime_plugin classes (TextCommand, WindowCommand, EventListener)
  • mock_view - Mock Sublime Text view objects
  • mock_window - Mock Sublime Text window objects
  • mock_settings - Mock settings with get/set/has/erase functionality
  • sample_ansi_output - Sample ANSI colored strings for testing
  • reset_modules - Auto-cleanup of imported modules between tests
  • capture_stdout - Stdout capture for testing print statements

Updated .gitignore

Added comprehensive testing-related entries:

  • Coverage files (.coverage, htmlcov/, coverage.xml)
  • Claude configuration (.claude/*)
  • Build artifacts and virtual environments
  • IDE files

How to Use

  1. Install dependencies:

    poetry install
    
  2. Run all tests:

    poetry run test
    # or
    poetry run tests
    
  3. Run specific test types:

    # Unit tests only
    poetry run pytest -m unit
    
    # Integration tests only
    poetry run pytest -m integration
    
    # Exclude slow tests
    poetry run pytest -m "not slow"
    
  4. View coverage report:

    • Terminal: Coverage is shown after each test run
    • HTML: Open htmlcov/index.html in a browser
    • XML: Available at coverage.xml for CI integration

Notes

  • The 80% coverage threshold is currently not met since no actual tests for the codebase exist yet
  • This setup provides all the infrastructure needed to start writing comprehensive tests
  • All validation tests pass, confirming the testing environment is properly configured
  • Poetry lock file (poetry.lock) is tracked in git for reproducible builds

llbbl avatar Jun 15 '25 17:06 llbbl