Writing tests for the testing framework - HopkinsIDD/cholera-mapping-pipeline GitHub Wiki

Get an API key

  1. Log into https://cholera-taxonomy.middle-distance.com/
  2. Scroll to the bottom of the page.
  3. Click the Account Button.
  4. Click the API key button
  5. Click Generate New API Key (this will print your API key to screen).

Setup Docker

You will need to get docker set up on your computer only once, and pull once each time the main branch is updated.

Download Docker

https://www.docker.com/products/docker-desktop

Pull Docker image

From a terminal, run

docker pull hopkinsidd/choleramappingpipeline:latest-dev

Mac Specific configuration

  1. Open Docker
  2. Click the gear icon in the upper right hand corner
  3. Click Resources from the menu on the left
  4. Ensure that Memory is at least 4GB (default on mac is 2GB). You may want to set more memory if you are doing larger tests, but at least 4GB is required for compiling the STAN model

To change the memory settings on Mac:

  • Open the docker application
  • Click the Gear icon in the upper right corner
  • Click the Resources tab
  • There should be sliders for different resources

Start a docker session

  1. Clone this repository in a local directory
  2. Run docker run -it -v <absolute path to local cholera-mapping-pipeline directory>:/home/app/cmp hopkinsidd/choleramappingpipeline:latest-dev

Making changes to files in cholera-mapping-pipeline

Any changes you make to files in your cholera-mapping-pipeline directory will also be made on docker and vice versa.

Run tests

  1. Some packages are not set up on docker yet
    • sudo apt install libxt-dev
    • Rscript -e 'install.packages(c("xfun", "kableExtra", "Cairo", "MCMCvis"))'
  2. Create environment variables for your api key and username
    • export CHOLERA_API_USERNAME=<your_email@wherever>
    • export CHOLERA_API_KEY=<your_api_key>
  3. Document and install taxdat
    • cd ~/cmp/packages/taxdat
    • Rscript -e 'devtools::document()'
    • Rscript -e 'install.packages(".", type = "source", repos = NULL)'
  4. Run tests
    • cd ~/cmp/packages/taxdat && Rscript -e 'devtools::test()'
    • cd ~/cmp/tests && Rscript testthat.R
    • cd ~/cmp/Analysis/R && Rscript run_test.R

Write your own tests

Start by making a copy of run_test.R as the basis for your test. There are lines you can modify (or remove) about how to create the different parts of your test case using the simulation framework. For some of the more complicated functions, only the default arguments are used and you'll need to use Rstudio's help or ? to see the rest of the arguments. There are examples of arguments for these functions in create_standardized_testing_data.R

Test case terminology

Covariates

  1. nonspatial: nonspatial==TRUE means the covariate is spatially varied in a random way.
  2. nontemporal: nontermpoal==TRUE means the covariate is termporally varied in a random way.
  3. spatially_smoothed: spatially_smoothed==TRUE means the covariate is spatially smoothed and covairate across different grid cells is correlated.
  4. temporally_smoothed: temporally_smoothed==TRUE means the covariate is termporally smoothed and covairate across different years is correlated.
  5. polygonal:
  6. radiating:
  7. constant