Test that ursa is running correctlyΒΆ

Ursa uses pytest in order to do unit testing for the outputs of various parts of the workflow from start to finish. We have created a test case based on the 2016 Sherpa fire, with a smaller area of interest that only covers a few of the outlets, so that the project runs in approximately 10 minutes on a typical laptop.

To run the test, navigate into the ursa/tests directory and execute:

source sherpa_test.sh

This script will setup, run, and test the sherpa-test example. After ursa completes, pytest will produce output that tells you the amount of tests that passed/failed, as well as a few other diagnostic numbers (which tests took the longest, how long the tests took).

The contents of sherpa-test.sh is as follows:

# Test Ursa using the 2016 Sherpa Fire.

# Create and navigate to an examples directory.
cd ../
mkdir examples
cd examples
conda activate ursa-env

# Remove the sherpa-test directory if it already exists.
rm -r -f sherpa-test

# Initialize a new ursa project called "sherpa-test"
ursa initialize sherpa-test

if [ ! -d "sherpa-test" ]; then # test that the director exists.
    echo "Ursa did not successfully initialize the sherpa-test example"
    echo "Navigate to ursa/examples and inspect the file"
    echo "failed_ursa_initialize_sherpa-test.log"
    echo "to determine where the failure occurred".
    echo "this usually occurs when there are internet connectivity issues."

    # put user back to where they started
    cd ../tests

else
    echo "Ursa successfully initialized the sherpa-test example"

    # Copy required data from the ursa/data/shr2016 directory into
    # the ursa/examples/sherpa-test/user-input directory
    cp ../data/shr2016/* sherpa-test/user-input/

    # Note that there are many ursa options to test
    # Refer to the user guide for details on each of these options.
    # If one wants to test most options, run this script with each 
    # of the three configuration files below.

    # This first example uses all of the external APIs.
    # cp ../data/shr2016/config_sherpa-test_options1.yml sherpa-test/config/config.yml

    # This second example uses none of the external APIs.
    # There are some other configuration differences.
    cp ../data/shr2016/config_sherpa-test_options2.yml sherpa-test/config/config.yml

    # The third example uses different configuration options.
    # cp ../data/shr2016/config_sherpa-test_options3.yml sherpa-test/config/config.yml

    # All three options should yield the same test result.

    # Enter the sherpa-test directory
    cd sherpa-test

    # Run ursa (this may take ~10 minutes)
    ursa run all


    if [ ! -e ".done" ]; then # .done created at the very end of the workflow
        echo "Ursa did not successfully complete the sherpa-test example"
        echo "Navigate to ursa/examples/sherpa-test directory and inspect the file"
        echo "snakemake_<date>_<time>.log"
        echo "to determine where the failure occurred".

        # put user back to where they started
        cd ../../tests

    else
        echo "Ursa successfully completed the sherpa-test example"

        # copy metadata and make sciencebase child item
        cp ../../data/shr2016/metadata.yml metadata
    	ursa export sciencebase
        ursa export plots

    	# Return to the tests directory
    	cd ../../tests

    	# Run pytest
    	pytest
    fi

fi