Exemplo n.º 1
0
    def it_knows_the_index_of_its_cube_in_the_cube_set(self, cube_):
        cube_.cube_index = 42
        cube_partition = CubePartition(cube_)

        cube_index = cube_partition.cube_index

        assert cube_index == 42
Exemplo n.º 2
0
    def and_it_constructs_a_nub_for_a_0D_cube(self, request, cube_):
        cube_.ndim = 0
        _Nub_ = class_mock(request, "cr.cube.cubepart._Nub")

        nub = CubePartition.factory(cube_)

        _Nub_.assert_called_once_with(cube_)
        assert nub is _Nub_.return_value
Exemplo n.º 3
0
 def it_knows_the_only_larger_flag_state_to_help(self,
                                                 _transforms_dict_prop_,
                                                 pw_indices_dict,
                                                 expected_value):
     _transforms_dict_prop_.return_value = {
         "pairwise_indices": pw_indices_dict
     }
     assert CubePartition(None)._only_larger == expected_value
Exemplo n.º 4
0
    def it_interprets_the_provided_alpha_values_to_help(
            self, pw_indices_dict, expected_value):
        cube_partition = CubePartition(None,
                                       {"pairwise_indices": pw_indices_dict})

        alpha_values = cube_partition._alpha_values

        assert alpha_values == expected_value
Exemplo n.º 5
0
    def but_it_constructs_a_strand_for_a_2D_cube_when_ca_as_0th(
            self, request, cube_):
        cube_.ndim = 2
        _Strand_ = class_mock(request, "cr.cube.cubepart._Strand")

        strand = CubePartition.factory(cube_, 0, ca_as_0th=True)

        _Strand_.assert_called_once_with(cube_, None, None, True, 0, 0)
        assert strand is _Strand_.return_value
Exemplo n.º 6
0
    def and_it_constructs_a_strand_for_a_1D_cube(self, request, cube_):
        cube_.ndim = 1
        _Strand_ = class_mock(request, "cr.cube.cubepart._Strand")

        strand = CubePartition.factory(cube_, 42, {"trans": "forms"}, 1000,
                                       False, 10)

        _Strand_.assert_called_once_with(cube_, {"trans": "forms"}, 1000,
                                         False, 42, 10)
        assert strand is _Strand_.return_value
Exemplo n.º 7
0
    def but_it_raises_on_invalid_alpha_values(self, pw_indices_dict,
                                              exception_type,
                                              expected_message):
        cube_partition = CubePartition(None,
                                       {"pairwise_indices": pw_indices_dict})

        with pytest.raises(exception_type) as e:
            cube_partition._alpha_values

        assert str(e.value) == expected_message
Exemplo n.º 8
0
 def partitions(self):
     """Sequence of _Slice, _Strand, or _Nub objects from this cube-result."""
     return tuple(
         CubePartition.factory(
             self,
             slice_idx=slice_idx,
             transforms=self._transforms_dict,
             population=self._population,
             ca_as_0th=self._ca_as_0th,
             mask_size=self._mask_size,
         ) for slice_idx in self._slice_idxs)
Exemplo n.º 9
0
    def it_constructs_a_slice_with_its_factory_for_a_2D_cube(
            self, request, cube_):
        cube_.ndim = 2
        _Slice_ = class_mock(request, "cr.cube.cubepart._Slice")

        slice_ = CubePartition.factory(cube_, 42, {"trans": "forms"}, 1000,
                                       False, 10)

        _Slice_.assert_called_once_with(cube_, 42, {"trans": "forms"}, 1000,
                                        10)
        assert slice_ is _Slice_.return_value
Exemplo n.º 10
0
    def it_can_evaluate_a_measure_expression(self, request):
        single_sided_moving_avg_smoother_ = instance_mock(
            request,
            SingleSidedMovingAvgSmoother,
            values=[[0.1, 0.2], [0.3, 0.4]])
        SingleSidedMovingAvgSmoother_ = class_mock(
            request,
            "cr.cube.cubepart.SingleSidedMovingAvgSmoother",
            return_value=single_sided_moving_avg_smoother_,
        )
        measure_expr = {
            "function": "one_sided_moving_avg",
            "base_measure": "col_percent",
            "window": 2,
        }
        cube_partition = CubePartition(None, None)

        values = cube_partition.evaluate(measure_expr)

        SingleSidedMovingAvgSmoother_.assert_called_once_with(
            cube_partition, measure_expr)
        assert values == [[0.1, 0.2], [0.3, 0.4]]
Exemplo n.º 11
0
 def it_provides_the_transforms_dict_to_help(self, transforms,
                                             expected_value):
     """Handles defaulting of transforms arg."""
     assert CubePartition(None,
                          transforms)._transforms_dict == expected_value
Exemplo n.º 12
0
 def it_knows_the_secondary_alpha_value_to_help(self, _alpha_values_prop_,
                                                alpha_values,
                                                expected_value):
     _alpha_values_prop_.return_value = alpha_values
     assert CubePartition(None)._alpha_alt == expected_value
Exemplo n.º 13
0
 def it_knows_the_primary_alpha_value_to_help(self, _alpha_values_prop_):
     """alpha is the primary confidence-interval threshold specified by the user."""
     _alpha_values_prop_.return_value = (0.042, 0.084)
     assert CubePartition(None)._alpha == 0.042