dmx Test And Quality
Use this skill for changes under tests/ and for final verification of Python changes.
Test Layout
- Follow the repo's pytest discovery rules:
- files:
*_test.pyortest_*.py - functions:
test_* - classes:
Test*or*TestCase
- files:
- Put new tests beside the code family they exercise:
tests/statstests/bstatstests/torch_statstests/utilstests/mpi4pyfor MPI-specific behavior
Existing Test Patterns
- For
dmx.statsdistributions, start by readingtests/stats/stats_tests.py. - Reuse the shared harness when possible instead of building bespoke assertions.
- Preserve the repo's standard distribution checks:
- string round-tripping with
eval(str(...))where that pattern already exists - estimator and encoder wiring
- sampler repeatability for fixed seeds
- agreement between scalar and sequence log-density paths
- estimation or sequence-estimation improvement checks where relevant
- string round-tripping with
- Add custom assertions only for behavior that the harness does not already cover.
Torch-Specific Rules
- Default tests to CPU behavior unless the task is explicitly device-specific.
- Respect
TEST_TORCH_DEVICE; CI sets it tocpu. - Do not require CUDA or MPS for routine validation.
- Be careful with dtype expectations because MPS may force
float32paths in repo code.
Quality Gates From CI
Format and import order:
poetry run black --check .
poetry run isort --check .
Type checking:
poetry run mypy --explicit-package-bases \
src/dmx/arithmetic.py \
src/dmx/utils \
src/dmx/stats \
src/dmx/bstats \
src/dmx/torch_utils \
src/dmx/torch_stats \
src/dmx/mpi4py \
examples \
tests
Linting:
poetry run pylint src/dmx/stats --jobs=1 --fail-under=10
poetry run pylint src/dmx/bstats --jobs=1 --fail-under=10
poetry run pylint src/dmx/torch_stats --jobs=1 --fail-under=10
poetry run pylint src/dmx/mpi4py --jobs=1 --fail-under=10
poetry run pylint src/dmx/utils --jobs=1 --fail-under=10
poetry run pylint src/dmx/torch_utils --jobs=1 --fail-under=10
poetry run pylint examples --jobs=1 --fail-under=10
poetry run pylint tests --jobs=1 --fail-under=10
Docstring quality:
poetry run pydocstyle src/dmx/stats/pdist.py \
src/dmx/bstats \
src/dmx/torch_stats/pdist.py \
src/dmx/utils/optsutil.py \
src/dmx/utils/vector.py
Test job command:
TEST_TORCH_DEVICE=cpu poetry run pytest tests/bstats/ tests/stats/ tests/torch_stats/ tests/utils/ -v --tb=short
Practical Workflow
- Run the smallest relevant test target while iterating.
- Run the matching formatter, import-sort, and type checks on changed paths.
- Before finishing a substantial Python change, run the CI-equivalent test command plus any affected lint or docstring checks.
- If optional dependencies are involved, keep CI's install shape in mind:
- tests use
poetry install --no-interaction --extras ci --with dev - mypy and pylint use
poetry install --no-interaction --extras "ci optional" --with dev
- tests use