Skip to content

Commit

Permalink
fix: add unit test for CubeSet._is_numeric_mean
Browse files Browse the repository at this point in the history
  • Loading branch information
scanny committed May 4, 2020
1 parent a944dae commit 5aa58b3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cr/cube/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def _is_multi_cube(self):
"""True if more than one cube-response was provided on construction."""
return len(self._cube_responses) > 1

@lazyproperty
def _is_numeric_mean(self):
"""True when CubeSet is special-case "numeric-mean" case requiring inflation.
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,29 @@ def it_provides_access_to_its_Cube_objects_to_help(self, _iter_cubes_, cube_):

assert cubes == (cube_, cube_, cube_)

@pytest.mark.parametrize(
("is_multi_cube", "cube_0_ndim", "expected_value"),
((False, 1, False), (False, 0, False), (True, 1, False), (True, 0, True)),
)
def it_knows_whether_it_is_numeric_mean_to_help(
self,
_is_multi_cube_prop_,
is_multi_cube,
Cube_,
cube_,
cube_0_ndim,
expected_value,
):
_is_multi_cube_prop_.return_value = is_multi_cube
cube_.ndim = cube_0_ndim
Cube_.return_value = cube_
cube_set = CubeSet(({"cube": 0}, {"cube": 1}), None, None, None)

is_numeric_mean = cube_set._is_numeric_mean

assert Cube_.call_args_list == ([call({"cube": 0})] if is_multi_cube else [])
assert is_numeric_mean == expected_value

def it_constructs_its_sequence_of_cube_objects_to_help(
self, request, Cube_, _is_numeric_mean_prop_
):
Expand Down Expand Up @@ -263,6 +286,10 @@ def cube_(self, request):
def _cubes_prop_(self, request):
return property_mock(request, CubeSet, "_cubes")

@pytest.fixture
def _is_multi_cube_prop_(self, request):
return property_mock(request, CubeSet, "_is_multi_cube")

@pytest.fixture
def _is_numeric_mean_prop_(self, request):
return property_mock(request, CubeSet, "_is_numeric_mean")
Expand Down

0 comments on commit 5aa58b3

Please sign in to comment.