osmand_map_creation icon indicating copy to clipboard operation
osmand_map_creation copied to clipboard

feat: Set up comprehensive Python testing infrastructure

Open llbbl opened this issue 3 months ago • 0 comments

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the osmand-osm project, providing all necessary tools and configurations for developers to write and run tests effectively.

What's Added

  • Package Management: Poetry configuration in pyproject.toml with proper dependency management
  • Testing Framework: pytest with coverage reporting, mocking utilities, and custom markers
  • Directory Structure: Organized testing structure with separate unit and integration test directories
  • Shared Fixtures: Comprehensive set of reusable test fixtures for common testing scenarios
  • Configuration: Pytest and coverage configurations with 80% coverage threshold
  • Validation: Infrastructure validation tests to ensure everything works correctly

Testing Infrastructure Components

Package Manager

  • Poetry set up as the primary package manager
  • Dependencies properly categorized (dev vs production)
  • Optional dependencies for database connections

Testing Dependencies

  • pytest - Main testing framework
  • pytest-cov - Coverage reporting with HTML, XML, and terminal output
  • pytest-mock - Enhanced mocking utilities

Directory Structure

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

Configuration Features

  • pytest.ini_options: Test discovery, strict markers, verbose output
  • coverage settings: 80% threshold, multiple report formats, exclusion patterns
  • test markers: unit, integration, slow for test categorization

Shared Fixtures

  • temp_dir - Temporary directory management
  • mock_config - Configuration mocking
  • mock_db_connection - Database connection mocking
  • sample_geojson_data - GeoJSON test data
  • sample_osm_data - OSM XML test data
  • mock_working_area - WorkingArea object mocking
  • And more...

Running Tests

After this PR, developers can run tests using:

# Install dependencies
poetry install --only=dev

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov=osmand_osm

# Run specific test categories
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow

# Run tests in specific directories
poetry run pytest tests/unit/
poetry run pytest tests/integration/

Coverage Reporting

The setup generates coverage reports in multiple formats:

  • Terminal: Shows missing lines during test runs
  • HTML: Detailed report in htmlcov/ directory
  • XML: Machine-readable report for CI/CD integration

Validation

The infrastructure includes validation tests (tests/test_infrastructure.py) that verify:

  • Python version compatibility
  • Pytest functionality
  • Fixture availability and functionality
  • Configuration correctness
  • Test markers
  • Mock capabilities
  • Temporary file handling
  • Environment setup

All validation tests pass, confirming the infrastructure is ready for use.

Notes

  • The setup uses optional dependencies to handle cases where system libraries (like GDAL) might not be available
  • .gitignore updated with comprehensive entries for testing artifacts, Python files, and development tools
  • Infrastructure is designed to be extensible - developers can easily add more fixtures and test utilities

🤖 Generated with Claude Code

llbbl avatar Sep 04 '25 14:09 llbbl