-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functional tests with Cram #542
Conversation
Codecov Report
@@ Coverage Diff @@
## master #542 +/- ##
==========================================
- Coverage 19.22% 19.16% -0.06%
==========================================
Files 31 31
Lines 5072 5072
Branches 1288 1289 +1
==========================================
- Hits 975 972 -3
- Misses 4074 4077 +3
Partials 23 23
Continue to review full report at Codecov.
|
conda does not provide a pip3 command, but the base Travis python does. This means pip3 install places the augur development dependencies in the global python environment instead of the conda environment. As a result, cram tests fail when they rely on python packages that are only installed as dev dependencies because cram's "python" is the conda environment's "python". This commit should install development dependencies in the conda environment instead of the global environment and make those packages available to the python command inside cram tests.
Introduces two different, complementary approaches to functional testing with Cram. The first approach basically copies the commands already executed by the Snakefiles in the tests/builds directory into the Cram format. The zika build, for example, is partially represented by zika.t in that builds directory. The second approach tries to more comprehensively test a specific augur command with a variety of reasonable inputs. The mask.t file represents an example of that type of test for augur mask.
augur mask now supports multiple masking inputs and no longer requires the `--mask` argument. This commit updates the augur mask tests to reflect these new command line arguments and also modifies informational output from the `read_bed_file` function to clarify that the reported number of sites to mask only reflects the BED file contents and not the other mask arguments.
496d320
to
0878320
Compare
Run functional tests when running the generic "run_tests" script and when full unit tests are also being run. We skip functional tests when the user requests a subset of unit tests to facilitate rapid testing during test-driven development. Cram tests use pushd and popd which are bash-specific and not available in Travis's default shell, so we specify the shell for Cram tests to use.
Also places one sentence per line in the testing section and clarifies how to run a subset of unit tests.
@tsibley @jameshadfield This approach with Cram seems to be working well now, so I am merging this PR now. This will allow us to start integrating other work from the community including new functional tests. I'm happy to make any revisions to this approach generally in future PRs, if you have suggestions. |
Adds functional tests of augur’s command line interface with Cram. These tests complement existing unit tests of individual augur Python functions by running augur commands on the shell and confirming that these commands:
These tests can reveal bugs resulting from untested internal functions or untested combinations fo internal functions.
Functional tests should either:
tests/functional/
(e.g.,mask.t
for augur mask)OR
tests/builds/
(e.g.,zika.t
for the example Zika build)Functional tests of complete builds should supersede existing Snakemake-based tests. The Snakemake files are still useful for producing new expected inputs and outputs for Cram, but Snakemake does not need to be run as part of Travis CI after we have migrated all example builds to Cram.
Running tests
Install augur with dev dependencies (
pip install .[dev]
from the GitHub repo). Run all functional tests per command and build with Cram.Functional tests of specific commands
Functional tests of specific commands consist of a single Cram file per test and a corresponding directory of expected inputs and outputs to use for comparison of test results.
The Cram file should test most reasonable combinations of command arguments and flags.
Functional tests of example builds
Functional tests of example builds use output from a real Snakemake workflow as expected inputs and outputs. These tests should confirm that all steps of a workflow can execute and produce the expected output. These tests reflect actual augur usage in workflows and are not intended to comprehensively test interfaces for specific augur commands.
The Cram file should replicate the example workflow from start to end. These tests should use the output of the Snakemake workflow (e.g., files in
zika/results/
for the Zika build test) as the expected inputs and outputs.Comparing outputs of augur commands
Compare deterministic outputs of augur commands with a
diff
between the expected and observed output files. For extremely simple deterministic outputs, use the expected text written to standard output instead of creating a separate expected output file.To compare trees with stochastic branch lengths:
--tree-builder-args "-seed 314159"
for the “iqtree” method of augur tree)scripts/diff_trees.py
instead ofdiff
and optionally provide a specific number to--significant-digits
to limit the precision that should be considered in the diffTo compare JSON outputs with stochastic numerical values, use
scripts/diff_jsons.py
with the appropriate--significant-digits
argument.Both tree and JSON comparison scripts rely on deepdiff for underlying comparisons.
Side effects
Travis CI
To get Cram tests to work as expected with Travis CI, I needed to modify the Travis config to install Python dev dependencies with
pip
instead ifpip3
. This change ensures that the dev dependencies are installed in the CI’s conda environment instead of the global Python environment and allows Python commands executed in Cram files to access dev dependencies.This PR also updates the Travis config to run Cram along with pytest and the Snakemake builds.
Random seed flag for augur refine
In an attempt to produce consistent augur refine outputs from run to run (even locally on my laptop), I added a
--seed
flag that allows the user to set numpy’s global random seed to a specific value. This flag is only useful for this kind of testing or for debugging. It also doesn’t completely fulfill its purpose since TreeTime still produces overly stochastic outputs with the example Zika data even when the random seed is fixed.I’ve kept this flag here in case this pattern becomes helpful for other augur commands.