climate_ref.testing
#
Testing utilities for running and validating diagnostic test cases.
This module provides: - Path resolution for package-local test data (catalogs, regression data) - Sample data fetching utilities - TestCaseRunner for executing diagnostics with test data - Result validation helpers
TEST_DATA_DIR = _determine_test_directory()
module-attribute
#
Path to the centralised test data directory (for sample data).
TestCaseRunner
#
Helper class for running diagnostic test cases.
This runner handles: - Running the diagnostic with pre-resolved datasets - Setting up the execution definition
Source code in packages/climate-ref/src/climate_ref/testing.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
run(diagnostic, test_case_name='default', output_dir=None, clean=False)
#
Run a specific test case for a diagnostic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagnostic
|
Diagnostic
|
The diagnostic to run |
required |
test_case_name
|
str
|
Name of the test case to run (default: "default") |
'default'
|
output_dir
|
Path | None
|
Optional output directory for results |
None
|
clean
|
bool
|
If True, delete the output directory before running |
False
|
Returns:
| Type | Description |
|---|---|
ExecutionResult
|
The result of running the diagnostic |
Raises:
| Type | Description |
|---|---|
NoTestDataSpecError
|
If the diagnostic has no test_data_spec |
TestCaseNotFoundError
|
If the test case doesn't exist |
DatasetResolutionError
|
If datasets cannot be resolved |
Source code in packages/climate-ref/src/climate_ref/testing.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
fetch_sample_data(force_cleanup=False, symlink=False)
#
Fetch the sample data for the given version.
The sample data is produced in the Climate-REF/ref-sample-data repository. This repository contains decimated versions of key datasets used by the diagnostics packages. Decimating these data greatly reduces the data volumes needed to run the test-suite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force_cleanup
|
bool
|
If True, remove any existing files |
False
|
symlink
|
bool
|
If True, symlink in the data otherwise copy the files The symlink approach is faster, but will fail when running with a non-local executor because the symlinks can't be followed. |
False
|
Source code in packages/climate-ref/src/climate_ref/testing.py
validate_result(diagnostic, config, result)
#
Asserts the correctness of the result of a diagnostic execution
This should only be used by the test suite as it will create a fake database entry for the diagnostic execution result.