-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #253 from jmccreight/doc_test_data_autotest
update test_data and autotest READMEs
- Loading branch information
Showing
7 changed files
with
485 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,126 @@ | ||
# Autotest | ||
|
||
## Usage | ||
|
||
``` | ||
cd autotest | ||
pytest | ||
``` | ||
Pytest options can be explored via `pytest --help`. | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
**Table of Contents** | ||
|
||
- [Autotest](#autotest) | ||
- [Test data](#test-data) | ||
- [Usage](#usage) | ||
- [domain_yaml details](#domain_yaml-details) | ||
- [Path resolution](#path-resolution) | ||
- [Answers for domain tests](#answers-for-domain-tests) | ||
|
||
## Developer | ||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
||
This is how the pywatershed package tests itself. | ||
# Autotest | ||
|
||
The test suite consists both | ||
* stand alone tests, and | ||
* domain tests | ||
Autotest provides the test suite for pywatershed. The tests include | ||
both | ||
* stand alone tests, and | ||
* domain tests. | ||
|
||
Stand alone tests do not require any input files or output files besides what | ||
is supplied in the testing framework. These tests generally run quickly | ||
(e.g. testing basic logic of a class or type requirements or results). | ||
|
||
Domain tests require input or output files for an NHM domain. These tests | ||
scale with the size or number of HRUs in a domain. The test suite takes | ||
arguments related to domain tests: | ||
arguments related to domain tests which are described in sthe usage section below. | ||
|
||
## Test data | ||
The majority of tests are domain tests (as of writing this). And the vast majority of the | ||
domain test data must be generated by running binaries included in the repository BEFORE | ||
running the autotests. | ||
|
||
To generate the test data, run the following command from `autotest/`: | ||
|
||
```shell | ||
python generate_test_data.py -n=auto | ||
``` | ||
|
||
This command should generally be sufficient but more options are available, including | ||
passing of options to pytest. Run `python generate_test_data.py --help` for more details. | ||
For example, if you are in a hurry to run and test a single domain you may restrict | ||
(or expand) the domains processed with the `--domains` option. To get verbose output | ||
from pytest, pass `-vv`. | ||
|
||
Using the above command allows the autotests to provide checks that the test data in | ||
`test_data/` have been generated and have been generated by the current version of | ||
pywatershed. These checks are meant to avoid gross errors with autotesting but will | ||
not cover ever possible testing situation. When in doubt about tests, it's always best | ||
practice to start over by re-generating the test data. | ||
|
||
There are temporary situations where errors caused by checking for test data are | ||
unwarranted and in those cases, disabling the errors by editing `autotest/conftest.py` | ||
is the temporary solution. | ||
|
||
Please see [`test_data/README.md`](../test_data/README.md) for additional details on how | ||
to generate the test data. | ||
|
||
## Usage | ||
|
||
``` | ||
cd autotest | ||
pytest -n=auto -vv | ||
``` | ||
--domain_yaml=DOMAIN_YAML | ||
YAML file(s) for indiv domain tests. You can pass multiples of this argument. Default | ||
value (not shown here) is --domain_yaml=../test_data/drb_2yr/drb_2yr.yaml. | ||
|
||
Pytest options can be explored via `pytest --help`. Custom options for | ||
pywatershed are buried down in the output of this call for help, these are: | ||
|
||
``` | ||
Custom options: | ||
--domain_yaml=DOMAIN_YAML | ||
YAML file(s) for indiv domain tests. You can pass multiples of this | ||
argument. Default value (not shown here) is | ||
--domain_yaml=../test_data/drb_2yr/drb_2yr.yaml | ||
--print_ans Print results and assert False for all domain tests | ||
--all_domains Run all test domains | ||
``` | ||
|
||
Note that the `--domain_yaml` argument may be repeated within a single call to test multiple | ||
domains in a single pytest. | ||
The default domain tested is `drb_2yr`. All domains present in `test_data/` | ||
can be tested using `--all_domains`. Requesting a specific domain or multiple | ||
domains is done by passing one or more `--domain_yaml` arguments. | ||
|
||
The `domain_yaml` file is an *evolving* set of data that includes static domain | ||
inputs (e.g. CBH forcing files, parameter files), static or reference model | ||
output (from PRMS/NHM), and the answers to domain tests. | ||
## domain_yaml details | ||
|
||
Examples of `domain_yaml` files can be found in, for example, in | ||
`pywatershed/test_data/drb_2yr/drb_2yr.yaml` | ||
and | ||
`pywatershed/test_data/conus_2yr/conus_2yr.yaml`. | ||
This section is about creating or working with the domain_yaml file when | ||
writing tests. | ||
|
||
The `domain_yaml` file provides information to the autotests. The domain_yaml | ||
files for a domain directory `somewhere/` will be `somewhere/somewhere.yaml`. | ||
This YAML file includes paths to static domain inputs (e.g. CBH forcing files, | ||
parameter files), paths to static or reference model output (from PRMS/NHM), | ||
and the answers to domain tests. Examples of `domain_yaml` files can be found | ||
in, each domain. | ||
|
||
### Domain inputs | ||
These are specific files for a specific model domain (e.g. the Delaware River Basin, | ||
or the CONUS NHM, etc). The files are paths and are to be specified as either | ||
* relative paths: relative to the location of the yaml file | ||
in which the path is appearing | ||
* absolute paths: use absolute paths (for some machine and potentially user) | ||
The examples listed above demonstrate use of both relative and absolute paths. | ||
Some details on the contents of the YAML file are given below. | ||
|
||
### Path resolution | ||
The test configuration for autotest (`autotest/conftest.py`) provides special | ||
path resolution relative to the `domain_yaml` file for paths specified in a | ||
list in that file: | ||
|
||
``` | ||
["param_file", "control_file", "cbh_nc", "prms_run_dir", "prms_output_dir",] | ||
``` | ||
|
||
Domain inputs are generally created by scripts run in `test_data/scripts`. The | ||
`drb_2yr` case shows the relationship between the prms binary, the input files, | ||
and the output files. These scripts help maintain sanity when generating new | ||
files for domain tests. | ||
Additional fields can be added to this list to provide path resolution for new | ||
fields in the YAML file. | ||
|
||
|
||
### Answers for domain tests | ||
Tests have objectively correct answers. The answer key is stored in the yaml in | ||
top-level attribute/key called `test_ans`. This can be seen in the examples | ||
listed above. This attibute has a sub-attributes for each file with domain | ||
tests in `autotest/test_*py` (the text `test_` and `.py` is dropped in the | ||
yaml reference). Below this, each file has named tests attributes which in turn | ||
potentially have named cases/keys when iterated with other fixtures (such as | ||
variables or types). | ||
|
||
The tests answers for a given test are output of some kind of summary statistic | ||
or other kind of reduction performed on data in memory. The answers vary with | ||
domain and are most easily collected by running the tests themselves while | ||
verifying accuracy manually when putting the answers into the domain yaml file. | ||
|
||
For convenience, a user can select to print the answers at run/test time using | ||
the `--print_ans` argument when running ptest. This prints the answer for | ||
domain tests and always asserts False after doing so for each test in a file. | ||
This option aids in conctruction of the tests_ans section of the domain | ||
yaml file for new domains or when extending tests on existing domains. Running | ||
`pytest -s ...` prints output in a format that can be copied to the yaml and | ||
edited quickly to get new test results enshrined in the answer key. | ||
Certain tests have answers stored in the domain YAML. This "answer key" is | ||
stored in the top-level key `test_ans`. This can be seen in the examples | ||
listed above. Generally, for a autotest `test_x.py` the key "x" will be | ||
provided below `test_ans` and below it will be what ever data is used in | ||
that test. | ||
|
||
These tests answers for a given test are typically a summary statistic | ||
performed on model data in memory. The answers vary with domain and | ||
are most easily collected by running the tests themselves while | ||
verifying accuracy of the test through expert judgement. The answers | ||
enshrined in the domain YAML indicate when test results change. Because | ||
test results change from time to time, a convenience utility function, | ||
`assert_or_print` is provided in `utils.py`. Using this function allows | ||
the option `--print_ans -s` (note that `-s` prints output to the terminal) | ||
to be passed at run time to print all the new values that should be | ||
updated into the domain YAML. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.