Tests¶
Munipack has two sets of tests. make check is the upstream test: it runs a short pipeline on one bundled real frame during the build. The tests in tests/ exercise the installed command-line tools, one file per area (tests/t_*.sh).
The tests in tests/ simulate their own frames with munipack artificial, so the right answer is known exactly. The tests need no network and all random numbers are seeded, so each run gives the same result. The whole set takes a few minutes.
Running the tests¶
In Docker¶
docker build --target test .
This builds the image, runs make check, and then runs all tests in tests/. A failed test fails the build. Add --progress=plain to see the log, and --no-cache-filter test to rerun the tests when nothing has changed. A plain docker build . skips the tests.
The final image does not contain the tests. To run them, or only some of them, in a container, tag the test stage:
docker build --target test -t munipack:test .
docker run --rm --entrypoint /opt/munipack-tests/run.sh munipack:test t_cli t_calib
With an image you already have, mount the test directory instead:
docker run --rm -v "$PWD/tests":/tests:ro --entrypoint /tests/run.sh <image> t_pipeline
Without Docker¶
tests/run.sh tests whichever munipack is on your PATH. It needs only bash, awk and the usual coreutils.
tests/run.sh # all tests
tests/run.sh t_cli t_astrometry # selected tests (.sh is optional)
KEEP=1 tests/run.sh t_gphot # keep the working directories
Each test runs in its own temporary directory, which is removed after a pass and kept after a failure so you can inspect the files; the log shows its path. Each check prints one ok: line, a test stops at its first FAIL:, and run.sh exits with status 0 only when every test passes.
make check¶
In a configured and built source tree (the Dockerfile shows the configure and build steps), run make check in src/. It finds stars, does aperture photometry, astrometry and photometric calibration on the bundled frame, and checks that the calibration constant is close to the expected value. The log is in src/test/check.sh.log.
What the tests check¶
Test |
What it checks |
|---|---|
|
Help works for every action, and bad input gives a clean error (exit status 1), not a crash |
|
The simulator: reproducible seeds, the detector noise model, star density, multiple processes |
|
Master bias, master dark and |
|
The main route |
|
Astrometry from scratch on rotated frames at high declination |
|
Matching guided by the header WCS, blind matching, wrong fields, few stars, proper motions |
|
Matching by a known pointing with unknown rotation, large catalogues, thread independence |
|
Stacking preserves flux, positions and exposure time |
|
Apertures of stars next to brighter neighbours |
|
Calibration in two filters gives the same result in either order |
|
The colour term of one filter, and |
|
The colour term with real SDSS star colours |
|
Two colour terms at once with real SDSS colours |
|
The colour term against noisy catalogue colours: corrected for their errors, and diluted with |
|
Growth-curve photometry, its errors and its calibration |
|
The systematic error of |
|
Empirical PSF photometry with a PSF that varies across the frame |
Writing a test¶
A test is a bash fragment tests/t_<area>.sh, with no shebang. run.sh picks up new files automatically and loads tests/lib.sh first, which turns on set -e -o pipefail and provides these helpers:
Helper |
What it does |
|---|---|
|
Report a passed check, or fail the test |
|
Pass when VALUE is a number between LO and HI |
|
Pass when CMD exits with a clean error (status 1) |
|
The value of a header keyword |
|
Number of rows, index of a column, or the values of columns of a table |
|
Mean, standard deviation and number of pixels of an image |
|
A checksum of the pixels, to compare images exactly |
|
Write a synthetic catalogue of N stars with V and B magnitudes |
|
Write a catalogue or any table from text lines on stdin |
|
Join two tables by sky position |
|
Median and robust standard deviation of numbers on stdin |
|
The column options that go with a |
Start each test with a short comment saying what it simulates. Send the output of commands that must succeed to /dev/null, and test every result with check, expect_fail or fail.