Skip to content

Commit

Permalink
Add tests for utils
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvothecoder committed Aug 27, 2024
1 parent fe334a7 commit cf56c47
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import xarray as xr

from tests.fixtures import generate_dataset
from xcdat.utils import compare_datasets, mask_var_with_weight_threshold, str_to_bool
from xcdat.utils import (
_validate_min_weight,
compare_datasets,
mask_var_with_weight_threshold,
str_to_bool,
)


class TestCompareDatasets:
Expand Down Expand Up @@ -231,3 +236,23 @@ def test_returns_mask_var_with_temporal_min_weight_of_0(self):
)

xr.testing.assert_allclose(result, expected)


class TestValidateMinWeight:
def test_pass_None_returns_0(self):
result = _validate_min_weight(None)

assert result == 0

def test_returns_error_if_less_than_0(self):
with pytest.raises(ValueError):
_validate_min_weight(-1)

def test_returns_error_if_greater_than_1(self):
with pytest.raises(ValueError):
_validate_min_weight(1.1)

def test_returns_valid_min_weight(self):
result = _validate_min_weight(1)

assert result == 1

0 comments on commit cf56c47

Please sign in to comment.