Unit Testing
Unit tests are described in hdp/tests and rely on the hdp.utils.generate_test_ functions to generate “mock” datasets. The same functions are described in the Quick Start Guide but are called with parameters add_noise=False and grid_shape=(2, 3) for reproducibility and less computational overhead. The grid shape was chosen to mimic real datasets which almost always span multiple latitude/longitude coordinates. By setting the grid shape to two different lengths (as opposed to a square), we can better isolate bugs that originate from coordinate-handling.
Unit tests are automatically run by GitHub Actions when a commit is made to any Python file in the project. The workflow is available in .github/workflows/unit_tests.yml
test_utils.py
Testing for all hdp.utils` functions but primarily to ensure that the sample data generated by the hdp.utils.generate_test_ functions are being created as expected.
test_workflow.py
Testing for the end-to-end workflow from formatting input data to creating figure decks. A PyTest fixture is used to test saving out the figure deck. Some basic assertions are made on the validity of the heatwave metric data based on their mathematical definitions, however no graphical tests for the quality of automated figure deck exist at this time.
test_heatwave*.py
Testing for the heatwave metrics individually. These tests feature a series of cases designed to evaluate both general and edge cases. They apply the numba-compiled metric functions featured in hdp.metric to one-dimensional arrays that effectively simulate individual timeseries. In practice, the HDP scales these functions up to execute in parallel across multiple dimensions (this is tested in test_workflow.py). However, since this process is embarrassingly parallel (no data is exchanged between timeseries), validity can (and should) be tested at a one-dimensional scale (as it would be cumbersome to hand-check multidimensional arrays).
test_index_heatwaves.py
Testing for the indexing algorithm that applies the heatwave definition against the boolean array generated after comparing the heat measure against the baseline threshold. This algorithm expects a timeseries of 1s and 0s that indicate whether a day exceeds to the given threshold. It then applies the heatwave definition to determine which days constitute heatwaves. In practice, the HDP scales this up in the same way that metrics are scaled up so testing is similarly done on one-dimensional arrays to ensure validity.