Skip to content

Commit

Permalink
Merge 9dc2229 into 6056085
Browse files Browse the repository at this point in the history
  • Loading branch information
slobodan-ilic committed Jan 21, 2019
2 parents 6056085 + 9dc2229 commit 6440464
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cr/cube/crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def as_array(

return self._drop_mr_cat_dims(array)

@lazyproperty
def can_compare_pairwise(self):
return all(slice_.can_compare_pairwise for slice_ in self.slices)

def count(self, weighted=True):
"""Return numberic count of rows considered for cube response."""
return self._measures.weighted_n if weighted else self._measures.unweighted_n
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/test_crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
_UnweightedCountMeasure,
_WeightedCountMeasure,
)
from cr.cube.cube_slice import CubeSlice
from cr.cube.dimension import AllDimensions, _ApparentDimensions, Dimension
from cr.cube.enum import DIMENSION_TYPE as DT

Expand All @@ -30,6 +31,12 @@


class DescribeCrunchCube(object):
def it_can_compare_pariwise(self, can_compare_pairwise_fixture, slices_prop_):
slices, can_compare_pairwise = can_compare_pairwise_fixture
slices_prop_.return_value = slices
cube = CrunchCube(None)
assert cube.can_compare_pairwise is can_compare_pairwise

def it_provides_a_default_repr(self):
cube = CrunchCube(None)
repr_ = repr(cube)
Expand Down Expand Up @@ -232,6 +239,22 @@ def it_provides_access_to_its_Measures_object_to_help(

# fixtures -------------------------------------------------------

@pytest.fixture(
params=[
([True, True, True], True),
([False, True, True], False),
([True, True, False], False),
([False, False, False], False),
]
)
def can_compare_pairwise_fixture(self, request):
slices_can_compare_pairwise, cube_can_compare_pairwise = request.param
slices = [
instance_mock(request, CubeSlice, can_compare_pairwise=can_compare_pairwise)
for can_compare_pairwise in slices_can_compare_pairwise
]
return slices, cube_can_compare_pairwise

@pytest.fixture(
params=[
# ---0 - CAT x CAT---
Expand Down Expand Up @@ -448,6 +471,10 @@ def is_weighted_fixture(self, request):
def AllDimensions_(self, request):
return class_mock(request, "cr.cube.crunch_cube.AllDimensions")

@pytest.fixture
def slices_prop_(self, request):
return property_mock(request, CrunchCube, "slices")

@pytest.fixture
def all_dimensions_(self, request):
return instance_mock(request, AllDimensions)
Expand Down

0 comments on commit 6440464

Please sign in to comment.