Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added xarray dataset accessor to record axis validation #136

Merged
merged 12 commits into from
Jan 16, 2023
Merged
Prev Previous commit
Next Next commit
Removed accessor tests from test_axes and updated validate_dataarray …
…test to check validation_dict return
  • Loading branch information
davidorme committed Dec 20, 2022
commit c0b568183b1bbf86d358b72b749bca908856738c
30 changes: 10 additions & 20 deletions tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,36 +118,42 @@ def test_AxisValidator_methods(new_axis_validators, fixture_data):


@pytest.mark.parametrize(
argnames=["value", "exp_err", "exp_msg"],
argnames=["value", "exp_val_dict", "exp_err", "exp_msg"],
argvalues=[
pytest.param(
DataArray(data=np.arange(4), dims=("cell_id")),
{"spatial": "Spat_CellId_Dim_Any", "testing": None},
does_not_raise(),
None,
id="Match found",
),
pytest.param(
DataArray(data=np.arange(4), dims=("x")),
{},
pytest.raises(ValueError),
"DataArray uses 'spatial' axis dimension names but "
"does not match a validator: x",
id="Uses dims, no match",
),
pytest.param(
DataArray(data=np.arange(50), dims=("test")),
{},
pytest.raises(RuntimeError),
"Validators on 'testing' axis not mutually exclusive",
id="Bad validator setup",
),
pytest.param(
DataArray(data=np.arange(4), dims=("cell_identities")),
{"spatial": None, "testing": None},
does_not_raise(),
None,
id="No match found",
),
],
)
def test_validate_dataarray(new_axis_validators, fixture_data, value, exp_err, exp_msg):
def test_validate_dataarray(
new_axis_validators, fixture_data, value, exp_val_dict, exp_err, exp_msg
):
"""Test the validate_dataarray function.

This just checks the pass through and failure modes - the individual AxisValidator
Expand All @@ -158,28 +164,12 @@ def test_validate_dataarray(new_axis_validators, fixture_data, value, exp_err, e

# Decorate a mock function to test the failure modes
with exp_err as err:
value = validate_dataarray(value, grid=fixture_data.grid)

value, val_dict = validate_dataarray(value, grid=fixture_data.grid)
assert exp_val_dict == val_dict
if err is not None:
assert str(err.value) == exp_msg


def test_validate_CoreAxesAccessor(new_axis_validators, fixture_data):
"""Test the core_axis property functions correctly."""

from virtual_rainforest.core.axes import validate_dataarray

value = DataArray(data=np.arange(4), dims=("cell_id"))

value = validate_dataarray(value, grid=fixture_data.grid)

assert value.core_axes["spatial"] == "Spat_CellId_Dim_Any"
assert value.core_axes["testing"] is None

assert value.core_axes("spatial")
assert not value.core_axes("testing")


@pytest.mark.parametrize(
argnames=["grid_args", "darray", "exp_err", "exp_message", "exp_vals"],
argvalues=[
Expand Down