Skip to content

Setup Testing Framework for C++ and Python Interfaces with scikit-build-core Integration #16

Description

@wdconinc

Current State

The mollerdb project currently has:

  • scikit-build-core + CMake build system
  • C++ core library (libmollerdb_core) with database functionality
  • Python bindings via pybind11
  • pytest listed in pyproject.toml test dependencies
  • Placeholder in CI workflow: echo "Tests would run here."
  • No actual test suite implemented

Proposed Testing Framework

C++ Testing (Core Library)

Framework: Google Test (gtest) or Catch2

  • Integrate via CMake (using FetchContent or as submodule)
  • Create tests/cpp/ directory with unit tests
  • Test Database class and core functionality independently
  • Build as CMake test target when BUILD_TESTING=ON
  • Run via CTest in CI pipeline

Example tests:

  • Database connection handling
  • Query execution
  • Apache Arrow table creation
  • Error handling and edge cases

Python Testing (Bindings & Integration)

Framework: pytest (already in dependencies)

  • Create tests/python/ directory with pytest test files
  • Test Python bindings correctness
  • Validate C++/Python data interchange via Apache Arrow
  • Test integration with pandas DataFrames
  • Mock database connections for unit tests

Example tests:

  • Module import and initialization
  • Database class instantiation from Python
  • Query execution and result retrieval
  • Arrow table to pandas DataFrame conversion

Integration with scikit-build-core

  1. CMake Configuration:

    • Add test targets to CMakeLists.txt
    • Configure CTest for C++ test discovery
    • Enable tests conditionally based on BUILD_TESTING
  2. Python Configuration:

    • Update pyproject.toml with test configuration
    • pytest automatically discovers tests in tests/python/
    • Can orchestrate running both C++ and Python tests
  3. CI Integration (.github/workflows/build.yml):

    - name: Run C++ tests
      run: |
        cd build
        ctest --output-on-failure
    
    - name: Run Python tests
      run: |
        pytest tests/python/ -v

Proposed Directory Structure

tests/
├── cpp/
│   ├── CMakeLists.txt
│   ├── test_database.cpp
│   └── test_arrow_conversion.cpp
└── python/
    ├── __init__.py
    ├── conftest.py          # pytest fixtures
    ├── test_basic.py        # import, initialization
    ├── test_database.py     # Database class tests
    └── test_integration.py  # end-to-end tests

Implementation Steps

  1. Add C++ Testing Framework:

    • Choose between Google Test or Catch2
    • Add to CMakeLists.txt (e.g., via FetchContent)
    • Create tests/cpp/CMakeLists.txt
    • Write initial tests for Database class
  2. Create Python Test Suite:

    • Create tests/python/ directory
    • Add conftest.py with pytest fixtures (mock connections, etc.)
    • Write basic import and instantiation tests
    • Add integration tests for query execution
  3. Update Build Configuration:

    • Ensure BUILD_TESTING option in CMake
    • Add test dependencies to pyproject.toml if needed
    • Configure pytest discovery settings
  4. Update CI Workflow:

    • Replace placeholder in build.yml with actual test commands
    • Run C++ tests after CMake build
    • Run Python tests after pip install
    • Ensure tests run on both Linux and macOS
  5. Documentation:

    • Update docs/README.md with "Testing" section
    • Add testing guidelines to AGENTS.md
    • Document how to run tests locally
    • Add examples in development workflow

Benefits

  • Independent validation: C++ core tested separately from Python bindings
  • Integration confidence: Ensures pybind11 bindings work correctly
  • Zero-copy verification: Validates Apache Arrow data transfer
  • Build system assurance: Catches scikit-build-core integration issues
  • CI/CD reliability: Automated testing on every commit and PR
  • Release quality: High confidence for PyPI releases

References

  • Current build workflow: .github/workflows/build.yml
  • CMake configuration: CMakeLists.txt
  • Python bindings: python/bindings.cpp
  • Core library: src/Database.cpp

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementNew feature or request

Type

Fields

Priority

None yet

Effort

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions