pytest-regressions plugin for xarray
Project description
A pytest-regressions plugin for identifying regressions in Xarray objects.
[!WARNING]
xarray-regressionsis in early development and might have breaking changes.
Install
pip install xarray-regressions
Usage
[!TIP] If you're unfamiliar with
pytest-regressions, check out their documentation first.
Once installed, this package registers a test fixture xarray_regression for detecting regressions in the data or metadata of xr.DataArray and xr.Dataset objects.
Say you have a function make_dataarray that should always return the same output:
import xarray as xr
def make_dataarray(name: str) -> xr.DataArray:
"""A dummy method that needs to be tested."""
return xr.DataArray(
np.full((2, 4, 3), 1),
dims=["variable", "y", "x"],
coords={
"variable": ["var1", "var2"],
"y": [1, 2, 3, 4],
"x": [1, 2, 3],
},
name=name,
attrs={"foo": "bar"},
)
Add the xarray_regression fixture to a new test and call the check method on the returned data array:
from xarray_regressions import XarrayRegressionFixture # Only used for type annotation
def test_make_dataarray(xarray_regression: XarrayRegressionFixture):
"""Test that the function always returns an identical xr.DataArray."""
da = make_dataarray(name="test_array")
xarray_regression.check(
da,
check_name=True,
check_attrs=True,
)
Running the test once will write da to a local NetCDF[^netcdf], and future test runs will compare da with the stored result. Values, dimensions, and coordinates are checked using xr.testing.assert_allclose to allow for minor floating point differences between systems, but can be tested for exact equality by specifying rtol=0 and atol=0. Names and attributes are checked separately. Encodings are not currently checked.
If make_dataarray(name="test_array") returns a different result in the future, the test will fail:
AssertionError: DataArray names are different. L: foo, R: test_array
Testing multiple objects
To test multiple objects in the same test, you can pass an obj_id argument to the check method. This will be appended to the basename (by default, the name of the test) so that each object is saved to a separate file.
def test_make_dataarray(xarray_regression: XarrayRegressionFixture):
"""Test that the function always returns an identical xr.DataArray."""
da1 = make_dataarray(name="test_array_1")
da2 = make_dataarray(name="test_array_2")
xarray_regression.check(da1, obj_id="da1", check_name=True)
xarray_regression.check(da2, obj_id="da2", check_name=True)
When adding new tests with multiple objects, the --regen-all flag can be helpful to avoid pytest-regressions aborting on the first missing file.
[^netcdf]: Because results are stored in NetCDF, all tested objects must be serializable.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xarray_regressions-0.0.3.tar.gz.
File metadata
- Download URL: xarray_regressions-0.0.3.tar.gz
- Upload date:
- Size: 48.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b989b81f80f6e05aa2952d27cda44fb21970acda8dae4159b9c706a68135d42a
|
|
| MD5 |
7d8f7c62deb8e3070d33c465446cc665
|
|
| BLAKE2b-256 |
825b8f51036464398f5f55f8e20dee6a4b57791fb3080650cac5aca105c9a9da
|
Provenance
The following attestation bundles were made for xarray_regressions-0.0.3.tar.gz:
Publisher:
publish.yaml on aazuspan/xarray-regressions
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xarray_regressions-0.0.3.tar.gz -
Subject digest:
b989b81f80f6e05aa2952d27cda44fb21970acda8dae4159b9c706a68135d42a - Sigstore transparency entry: 255744611
- Sigstore integration time:
-
Permalink:
aazuspan/xarray-regressions@15970dc6006369ac3dae053b89d3c180996a829c -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/aazuspan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@15970dc6006369ac3dae053b89d3c180996a829c -
Trigger Event:
push
-
Statement type:
File details
Details for the file xarray_regressions-0.0.3-py3-none-any.whl.
File metadata
- Download URL: xarray_regressions-0.0.3-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
752e00b340680c26428a625df2daa66a676b5d2386358a724026912eaaafda03
|
|
| MD5 |
5401c0153a24d97e751e631a9a4e2608
|
|
| BLAKE2b-256 |
93f03b681f530bd9f38cd32ed7a9233f7ac9a2278672ea4cd0582d90b8fa2a44
|
Provenance
The following attestation bundles were made for xarray_regressions-0.0.3-py3-none-any.whl:
Publisher:
publish.yaml on aazuspan/xarray-regressions
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xarray_regressions-0.0.3-py3-none-any.whl -
Subject digest:
752e00b340680c26428a625df2daa66a676b5d2386358a724026912eaaafda03 - Sigstore transparency entry: 255744613
- Sigstore integration time:
-
Permalink:
aazuspan/xarray-regressions@15970dc6006369ac3dae053b89d3c180996a829c -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/aazuspan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@15970dc6006369ac3dae053b89d3c180996a829c -
Trigger Event:
push
-
Statement type: