Testing and GitHub Actions - rosepearson/GeoFabrics GitHub Wiki

Tests exist for stand alone functionality (i.e. fetch lidar), and complete processing chain (i.e. creating a DEM from LiDAR files within a shapefile). A benchmark_dem.nc is uploaded for each test when a DEM is generated. This is stored using git LTS as these file are not human readable.

.env file for retrieving API keys

A .env file under the root repository directory is used to store API key information. This is not versions as the API keys should be kept secure. You will need to create one if running tests locally. The contents of test API keys is stored securely in GitHub as a secrete and retrieved and used to create a .env file as part of the GitHub Actions workflow.

The .env file contents looks like:

LINZ_API="YOUR_API_KEY_STRING_HERE"
LRIS_API="YOUR_API_KEY_STRING_HERE"

Automated testing

Github Actions are used to run:

Check the Actions tab after you push to check if your tests run successfully.

Testing

Miniconda from the GitHub Actions marketplace is used to install the package dependencies. Linting with Flake8 and testing with PyTest is then performed. Several tests require an API key. This is stored as a GitHub secret and accessed by the workflow.

See Package Requirements for details about the required API tokens, and .env file for retrieving API keys for details about it's structure. This blog was used to create the secret string directly from an .env file, and to set the GitHub Actions workflow to create a local instance of the .env file for each workflow run. Remove any new-line characters or spaces in the string before adding it as a secret.

Running tests locally

Tests (i.e test_processor_remote_all_westport) can require a LINZ API token. Create an API token using the instructions under the Requirements section then store it in an .env file under root.

LINZ_API="COPY_YOUR_API_KEY_HERE"

In the conda environment defined in the root\environment_[windows|linux].yml, run the following in the repository root folder:

  1. to run individual tests call python -m tests.test_processor_local_files.test_processor_local_files, etc.
  2. to run all tests call python -m pytest

Test logs are written out to test.log in each test folder.