Skip to content

Improve test coverage for core modules using shared fixtures #427

Description

@jwrth

Background

Overall test coverage is ~33% (4,525 / 13,801 statements). The largest untested modules were assessed in March 2026. Two modules have 0% coverage and are good near-term targets. Two megaclass modules are feasible but require shared fixture infrastructure first.

Priority targets

Module Statements Coverage Barrier
tools/permutation.py 236 0% Pure numerical logic; needs AnnData + spatial graph fixture
spatialdata/_convert.py 261 0% Conversion layer; needs round-trip InSituPy ↔ SpatialData fixture
_core/data.py 731 26% Core InSituData class; needs shared fixture
experiment/data.py 947 14% Multi-sample container; needs shared fixture

Skip for now: interactive/_widgets.py and interactive/_transcript_viewer.py — both require a live napari/Qt display context.

What needs to be done

  1. Build a shared fixture in tests/conftest.py — a minimal but real InSituData object (and optionally a small InSituExperiment) constructed once per session:
    @pytest.fixture(scope="session")
    def insitudata_small():
        # load smallest available test dataset or construct synthetically
        ...
  2. Cover permutation.py — test the permutation null distribution logic with a small AnnData + precomputed neighbor graph.
  3. Cover spatialdata/_convert.py — test round-trip conversion (InSituPy → SpatialData → InSituPy) for each element type (images, tables, annotations, transcripts, boundaries).
  4. Cover _core/data.py and experiment/data.py using the shared fixture once it exists.

Implementation prompt

You are adding tests to the InSituPy package to improve coverage of four under-tested modules. Start by creating a shared session-scoped pytest fixture in tests/conftest.py that constructs a minimal InSituData object (use the smallest available test dataset or synthetic data). Use the conda environment isp012 to run pytest.

Then implement tests in this order:

  1. tests/test_tools_permutation.py — cover tools/permutation.py (236 stmts, 0%). Build a small AnnData with a precomputed neighbor graph and test the permutation null distribution logic.
  2. tests/test_spatialdata_convert.py — cover spatialdata/_convert.py (261 stmts, 0%). Write round-trip conversion tests (InSituPy → SpatialData → InSituPy) for each supported element type.
  3. tests/test_core_data.py — cover _core/data.py (731 stmts, 26%) using the shared insitudata_small fixture.
  4. tests/test_experiment_data.py — cover experiment/data.py (947 stmts, 14%) using a shared InSituExperiment fixture wrapping multiple InSituData instances.

Run pytest --cov=insitupy --cov-report=json before and after to measure the coverage delta. Target: raise overall coverage above 45%.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions