fundamentals

tests/ — agent guide

The test directory mirrors src/active_inference/ one-for-one. Every new module under src/ must get a matching test file under tests/. New chapter scripts must be registered in tests/chapters/test_smoke.py; new extras topics must be registered in tests/extras/test_smoke.py; application demos are discovered automatically under tests/demo/test_demo_smoke.py.

Layout invariant

src/active_inference/<sub>/<module>.py   ↔   tests/<sub>/test_<module>.py

Examples:

Source file Test file
src/active_inference/core/distributions.py tests/core/test_distributions.py (+ test_distributions_mvn.py for the multivariate split)
src/active_inference/estimators/em.py tests/estimators/test_em.py
src/active_inference/utils/grids.py tests/utils/test_grids.py
src/active_inference/visualizations/plotting.py tests/visualizations/test_plotting.py

When you add a public symbol

  1. Add a test class to the matching tests/<sub>/test_<module>.py.
  2. The test must include at minimum:
    • one happy-path assertion against a hand-computed value;
    • one validation assertion (raises on bad input);
    • one numerical-stability or edge-case assertion (large/small values, batched input, empty arrays where applicable).
  3. If a chapter script uses the new symbol, also confirm it is exercised by the chapter smoke test in tests/chapters/test_smoke.py.

Conventions

Running locally

# fast inner loop — skip subprocess smoke tests
pytest tests/core tests/estimators tests/utils tests/visualizations -q

# full suite incl. chapter smoke tests
pytest

# extras smoke tests
pytest tests/extras -v

# application demo smoke + workflow tests
pytest tests/demo tests/test_demo_workflows -v

# coverage
pytest --cov=active_inference --cov-report=term-missing

Don’t put