Skip to content

Add property-based, contract, regression, and plotting tests - #536

Merged
aarmey merged 2 commits into
mainfrom
test/thorough-testing-strategy
Sep 4, 2026
Merged

Add property-based, contract, regression, and plotting tests#536
aarmey merged 2 commits into
mainfrom
test/thorough-testing-strategy

Conversation

@aarmey

@aarmey aarmey commented Sep 2, 2026

Copy link
Copy Markdown
Member

Summary

Implements the testing strategy discussed for this repo: raises scrise coverage from 74% to 89% and adds test categories the suite was missing entirely.

  • Property-based invariant tests (test_invariants.py, Hypothesis): fuzzes shapes/ranks/seeds to check mathematical invariants that must hold for any valid input — sign-canonicalization idempotence, energy-ordering as a true permutation, self-matching identity in match_components_across_ranks, OPQ fidelity non-decreasing in sub-quantizer count, and correct_conditions' invariance to uniform rescaling of the condition factors (derived from OLS's scale-equivariance).
  • Contract/error-path tests (test_contracts.py): pins the exact exceptions raised when documented AnnData-key/parameter contracts are violated (missing condition_unique_idxs, missing Pf2_* factors, invalid bicv fractions, infeasible rank, X.X is None), so these become loud failures instead of confusing downstream crashes.
  • Golden regression test (test_golden_regression.py): pins pf2()'s R2X, component weights, and top-gene-per-component on a fixed synthetic fixture + seed, to catch silent behavior drift from e.g. a parafac2 dependency bump.
  • Plotting smoke tests (test_plotting_{factors,general,pacmap,stability}.py): the plotting subpackage was at 14–30% coverage; now 70–100%. Checks functions run without raising across edge cases (rank=1, missing pivot columns, 3-gene input) and that the right data lands on the right axis (plot_r2x, plot_bicv_r2x, plot_condition_factors legends, FMS invariance to component permutation).
  • Adds hypothesis as a dev dependency, a shared conftest.py synthetic-data factory (replacing ad hoc per-file fixtures going forward), and a [tool.coverage.report] fail_under = 85 gate so coverage regressions are caught in CI automatically.

Test plan

  • uv run pytest --cov=scrise --cov-report=term-missing — 81 passed, 2 skipped, 89% coverage, fail-under gate passes
  • uv run ruff check scrise / uv run ruff format --check scrise
  • uv run ty check scrise

🤖 Generated with Claude Code

aarmey and others added 2 commits September 2, 2026 09:40
Fills the gaps identified in the testing-strategy review: Hypothesis-driven
invariant tests for the core factorization/OPQ primitives, explicit
error-path tests for documented AnnData-key/parameter contracts, a golden
regression fixture pinning pf2() output on fixed synthetic data, and smoke
tests for the previously ~0-30%-covered plotting modules. Adds hypothesis
as a dev dependency and a shared synthetic-data conftest, and gates CI on
85% coverage (currently 89%) via tool.coverage.report.fail_under.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@aarmey
aarmey merged commit 15fdc6b into main Sep 4, 2026
6 checks passed
@aarmey
aarmey deleted the test/thorough-testing-strategy branch September 4, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant