GraphLoG icon indicating copy to clipboard operation
GraphLoG 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 GraphLoG project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for developers to write and run unit tests, integration tests, and generate coverage reports.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry setup for dependency management
  • Dependencies: Added core dependencies (torch, numpy, scikit-learn, pandas, tqdm, tensorboardx)
  • Dev Dependencies: Added pytest, pytest-cov, and pytest-mock for comprehensive testing

Testing Framework

  • pytest Configuration: Configured with custom markers (unit, integration, slow)
  • Coverage Reporting: Set up with 80% coverage threshold, HTML and XML report generation
  • Test Discovery: Configured for test_*.py and *_test.py patterns

Directory Structure

  • Testing Directories: Created tests/, tests/unit/, and tests/integration/ with proper __init__.py files
  • Shared Fixtures: Comprehensive conftest.py with fixtures for temp directories, mock data, graph structures, and configuration

Additional Setup

  • Validation Tests: Created test_infrastructure.py to verify the testing setup works correctly
  • .gitignore: Updated with testing-related entries, coverage files, and development artifacts
  • Coverage Configuration: Proper exclusions for test files, virtual environments, and build artifacts

Testing Infrastructure Components

Available Fixtures in conftest.py

  • temp_dir, temp_file: Temporary filesystem utilities
  • mock_config, mock_args: Configuration and argument mocking
  • sample_tensor, sample_graph_data: Test data generation
  • set_seed: Reproducible random number generation
  • cleanup_cuda: CUDA memory management

Custom Markers

  • @pytest.mark.unit: Unit tests
  • @pytest.mark.integration: Integration tests
  • @pytest.mark.slow: Slow-running tests

How to Run Tests

Install Dependencies

# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -

# Install project dependencies
poetry install

Run Tests

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov

# Run specific test types
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"

# Run specific test file
poetry run pytest tests/test_infrastructure.py

# Run with verbose output
poetry run pytest -v

Coverage Reports

  • Terminal: Shows missing line coverage in terminal output
  • HTML: Generates htmlcov/index.html for browser viewing
  • XML: Generates coverage.xml for CI/CD integration

Validation

All 14 validation tests pass, confirming:

  • pytest framework works correctly
  • Fixtures are properly configured
  • Test discovery and markers function as expected
  • Coverage reporting generates successfully
  • Mock data structures work for graph-based testing

Dependencies Added

Production Dependencies

  • torch: Deep learning framework
  • numpy: Numerical computing
  • scikit-learn: Machine learning utilities
  • pandas: Data manipulation
  • tqdm: Progress bars
  • tensorboardx: TensorBoard logging

Development Dependencies

  • pytest ^7.0.0: Testing framework
  • pytest-cov ^4.0.0: Coverage reporting
  • pytest-mock ^3.10.0: Mocking utilities

Notes

  • Poetry lock file (poetry.lock) is committed to ensure reproducible builds
  • Package mode is disabled since this is a research project, not a distributable package
  • Coverage threshold is set to 80% but can be adjusted in pyproject.toml
  • The infrastructure is designed to work with the existing GraphLoG codebase structure

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the shared fixtures for consistent test data
  4. Generate coverage reports to track test completeness
  5. Run tests with various filtering options using the custom markers

🤖 Generated with Claude Code

llbbl avatar Sep 04 '25 14:09 llbbl