newm
newm copied to clipboard
feat: Set up complete Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR sets up a complete testing infrastructure for the newm Wayland compositor project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
-
Poetry Configuration: Created
pyproject.tomlwith Poetry configuration -
Dependencies Migration: Migrated all dependencies from
requirements.txtandsetup.pyto Poetry -
Entry Points: Created proper entry point modules (
__main__.py) for bothnewmandnewm_panel_basicpackages
Testing Framework
- Testing Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies
-
Pytest Configuration: Configured pytest with:
- Test discovery patterns
- Coverage reporting (HTML, XML, terminal)
- Custom markers for unit, integration, and slow tests
- Strict configuration options
Testing Structure
- Created organized test directory structure:
tests/ ├── __init__.py ├── conftest.py # Shared fixtures ├── test_setup_validation.py # Infrastructure validation ├── unit/ │ └── __init__.py └── integration/ └── __init__.py
Shared Fixtures (conftest.py)
Created comprehensive fixtures for common testing needs:
-
temp_dir: Temporary directory management -
mock_config_dir,mock_cache_dir,mock_runtime_dir: XDG directory mocking -
sample_config_file: Sample newm configuration -
mock_display: Wayland display mock -
mock_dbus_session: D-Bus session mock -
mock_pam_handle: PAM authentication mock -
mock_cairo_surface: Cairo surface mock -
mock_gesture_event: Gesture event mock -
clean_environment: Environment variable cleanup -
capture_logs: Log capturing utility
Other Changes
-
Updated .gitignore: Added comprehensive entries for:
- Testing artifacts (.pytest_cache, coverage files)
- Claude settings
- Virtual environments
- IDE files
- Python packaging artifacts
How to Use
Installing Dependencies
# Install all dependencies including dev dependencies
poetry install
Running Tests
# Run all tests
poetry run pytest
# Run with coverage
poetry run pytest --cov
# Run specific test file
poetry run pytest tests/test_setup_validation.py
# Run tests with specific marker
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow
Coverage Reports
After running tests with coverage, reports are generated in:
- Terminal output (with --cov flag)
- HTML report:
htmlcov/index.html - XML report:
coverage.xml
Notes
- The validation tests handle missing optional dependencies (like pywm) gracefully
- Coverage threshold is currently set to 0% to allow initial setup without failing
- The infrastructure is ready for developers to start writing unit and integration tests
- Both
poetry run testandpoetry run testscommands are available but currently not working due to Poetry limitations with script aliases