input4mips_validation.testing#
input4mips_validation.testing
#
Support for testing
This covers (or could cover) both testing (e.g. comparing objects) and generation of test/example instances.
create_files_in_tree(variable_ids, units, fixed_fields, tree_root, cvs, dataset_category=None)
#
Create test files in a tree
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_ids
|
Collection[str]
|
Variable IDs to write in the created files |
required |
units
|
Collection[str]
|
Units to use in/assign to the created files |
required |
fixed_fields
|
Collection[bool]
|
Should the created files be fixed field files? For example, cell area files. |
required |
tree_root
|
Path
|
Root of the tree in which to write the files |
required |
cvs
|
Input4MIPsCVs
|
CVs to use when writing the files |
required |
dataset_category
|
Optional[str]
|
Dataset category to apply to the created files |
None
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
List of created files |
Source code in src/input4mips_validation/testing.py
create_files_in_tree_return_info(tree_root, **kwargs)
#
Create files in tree, returning information about them useful for testing
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree_root
|
Path
|
Root of the tree in which to write the files |
required |
**kwargs
|
Any
|
Passed to
|
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, str]]
|
Information about the files useful for testing |
Source code in src/input4mips_validation/testing.py
get_valid_ds_min_metadata_example(variable_id='siconc', units='%', unit_registry=None, fixed_field=False)
#
Get an example of a valid dataset and associated minimum metadata
The results can be combined to create a
Input4MIPsDataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_id
|
str
|
Variable ID to apply to the dataset |
'siconc'
|
units
|
str
|
Units to attach to the dataset |
'%'
|
unit_registry
|
Union[UnitRegistry, None]
|
Unit registry to use. If not supplied, we retrieve it with pint.get_application_registry. |
None
|
fixed_field
|
bool
|
Should we return a fixed field dataset? |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
dataset |
Dataset
|
Example valid dataset |
minimum_metadata |
Input4MIPsDatasetMetadataDataProducerMinimum
|
Example minimum metadata |
Source code in src/input4mips_validation/testing.py
get_valid_ds_min_metadata_example_climatology(variable_id='co2', units='ppm', unit_registry=None)
#
Get an example of a valid climatology dataset and associated minimum metadata
The results can be combined to create a
Input4MIPsDataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_id
|
str
|
Variable ID to apply to the dataset |
'co2'
|
units
|
str
|
Units to attach to the dataset |
'ppm'
|
unit_registry
|
Union[UnitRegistry, None]
|
Unit registry to use. If not supplied, we retrieve it with pint.get_application_registry. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dataset |
Dataset
|
Example valid dataset |
minimum_metadata |
Input4MIPsDatasetMetadataDataProducerMinimum
|
Example minimum metadata |
Source code in src/input4mips_validation/testing.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 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 | |
get_valid_out_path_and_disk_ready_ds(variable_name='mole_fraction_of_carbon_dioxide_in_air', time_encoding=None, cv_source='gh:v6.6.0', root_data_dir=Path('/to/somewhere'))
#
Get a valid ouput path and disk-ready dataset
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str
|
Variable to write in the dataset |
'mole_fraction_of_carbon_dioxide_in_air'
|
time_encoding
|
dict[str, Any] | None
|
Encoding to use with the time axis If not supplied, we use basic defaults. |
None
|
cv_source
|
str | Input4MIPsCVs
|
Source for the CVs. |
'gh:v6.6.0'
|
root_data_dir
|
Path
|
Root data directory to use when generating the output path. |
Path('/to/somewhere')
|
Returns:
| Type | Description |
|---|---|
tuple[Path, Dataset]
|
Valid output path and disk-ready dataset |