Skip to content

Latest commit

 

History

History

README.md

KortexDL Python Bindings - Test Suite

Comprehensive pytest suite for testing Python bindings of KortexDL framework.

Prerequisites

  1. Build Python bindings first:
cd python_bindings
mkdir build && cd build
cmake ..
make _kortexdl_core
  1. Install test dependencies:
pip install pytest pytest-cov numpy

Running Tests

Run all tests:

cd python_bindings
pytest tests/ -v

Run specific test file:

pytest tests/test_cnn.py -v

Run tests with coverage:

pytest tests/ --cov=. --cov-report=html

Run only CNN tests:

pytest tests/ -m cnn -v

Run without tests requiring bindings:

pytest tests/ -m "not requires_build"

Test Organization

tests/
├── conftest.py          # Shared fixtures and configuration
├── test_cnn.py          # CNN layer tests (Conv2d, MaxPool, etc.)
├── test_network.py      # Network class tests
├── test_optimizers.py   # Optimizer tests
└── test_utils.py        # Utility function tests

Test Markers

  • @pytest.mark.cnn - CNN layer tests
  • @pytest.mark.core - Core component tests
  • @pytest.mark.optimizer - Optimizer tests
  • @pytest.mark.integration - Integration tests
  • @pytest.mark.slow - Time-consuming tests
  • @pytest.mark.requires_build - Tests needing compiled bindings

Coverage

View coverage report:

pytest tests/ --cov=. --cov-report=html
open htmlcov/index.html

Continuous Integration

Tests automatically run in GitHub Actions CI pipeline for every push/PR.

Writing New Tests

  1. Add test file: tests/test_<component>.py
  2. Use fixtures from conftest.py
  3. Mark with appropriate pytest markers
  4. Follow naming convention: test_<functionality>

Example:

import pytest
import _kortexdl_core as bd

@pytest.mark.requires_build
@pytest.mark.cnn
def test_my_cnn_feature(sample_conv_input):
    conv = bd.Conv2d(3, 16, 3)
    output = conv.forward(sample_conv_input)
    assert output.shape[1] == 16

Troubleshooting

ImportError: No module named '_kortexdl_core':

  • Build the Python bindings first
  • Set PYTHONPATH: export PYTHONPATH=../build:$PYTHONPATH

Tests skipped:

  • Tests marked with requires_build will skip if bindings aren't built
  • This is expected - build bindings to run all tests

For more information, see the main project README.