diff --git a/setup.cfg b/setup.cfg index 8982989f8..5df615563 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,4 @@ [tool:pytest] -python_classes = Test Describe -python_files = test_*.py -python_functions = test_ it_ they_ but_ and_it_ testpaths = tests diff --git a/tests/integration/test_collator.py b/tests/integration/test_collator.py index d7d1de32c..0d42dcbdc 100644 --- a/tests/integration/test_collator.py +++ b/tests/integration/test_collator.py @@ -15,7 +15,7 @@ from ..unitutil import instance_mock, property_mock -class DescribeExplicitOrderCollator: +class TestExplicitOrderCollator: """Partial-integration test suite for `ExplicitOrderCollator` object.""" @pytest.mark.parametrize( @@ -30,7 +30,7 @@ class DescribeExplicitOrderCollator: ((9, 3, 7), [7], (), (2, 0, 1)), ), ) - def it_knows_the_display_order_for_a_dimension( + def test_it_knows_the_display_order_for_a_dimension( self, request, element_ids, order, anchors, expected_value ): subtotals_ = [instance_mock(request, _Subtotal, anchor=a) for a in anchors] @@ -55,7 +55,7 @@ def it_knows_the_display_order_for_a_dimension( ) -class DescribePayloadOrderCollator: +class TestPayloadOrderCollator: """Partial-integration test suite for `PayloadOrderCollator` object.""" @pytest.mark.parametrize( @@ -66,7 +66,7 @@ class DescribePayloadOrderCollator: ((), ("bottom", 3, 3, "top"), (-1, -4, -3, -2)), ), ) - def it_knows_the_display_order_for_a_dimension( + def test_it_knows_the_display_order_for_a_dimension( self, request, element_ids, anchors, expected_value ): subtotals_ = [instance_mock(request, _Subtotal, anchor=a) for a in anchors] @@ -95,7 +95,7 @@ def it_knows_the_display_order_for_a_dimension( ((), ("bottom", 3, 3, "top"), ("ins_4", "ins_2", "ins_3")), ), ) - def it_knows_the_payload_order_for_a_dimension( + def test_it_knows_the_payload_order_for_a_dimension( self, request, element_ids, anchors, expected_value ): subtotals_ = [ @@ -129,7 +129,7 @@ def it_knows_the_payload_order_for_a_dimension( assert payload_order == expected_value -class DescribeSortByValueCollator: +class TestSortByValueCollator: """Partial-integration test suite for `SortByValueCollator` object.""" @pytest.mark.parametrize( @@ -153,7 +153,7 @@ class DescribeSortByValueCollator: ("A", [4], [1], (10, 30, 20, 40), (0, 3), (2, 1, -1, -2)), ), ) - def it_knows_the_display_order_for_a_dimension( + def test_it_knows_the_display_order_for_a_dimension( self, order, xtop, xbot, element_vals, empty_idxs, expected_value ): subtot_vals = [60, 40] @@ -205,7 +205,7 @@ def it_knows_the_display_order_for_a_dimension( ("A", [4], [1], (10, 30, 20, 40), (0, 3), (2, 1, "ins_2", "ins_1")), ), ) - def it_knows_the_display_order_for_a_dimension_in_bogus_id_fmt( + def test_it_knows_the_display_order_for_a_dimension_in_bogus_id_fmt( self, request, order, xtop, xbot, element_vals, empty_idxs, expected_value ): subtot_vals = [60, 40] diff --git a/tests/integration/test_cube.py b/tests/integration/test_cube.py index b36899e87..60b2c8b0e 100644 --- a/tests/integration/test_cube.py +++ b/tests/integration/test_cube.py @@ -22,10 +22,10 @@ ) -class DescribeIntegratedCube: +class TestIntegratedCube: """Integration-test suite for `cr.cube.cube.Cube` object.""" - def it_provides_values_for_cat_x_cat(self): + def test_it_provides_values_for_cat_x_cat(self): cube = Cube(CR.CAT_X_CAT) assert cube.__repr__() == "Cube(name='v4', dimension_types='CAT x CAT')" @@ -54,14 +54,16 @@ def it_provides_values_for_cat_x_cat(self): (CR.LOGICAL_UNIVARIATE, (DT.LOGICAL,)), ), ) - def it_provides_access_to_its_dimensions(self, cube_response, expected_dim_types): + def test_it_provides_access_to_its_dimensions( + self, cube_response, expected_dim_types + ): cube = Cube(cube_response) dimension_types = tuple(d.dimension_type for d in cube.dimensions) assert dimension_types == expected_dim_types - def it_provides_array_for_single_valid_cat_CAT_X_MR(self): + def test_it_provides_array_for_single_valid_cat_CAT_X_MR(self): """No pruning needs to happen, because pruning is based on unweighted counts: >>> cube.unweighted_counts array([[[0, 108], @@ -85,7 +87,7 @@ def it_provides_array_for_single_valid_cat_CAT_X_MR(self): slice_ = Cube(CR.CAT_X_MR_SENTRY, transforms=transforms).partitions[0] np.testing.assert_array_equal(slice_.counts, np.array([[0, 0, 0]])) - def it_provides_pruned_array_for_CA_CAT_x_CA_SUBVAR(self): + def test_it_provides_pruned_array_for_CA_CAT_x_CA_SUBVAR(self): transforms = { "rows_dimension": {"prune": True}, "columns_dimension": {"prune": True}, @@ -104,7 +106,7 @@ def it_provides_pruned_array_for_CA_CAT_x_CA_SUBVAR(self): ), ) - def it_provides_valid_counts_for_NUM_ARRAY_GROUPED_BY_CAT(self): + def test_it_provides_valid_counts_for_NUM_ARRAY_GROUPED_BY_CAT(self): cube = Cube(NA.NUM_ARR_MEANS_GROUPED_BY_CAT) assert cube.covariance is None @@ -122,7 +124,7 @@ def it_provides_valid_counts_for_NUM_ARRAY_GROUPED_BY_CAT(self): (CR.DICHOTOMIZED_NUMERIC_MEAN, (9, 92)), ), ) - def it_provides_valid_counts_summary_range_for_various_cubes( + def test_it_provides_valid_counts_summary_range_for_various_cubes( self, cube, valid_counts_summary_range ): cube = Cube(cube) @@ -131,17 +133,19 @@ def it_provides_valid_counts_summary_range_for_various_cubes( cube.valid_counts_summary_range, valid_counts_summary_range ) - def and_it_returns_empty_array_for_summary_if_valid_counts_are_not_available(self): + def test_and_it_returns_empty_array_for_summary_if_valid_counts_are_not_available( + self, + ): cube = Cube(CR.CAT_X_CAT) np.testing.assert_array_equal(cube.valid_counts_summary_range, []) - def it_provides_n_responses_for_NUM_ARRAY_GROUPED_BY_CAT(self): + def test_it_provides_n_responses_for_NUM_ARRAY_GROUPED_BY_CAT(self): cube = Cube(NA.NUM_ARR_MEANS_GROUPED_BY_CAT) assert cube.n_responses == 5 - def it_provides_multiple_measures_for_NUM_ARRAY_GROUPED_BY_CAT(self): + def test_it_provides_multiple_measures_for_NUM_ARRAY_GROUPED_BY_CAT(self): cube = Cube(NA.NUM_ARR_MULTI_NUMERIC_MEASURES_GROUPED_BY_CAT) assert cube.sums.tolist() == [ @@ -197,12 +201,12 @@ def test_optional_covariance_cube_measure(self): assert cube.covariance is None - def it_does_not_get_fooled_into_single_mr_cats_dim(self): + def test_it_does_not_get_fooled_into_single_mr_cats_dim(self): cube = Cube(CR.NOT_MR_CATS) assert cube.dimension_types == (DT.LOGICAL,) assert cube.partitions[0].counts.tolist() == [200, 100] - def it_provides_squared_weights_counts(self): + def test_it_provides_squared_weights_counts(self): cube = Cube(CR.SQUARED_WEIGHTS) assert cube.weighted_squared_counts.tolist() == [ 0.0, @@ -217,15 +221,15 @@ def it_provides_squared_weights_counts(self): 0.0, ] - def but_it_provides_None_when_no_squared_weights_counts_exist(self): + def test_but_it_provides_None_when_no_squared_weights_counts_exist(self): cube = Cube(CR.NOT_MR_CATS) assert cube.weighted_squared_counts is None -class DescribeIntegrated_Measures: +class TestIntegrated_Measures: """Integration-tests that exercise the `cr.cube.cube._Measures` object.""" - def it_provides_access_to_the_overlaps_measure(self): + def test_it_provides_access_to_the_overlaps_measure(self): cube_dict = OL.CAT_X_MR_SUB_X_MR_SEL measures = _Measures( cube_dict, @@ -236,7 +240,7 @@ def it_provides_access_to_the_overlaps_measure(self): assert type(overlaps).__name__ == "_OverlapMeasure" - def but_only_when_the_cube_response_contains_overlaps(self): + def test_but_only_when_the_cube_response_contains_overlaps(self): cube_dict = CR.CAT_X_CAT measures = _Measures(cube_dict, None) @@ -244,7 +248,7 @@ def but_only_when_the_cube_response_contains_overlaps(self): assert overlaps is None - def it_provides_access_to_the_mean_measure(self): + def test_it_provides_access_to_the_mean_measure(self): cube_dict = CR.CAT_X_CAT_MEAN_WGTD measures = _Measures( cube_dict, @@ -255,7 +259,7 @@ def it_provides_access_to_the_mean_measure(self): assert type(means).__name__ == "_MeanMeasure" - def but_only_when_the_cube_response_contains_means(self): + def test_but_only_when_the_cube_response_contains_means(self): cube_dict = CR.CAT_X_CAT measures = _Measures(cube_dict, None) @@ -263,7 +267,7 @@ def but_only_when_the_cube_response_contains_means(self): assert means is None - def it_provides_the_means_missing_count_when_means_are_available(self): + def test_it_provides_the_means_missing_count_when_means_are_available(self): cube_dict = CR.CAT_X_CAT_MEAN_WGTD measures = _Measures( cube_dict, @@ -272,7 +276,7 @@ def it_provides_the_means_missing_count_when_means_are_available(self): missing_count = measures.missing_count assert missing_count == 3 - def it_provides_the_median_missing_count_when_median_is_available(self): + def test_it_provides_the_median_missing_count_when_median_is_available(self): cube_dict = CR.MEDIAN_CAT_X_CAT_HS measures = _Measures( cube_dict, @@ -281,7 +285,7 @@ def it_provides_the_median_missing_count_when_median_is_available(self): missing_count = measures.missing_count assert missing_count == 0 - def it_provides_the_means_missing_count_when_sum_are_available(self): + def test_it_provides_the_means_missing_count_when_sum_are_available(self): cube_dict = CR.SUM_CAT_X_MR measures = _Measures( cube_dict, @@ -290,7 +294,7 @@ def it_provides_the_means_missing_count_when_sum_are_available(self): missing_count = measures.missing_count assert missing_count == 1 - def but_provides_the_general_missing_count_otherwise(self): + def test_but_provides_the_general_missing_count_otherwise(self): measures = _Measures(CR.CAT_X_CAT, None) missing_count = measures.missing_count assert missing_count == 5 @@ -306,14 +310,14 @@ def but_provides_the_general_missing_count_otherwise(self): (CR.CAT_X_CAT_FILT_COMPLETE, 0.5760869565217391), ), ) - def it_knows_the_population_fraction(self, cube_dict, expected_value): + def test_it_knows_the_population_fraction(self, cube_dict, expected_value): measures = _Measures(cube_dict, None) population_fraction = measures.population_fraction assert population_fraction == expected_value - def it_provides_access_to_the_unweighted_count_measure(self): + def test_it_provides_access_to_the_unweighted_count_measure(self): measures = _Measures(None, None) unweighted_counts = measures.unweighted_counts @@ -329,7 +333,9 @@ def it_provides_access_to_the_unweighted_count_measure(self): (CR.CAT_X_CAT, "NoneType"), ), ) - def it_provides_access_to_wgtd_count_measure(self, cube_dict, expected_type_name): + def test_it_provides_access_to_wgtd_count_measure( + self, cube_dict, expected_type_name + ): measures = _Measures( cube_dict, Dimensions.from_dicts(cube_dict["result"]["dimensions"]), @@ -340,8 +346,8 @@ def it_provides_access_to_wgtd_count_measure(self, cube_dict, expected_type_name assert type(weighted_counts).__name__ == expected_type_name -class DescribeIntegrated_MeanMeasure: - def it_provides_access_to_its_raw_cube_array(self): +class TestIntegrated_MeanMeasure: + def test_it_provides_access_to_its_raw_cube_array(self): cube_dict = CR.CAT_X_CAT_MEAN_WGTD cube = Cube(cube_dict) measure = _MeanMeasure(cube_dict, cube._all_dimensions) @@ -362,7 +368,7 @@ def it_provides_access_to_its_raw_cube_array(self): ], ) - def it_handles_cat_x_mr_with_means(self): + def test_it_handles_cat_x_mr_with_means(self): slice_ = Cube(CR.MEANS_CAT_X_MR).partitions[0] assert slice_.column_labels.tolist() == [ "Denmark", @@ -372,7 +378,7 @@ def it_handles_cat_x_mr_with_means(self): "Sweden", ] - def it_handles_means_cat_hs_x_cat_hs(self): + def test_it_handles_means_cat_hs_x_cat_hs(self): slice_ = Cube(CR.MEANS_CAT_HS_X_CAT_HS).partitions[0] means = slice_.means @@ -391,8 +397,8 @@ def it_handles_means_cat_hs_x_cat_hs(self): ) -class DescribeIntegrated_UnweightedCountMeasure: - def it_provides_access_to_its_raw_cube_array(self): +class TestIntegrated_UnweightedCountMeasure: + def test_it_provides_access_to_its_raw_cube_array(self): cube_dict = CR.CAT_X_CAT cube = Cube(cube_dict) measure = _UnweightedCountMeasure(cube_dict, cube._all_dimensions) @@ -404,8 +410,8 @@ def it_provides_access_to_its_raw_cube_array(self): ) -class DescribeIntegrated_WeightedCountMeasure: - def it_provides_access_to_its_raw_cube_array(self): +class TestIntegrated_WeightedCountMeasure: + def test_it_provides_access_to_its_raw_cube_array(self): cube_dict = CR.CAT_X_CAT_WGTD cube = Cube(cube_dict) measure = _WeightedCountMeasure(cube_dict, cube._all_dimensions) diff --git a/tests/integration/test_cubepart.py b/tests/integration/test_cubepart.py index 126e6f796..939aa4d18 100644 --- a/tests/integration/test_cubepart.py +++ b/tests/integration/test_cubepart.py @@ -18,10 +18,10 @@ NA = np.nan -class Describe_Slice: +class Test_Slice: """Integration-test suite for _Slice object.""" - def it_provides_values_for_cat_x_cat(self): + def test_it_provides_values_for_cat_x_cat(self): slice_ = Cube(CR.CAT_X_CAT, population=9001).partitions[0] assert slice_.column_aliases.tolist() == ["", ""] @@ -165,7 +165,7 @@ def it_provides_values_for_cat_x_cat(self): "Available measures: []" ) - def it_provides_values_for_cat_hs_mt_x_cat_hs_mt(self): + def test_it_provides_values_for_cat_hs_mt_x_cat_hs_mt(self): slice_ = Cube(CR.CAT_HS_MT_X_CAT_HS_MT, population=1000).partitions[0] np.testing.assert_array_equal( @@ -334,7 +334,7 @@ def it_provides_values_for_cat_hs_mt_x_cat_hs_mt(self): ], ) - def it_provides_values_for_cat_x_datetime(self): + def test_it_provides_values_for_cat_x_datetime(self): slice_ = Cube(CR.CAT_X_DATETIME).partitions[0] assert slice_.column_labels.tolist() == [ @@ -399,7 +399,9 @@ def it_provides_values_for_cat_x_datetime(self): ), ), ) - def and_it_accepts_transforms_for_datetimes_in_both_formats(self, elements, order): + def test_and_it_accepts_transforms_for_datetimes_in_both_formats( + self, elements, order + ): transforms = {"columns_dimension": {"elements": elements, "order": order}} slice_ = Cube(CR.CAT_X_DATETIME, transforms=transforms).partitions[0] assert slice_.column_labels.tolist() == [ @@ -408,7 +410,7 @@ def and_it_accepts_transforms_for_datetimes_in_both_formats(self, elements, orde "2000-01-01", ] - def it_provides_values_for_cat_hs_x_mr(self): + def test_it_provides_values_for_cat_hs_x_mr(self): slice_ = Cube(CR.CAT_HS_X_MR).partitions[0] np.testing.assert_almost_equal( @@ -434,7 +436,7 @@ def it_provides_values_for_cat_hs_x_mr(self): slice_.pvals, load_python_expression("cat-hs-x-mr-pvals") ) - def it_provides_values_for_mean_cat_x_cat_hs(self): + def test_it_provides_values_for_mean_cat_x_cat_hs(self): slice_ = Cube(CR.MEANS_CAT_X_CAT_HS).partitions[0] # This fixture has both cube_counts and cube_means measure, for this reason @@ -447,7 +449,7 @@ def it_provides_values_for_mean_cat_x_cat_hs(self): ) assert slice_.rows_margin.tolist() == [1500.0] - def it_provides_values_for_median_cat_x_cat_hs(self): + def test_it_provides_values_for_median_cat_x_cat_hs(self): slice_ = Cube(CR.MEDIAN_CAT_X_CAT_HS).partitions[0] # This fixture has both cube_counts and cube_means measure, for this reason @@ -460,7 +462,7 @@ def it_provides_values_for_median_cat_x_cat_hs(self): ) assert slice_.rows_margin.tolist() == [1500.0] - def it_provides_values_for_mr_x_mr_means(self): + def test_it_provides_values_for_mr_x_mr_means(self): slice_ = Cube(CR.MR_X_MR_MEANS).partitions[0] assert slice_.counts == pytest.approx( @@ -487,7 +489,7 @@ def it_provides_values_for_mr_x_mr_means(self): "Available measures: [, ]" # noqa ) - def it_provides_values_for_mr_x_cat_hs(self): + def test_it_provides_values_for_mr_x_cat_hs(self): slice_ = Cube(CR.MR_X_CAT_HS_MT).partitions[0] np.testing.assert_almost_equal( @@ -521,7 +523,7 @@ def it_provides_values_for_mr_x_cat_hs(self): (MRI.MR_X_MR, None, (0,), (0,), (), ()), ), ) - def it_provides_derived_indexes_for_multiple_responses_with_insertions( + def test_it_provides_derived_indexes_for_multiple_responses_with_insertions( self, fixture, dim_key, derived_rows, derived_cols, inserted_rows, inserted_cols ): transforms = ( @@ -548,7 +550,7 @@ def it_provides_derived_indexes_for_multiple_responses_with_insertions( assert slice_.inserted_row_idxs == inserted_rows assert slice_.inserted_column_idxs == inserted_cols - def it_provides_derived_indexes_for_mr_x_cat_with_transforms(self): + def test_it_provides_derived_indexes_for_mr_x_cat_with_transforms(self): transforms = { "rows_dimension": { "elements": {"2": {"hide": True}}, @@ -574,7 +576,7 @@ def it_provides_derived_indexes_for_mr_x_cat_with_transforms(self): assert slice_.inserted_row_idxs == () assert slice_.inserted_column_idxs == (3,) - def it_provides_derived_indexes_for_cat_x_mr_with_transforms(self): + def test_it_provides_derived_indexes_for_cat_x_mr_with_transforms(self): transforms = { "rows_dimension": { "insertions": [ @@ -600,7 +602,7 @@ def it_provides_derived_indexes_for_cat_x_mr_with_transforms(self): assert slice_.inserted_row_idxs == (3,) assert slice_.inserted_column_idxs == () - def it_knows_the_row_order_and_the_payload_order(self): + def test_it_knows_the_row_order_and_the_payload_order(self): transforms = { "rows_dimension": { "order": {"type": "explicit", "element_ids": [1, 4, 2, 3]}, @@ -611,7 +613,7 @@ def it_knows_the_row_order_and_the_payload_order(self): assert slice_.payload_order == (0, 1, 2, 3) assert slice_.row_order().tolist() == [0, 3, 1, 2] - def it_knows_bogus_ids_row_order(self): + def test_it_knows_bogus_ids_row_order(self): transforms = { "rows_dimension": { "insertions": [ @@ -640,7 +642,7 @@ def it_knows_bogus_ids_row_order(self): "4", ) - def it_provides_derived_indexes_for_mr_x_mr_with_transforms(self): + def test_it_provides_derived_indexes_for_mr_x_mr_with_transforms(self): transforms = { "rows_dimension": { "order": {"type": "explicit", "element_ids": [2, 3]}, @@ -659,7 +661,7 @@ def it_provides_derived_indexes_for_mr_x_mr_with_transforms(self): assert slice_.inserted_row_idxs == () assert slice_.inserted_column_idxs == () - def it_provides_empty_derived_indexes_for_categorical(self): + def test_it_provides_empty_derived_indexes_for_categorical(self): transforms = { "rows_dimension": { "insertions": [ @@ -688,7 +690,7 @@ def it_provides_empty_derived_indexes_for_categorical(self): assert slice_.derived_row_idxs == () assert slice_.inserted_row_idxs == (0, 2, 4) - def it_knows_the_rows_base_cat_x_hs_mr(self): + def test_it_knows_the_rows_base_cat_x_hs_mr(self): slice_ = slice_ = Cube(CR.CAT_HS_X_MR).partitions[0] rows_base = slice_.rows_base @@ -704,14 +706,14 @@ def it_knows_the_rows_base_cat_x_hs_mr(self): [126.0, 161.0, 192.0, 380.0, 375.0], ] - def it_knows_the_rows_base_mr_x_cat_hs(self): + def test_it_knows_the_rows_base_mr_x_cat_hs(self): slice_ = Cube(CR.MR_X_CAT_HS_MT).partitions[0] rows_base = slice_.rows_base assert rows_base.tolist() == [26.0, 76.0, 118.0, 369.0, 385.0] - def it_knows_the_rows_base_mr_x_mr(self): + def test_it_knows_the_rows_base_mr_x_mr(self): slice_ = Cube(CR.MR_X_MR).partitions[0] rows_base = slice_.rows_base @@ -731,7 +733,7 @@ def it_knows_the_rows_base_mr_x_mr(self): (CR.MR_X_MR, "mr-x-mr-row-proportions"), ), ) - def it_knows_the_row_proportions(self, fixture, expectation): + def test_it_knows_the_row_proportions(self, fixture, expectation): slice_ = _Slice( Cube(fixture), slice_idx=0, transforms={}, population=None, mask_size=0 ) @@ -750,7 +752,7 @@ def it_knows_the_row_proportions(self, fixture, expectation): (CR.MR_X_MR, "mr-x-mr-row-margin-proportions"), ), ) - def it_knows_the_rows_margin_proportion(self, fixture, expectation): + def test_it_knows_the_rows_margin_proportion(self, fixture, expectation): slice_ = _Slice( Cube(fixture), slice_idx=0, transforms={}, population=None, mask_size=0 ) @@ -767,7 +769,7 @@ def it_knows_the_rows_margin_proportion(self, fixture, expectation): (CR.MR_X_MR, "mr-x-mr-column-proportions"), ), ) - def it_knows_the_column_proportions(self, fixture, expectation): + def test_it_knows_the_column_proportions(self, fixture, expectation): slice_ = _Slice( Cube(fixture), slice_idx=0, transforms={}, population=None, mask_size=0 ) @@ -786,7 +788,7 @@ def it_knows_the_column_proportions(self, fixture, expectation): (CR.MR_X_MR, "mr-x-mr-columns-margin-proportions"), ), ) - def it_knows_the_column_margin_proportions(self, fixture, expectation): + def test_it_knows_the_column_margin_proportions(self, fixture, expectation): slice_ = _Slice( Cube(fixture), slice_idx=0, transforms={}, population=None, mask_size=0 ) @@ -795,7 +797,7 @@ def it_knows_the_column_margin_proportions(self, fixture, expectation): assert columns_margin_proportion.tolist() == load_python_expression(expectation) - def it_knows_the_margins_of_mr_x_mr(self): + def test_it_knows_the_margins_of_mr_x_mr(self): slice_ = _Slice( Cube(CR.MR_X_MR), slice_idx=0, transforms={}, population=None, mask_size=0 ) @@ -865,7 +867,7 @@ def it_knows_the_margins_of_mr_x_mr(self): ), ), ) - def it_respects_explicit_order_transform_for_dim_types( + def test_it_respects_explicit_order_transform_for_dim_types( self, fixture, row_order, col_order, expectation ): transforms = { @@ -895,7 +897,7 @@ def it_respects_explicit_order_transform_for_dim_types( ("zscores", "cat-x-cat-zscores-explicit-order"), ), ) - def and_it_respects_explicit_order_transform_for_measures( + def test_and_it_respects_explicit_order_transform_for_measures( self, measure_propname, expectation ): transforms = { @@ -919,7 +921,7 @@ def and_it_respects_explicit_order_transform_for_measures( expected = load_python_expression(expectation) np.testing.assert_almost_equal(actual, expected) - def it_can_sort_by_column_index(self): + def test_it_can_sort_by_column_index(self): """Responds to order:opposing_element sort-by-column-index.""" transforms = { "rows_dimension": { @@ -947,7 +949,7 @@ def it_can_sort_by_column_index(self): actual = np.round(slice_.column_index, 1).tolist() assert expected == actual, "\n%s\n\n%s" % (expected, actual) - def it_can_sort_by_column_percent(self): + def test_it_can_sort_by_column_percent(self): """Responds to order:opposing_element sort-by-value. So far, this is limited to column-percents (column-proportions) measure, but @@ -979,7 +981,7 @@ def it_can_sort_by_column_percent(self): actual = np.round(slice_.column_percentages, 1).tolist() assert expected == actual, "\n%s\n\n%s" % (expected, actual) - def it_can_sort_by_labels(self): + def test_it_can_sort_by_labels(self): """Responds to order:label sort-by-label.""" transforms = { "rows_dimension": { @@ -997,7 +999,7 @@ def it_can_sort_by_labels(self): actual = slice_.row_labels.tolist() assert expected == actual, "\n%s\n\n%s" % (expected, actual) - def it_can_sort_by_marginal_with_nan_in_body(self): + def test_it_can_sort_by_marginal_with_nan_in_body(self): transforms = { "columns_dimension": {"insertions": {}}, "rows_dimension": { @@ -1014,7 +1016,7 @@ def it_can_sort_by_marginal_with_nan_in_body(self): [2.45356177, 2.11838791, 2.0, 1.97, 1.74213625, np.nan], nan_ok=True ) - def it_can_fix_order_of_subvars_identified_by_bogus_id(self): + def test_it_can_fix_order_of_subvars_identified_by_bogus_id(self): transforms = { "rows_dimension": { "order": { @@ -1038,7 +1040,7 @@ def it_can_fix_order_of_subvars_identified_by_bogus_id(self): "A_B", # --- alias ), ) - def it_can_sort_by_value_for_mr_derived_insertions(self, id): + def test_it_can_sort_by_value_for_mr_derived_insertions(self, id): # --- Ensure that payload order is how we expect it before sorting payload_order_slice_ = Cube(MRI.CAT_X_MR).partitions[0] assert payload_order_slice_.counts.tolist() == [ @@ -1064,7 +1066,7 @@ def it_can_sort_by_value_for_mr_derived_insertions(self, id): assert slice_.derived_column_idxs == (0,) assert slice_.counts[:, 0].tolist() == [14.0, 19.2, 23.2, 32.0, 37.6] - def it_recalculates_anchor_for_mr_insertion_with_explicit_order(self): + def test_it_recalculates_anchor_for_mr_insertion_with_explicit_order(self): transforms = { "columns_dimension": { "order": { @@ -1092,7 +1094,7 @@ def it_recalculates_anchor_for_mr_insertion_with_explicit_order(self): ("population_counts_moe", "cat-x-cat-population-counts-moe"), ), ) - def but_it_fallback_to_payload_order_when_sort_by_value_is_not_supported( + def test_but_it_fallback_to_payload_order_when_sort_by_value_is_not_supported( self, measure, expectation ): transforms = { @@ -1115,7 +1117,7 @@ def but_it_fallback_to_payload_order_when_sort_by_value_is_not_supported( assert measure == pytest.approx(np.array(load_python_expression(expectation))) - def it_can_recover_from_sort_by_value_failure_invalid_id(self): + def test_it_can_recover_from_sort_by_value_failure_invalid_id(self): """Falls back to payload order when opposing element id does not exist.""" transforms = { "rows_dimension": { @@ -1139,7 +1141,7 @@ def it_can_recover_from_sort_by_value_failure_invalid_id(self): [17.0, 12.0, 28.0, 11.0], ] - def it_can_recover_from_sort_by_value_invalid_sort_type(self): + def test_it_can_recover_from_sort_by_value_invalid_sort_type(self): """Falls back to payload order when measure is unavailable.""" transforms = { "rows_dimension": { @@ -1158,7 +1160,7 @@ def it_can_recover_from_sort_by_value_invalid_sort_type(self): [17.0, 12.0, 28.0, 11.0], ] - def it_can_sort_by_rows_scale_mean(self): + def test_it_can_sort_by_rows_scale_mean(self): """Responds to order of marginal sort-by-value.""" transforms = { "rows_dimension": { @@ -1185,7 +1187,7 @@ def it_can_sort_by_rows_scale_mean(self): [46.0, 21.0, 3.0, 0.0, 7.0], ] - def it_can_sort_by_rows_margin(self): + def test_it_can_sort_by_rows_margin(self): """Responds to order of marginal sort-by-value.""" transforms = { "rows_dimension": { @@ -1202,7 +1204,7 @@ def it_can_sort_by_rows_margin(self): # --- scale means should be in order assert slice_.rows_margin.tolist() == pytest.approx([74.0, 68.0, 67.0, 57.0]) - def it_can_sort_by_rows_margin_proportion(self): + def test_it_can_sort_by_rows_margin_proportion(self): """Responds to order of marginal sort-by-value.""" transforms = { "rows_dimension": { @@ -1221,7 +1223,7 @@ def it_can_sort_by_rows_margin_proportion(self): [0.2142857, 0.2518796, 0.2556391, 0.2781954] ) - def it_can_sort_by_rows_base(self): + def test_it_can_sort_by_rows_base(self): """Responds to order of marginal sort-by-value.""" transforms = { "rows_dimension": { @@ -1238,7 +1240,9 @@ def it_can_sort_by_rows_base(self): # --- base should be in order assert slice_.rows_base.tolist() == pytest.approx([57.0, 67.0, 68.0, 74.0]) - def but_it_falls_back_to_payload_order_when_rows_scale_means_is_unavailable(self): + def test_but_it_falls_back_to_payload_order_when_rows_scale_means_is_unavailable( + self, + ): """Falls back to payload order when measure is unavailable.""" transforms = { "rows_dimension": { @@ -1262,7 +1266,7 @@ def but_it_falls_back_to_payload_order_when_rows_scale_means_is_unavailable(self [17.0, 12.0, 28.0, 11.0], ] - def it_fallback_to_payload_order_when_measure_is_not_a_valid_marginal(self): + def test_it_fallback_to_payload_order_when_measure_is_not_a_valid_marginal(self): transforms = { "rows_dimension": { "order": { @@ -1297,7 +1301,7 @@ def it_fallback_to_payload_order_when_measure_is_not_a_valid_marginal(self): [247.0, 80.0, 19.0, 4.0, 26.0], ] - def it_ignores_hidden_subtotals(self): + def test_it_ignores_hidden_subtotals(self): """A subtotal with `"hide": True` does not appear. This behavior is added in the "interim", insertion-has-no-id state to allow @@ -1343,7 +1347,7 @@ def it_ignores_hidden_subtotals(self): [[14, 14, 13, 16], [22, 14, 19, 19], [14, 16, 19, 18], [17, 12, 28, 11]], ) - def it_ignores_hidden_mr_insertions(self): + def test_it_ignores_hidden_mr_insertions(self): """A subtotal with `"hide": True` does not appear. This behavior is added in the "interim", insertion-has-no-id state to allow @@ -1387,7 +1391,7 @@ def it_ignores_hidden_mr_insertions(self): ) ) - def it_renders_mr_insertions_on_scorecards(self): + def test_it_renders_mr_insertions_on_scorecards(self): slice_ = _Slice(Cube(MRI.SCORECARD), 0, None, None, 0) assert slice_.counts == pytest.approx( np.array( @@ -1403,7 +1407,7 @@ def it_renders_mr_insertions_on_scorecards(self): ) ) - def it_does_not_break_when_hiding_mr_insertion_that_does_not_exist(self): + def test_it_does_not_break_when_hiding_mr_insertion_that_does_not_exist(self): # --- Though it doesn't actually hide anything transforms = { "rows_dimension": { @@ -1440,7 +1444,7 @@ def it_does_not_break_when_hiding_mr_insertion_that_does_not_exist(self): ) ) - def it_renders_scorecard_transforms(self): + def test_it_renders_scorecard_transforms(self): transforms = { "rows_dimension": { "elements": { @@ -1460,7 +1464,7 @@ def it_renders_scorecard_transforms(self): assert slice_.row_labels.tolist() == ["CCC", "RENAMED AAA"] assert slice_.column_labels.tolist() == ["RENAMED Simple MR2", "Simple MR1"] - def it_places_insertions_on_a_reordered_dimension_in_the_right_position(self): + def test_it_places_insertions_on_a_reordered_dimension_in_the_right_position(self): """Subtotal anchors follow re-ordered rows. The key fixture characteristic is that an ordering transform is combined with @@ -1549,7 +1553,7 @@ def it_places_insertions_on_a_reordered_dimension_in_the_right_position(self): ], ) - def it_provides_same_proportions_without_explicit_order(self): + def test_it_provides_same_proportions_without_explicit_order(self): transforms = TR.TEST_DASHBOARD_TRANSFORM_SINGLE_EL_VISIBLE slice_ = Cube(CR.TEST_DASHBOARD_FIXTURE, transforms=transforms).partitions[0] @@ -1575,16 +1579,16 @@ def it_provides_same_proportions_without_explicit_order(self): slice_.rows_base, slice_wo_explicit_order_.rows_base ) - def it_knows_when_it_is_empty(self): + def test_it_knows_when_it_is_empty(self): assert Cube(CR.OM_SGP8334215_VN_2019_SEP_19).partitions[0].is_empty is True - def it_provides_unpruned_table_margin(self): + def test_it_provides_unpruned_table_margin(self): slice_ = _Slice(Cube(CR.MR_X_CAT_HS_MT), 0, None, None, 0) assert slice_.table_base_range.tolist() == [165, 476] assert slice_.table_margin_range == pytest.approx([176.3655518, 471.9317685]) - def it_prunes_cat_x_cat_with_hs(self): + def test_it_prunes_cat_x_cat_with_hs(self): # Pruned - without insertions transforms = { "rows_dimension": {"insertions": {}, "prune": True}, @@ -1660,12 +1664,12 @@ def it_prunes_cat_x_cat_with_hs(self): ) np.testing.assert_equal(slice_.unweighted_counts, expected) - def it_accommodates_an_all_missing_element_rows_dimension(self): + def test_it_accommodates_an_all_missing_element_rows_dimension(self): slice_ = _Slice(Cube(CR.CAT_X_CAT_ALL_MISSING_ROW_ELEMENTS), 0, None, None, 0) row_proportions = slice_.row_proportions np.testing.assert_almost_equal(row_proportions, np.array([]).reshape((0, 2))) - def it_knows_means_with_subtotals_on_cat_x_cat(self): + def test_it_knows_means_with_subtotals_on_cat_x_cat(self): slice_ = _Slice(Cube(CR.CAT_X_CAT_MEAN_SUBTOT), 0, None, None, 0) means = slice_.means @@ -1674,12 +1678,12 @@ def it_knows_means_with_subtotals_on_cat_x_cat(self): means, np.array([[38.3333333, np.nan, 65.0, 55.0, 34.0]]) ) - def it_knows_its_selected_categories(self): + def test_it_knows_its_selected_categories(self): slice_ = Cube(CR.MR_X_MR_SELECTED_CATEGORIES).partitions[0] assert slice_.selected_category_labels == ("Very Favorable",) - def it_provides_sum_measure_for_mr_x_mr(self): + def test_it_provides_sum_measure_for_mr_x_mr(self): slice_ = Cube(CR.MR_X_MR_SUM).partitions[0] assert slice_.sums == pytest.approx( np.array( @@ -1691,7 +1695,7 @@ def it_provides_sum_measure_for_mr_x_mr(self): ) ) - def it_provides_stddev_measure_for_cat_x_mr(self): + def test_it_provides_stddev_measure_for_cat_x_mr(self): slice_ = Cube(CR.CAT_X_MR_STDDEV).partitions[0] assert slice_.stddev == pytest.approx( @@ -1705,7 +1709,7 @@ def it_provides_stddev_measure_for_cat_x_mr(self): ) assert slice_.table_base.tolist() == [3, 3, 3] - def it_provides_share_of_sum_measure_for_mr_x_mr(self): + def test_it_provides_share_of_sum_measure_for_mr_x_mr(self): slice_ = Cube(CR.MR_X_MR_SUM).partitions[0] assert slice_.column_share_sum == pytest.approx( @@ -1746,7 +1750,9 @@ def it_provides_share_of_sum_measure_for_mr_x_mr(self): "Available measures: [, ]" # noqa ) - def it_uses_row_proportions_for_pop_counts_and_moe_when_row_dim_is_cat_date(self): + def test_it_uses_row_proportions_for_pop_counts_and_moe_when_row_dim_is_cat_date( + self, + ): slice_ = Cube(CR.CAT_DATE_X_CAT, population=100).partitions[0] assert slice_.population_counts == pytest.approx( np.array( @@ -1780,7 +1786,9 @@ def it_uses_row_proportions_for_pop_counts_and_moe_when_row_dim_is_cat_date(self abs=10e-2, ) - def it_uses_column_proportions_for_pop_counts_when_column_dim_is_cat_date(self): + def test_it_uses_column_proportions_for_pop_counts_when_column_dim_is_cat_date( + self, + ): slice_ = Cube(CR.CAT_HS_X_CAT_DATE, population=100).partitions[0] assert slice_.population_counts == pytest.approx( np.array( @@ -1830,7 +1838,7 @@ def it_uses_column_proportions_for_pop_counts_when_column_dim_is_cat_date(self): abs=10e-2, ) - def it_uses_rows_proportions_for_ca_subvar_x_ca_cat_population_counts(self): + def test_it_uses_rows_proportions_for_ca_subvar_x_ca_cat_population_counts(self): slice_ = Cube(CR.SIMPLE_CAT_ARRAY, population=100).partitions[0] assert slice_.population_counts == pytest.approx( np.array( @@ -1846,7 +1854,7 @@ def it_uses_rows_proportions_for_ca_subvar_x_ca_cat_population_counts(self): np.array([100, 100, 100]) ) - def it_uses_columns_proportions_for_ca_cat_x_ca_subvar_population_counts(self): + def test_it_uses_columns_proportions_for_ca_cat_x_ca_subvar_population_counts(self): slice_ = Cube(CR.MR_X_CA_CAT_X_CA_SUBVAR, population=100).partitions[0] assert slice_.population_counts == pytest.approx( np.array( @@ -1871,7 +1879,7 @@ def it_uses_columns_proportions_for_ca_cat_x_ca_subvar_population_counts(self): np.array([100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) ) - def it_has_bases_that_dont_sum_across_ca_subvars(self): + def test_it_has_bases_that_dont_sum_across_ca_subvars(self): slice_ = Cube(CR.CA_CAT_X_CA_SUBVAR).partitions[0] column_bases = [ [1641.0, 1639.0, 0.0], @@ -1887,7 +1895,7 @@ def it_has_bases_that_dont_sum_across_ca_subvars(self): # --- and row bases are the same as the counts assert slice_.row_weighted_bases.tolist() == slice_.counts.tolist() - def it_has_bases_that_dont_sum_across_ca_subvars_with_insertions(self): + def test_it_has_bases_that_dont_sum_across_ca_subvars_with_insertions(self): transforms = { "rows_dimension": { "insertions": [ @@ -1916,7 +1924,7 @@ def it_has_bases_that_dont_sum_across_ca_subvars_with_insertions(self): # --- and row bases are the same as the counts assert slice_.row_weighted_bases.tolist() == slice_.counts.tolist() - def it_uses_squared_weights_for_effect_calculation(self): + def test_it_uses_squared_weights_for_effect_calculation(self): cube = Cube(CR.SQUARED_WEIGHTS_CAT_X_CAT) slice_ = cube.partitions[0] np.testing.assert_almost_equal( @@ -1935,14 +1943,14 @@ def it_uses_squared_weights_for_effect_calculation(self): ) -class Describe_Strand: +class Test_Strand: """Integration-test suite for `cr.cube.cubepart._Strand` object.""" - def it_uses_correct_proportions_for_pop_counts_when_cat_date(self): + def test_it_uses_correct_proportions_for_pop_counts_when_cat_date(self): strand_ = Cube(CR.CAT_DATE, population=100).partitions[0] assert strand_.population_counts.tolist() == [100] * 9 - def it_provides_values_for_ca_as_0th(self): + def test_it_provides_values_for_ca_as_0th(self): transforms = { "columns_dimension": {"insertions": {}}, "rows_dimension": {"insertions": {}}, @@ -1958,7 +1966,7 @@ def it_provides_values_for_ca_as_0th(self): assert strand.table_name == "Level of in: ATP Men's T" assert strand.weighted_bases == pytest.approx([27292.0] * 4) - def it_provides_values_for_univariate_cat(self): + def test_it_provides_values_for_univariate_cat(self): strand = Cube(CR.UNIVARIATE_CATEGORICAL, population=1000).partitions[0] assert strand.counts.tolist() == [10, 5] @@ -2044,7 +2052,7 @@ def it_provides_values_for_univariate_cat(self): "Available measures: []" ) - def it_provides_values_for_univariate_cat_means_hs(self): + def test_it_provides_values_for_univariate_cat_means_hs(self): strand = Cube(CR.CAT_MEANS_HS).partitions[0] assert strand.is_empty is False @@ -2054,7 +2062,7 @@ def it_provides_values_for_univariate_cat_means_hs(self): assert strand.title == "Untitled" assert strand.unweighted_counts.tolist() == [409, 113, 139, 409, 252] - def it_provides_values_for_univariate_cat_means_and_counts(self): + def test_it_provides_values_for_univariate_cat_means_and_counts(self): """The cube_mean and cube_count measures can appear together.""" # --- prune to avoid NaNs in results and thereby simplify assertions --- transforms = {"rows_dimension": {"prune": True}} @@ -2068,7 +2076,7 @@ def it_provides_values_for_univariate_cat_means_and_counts(self): # --- means cube that also has counts has a table-margin --- assert strand.table_margin_range == pytest.approx([1500.961, 1500.961]) - def it_provides_values_for_univariate_datetime(self): + def test_it_provides_values_for_univariate_datetime(self): strand = Cube(CR.DATE, population=9001).partitions[0] assert strand.counts.tolist() == [1, 1, 1, 1] @@ -2085,7 +2093,7 @@ def it_provides_values_for_univariate_datetime(self): ) assert strand.table_proportions == pytest.approx([0.25, 0.25, 0.25, 0.25]) - def it_provides_values_for_univariate_mr_hs(self): + def test_it_provides_values_for_univariate_mr_hs(self): # --- subtotals shouldn't be in the MR variable, but there are cases when they # --- are present. H&S should be ignored for univariate MR. strand = Cube(CR.UNIV_MR_WITH_HS).partitions[0] @@ -2147,7 +2155,7 @@ def it_provides_values_for_univariate_mr_hs(self): assert strand.unweighted_bases.tolist() == [33358] * 9 assert strand.weighted_bases == pytest.approx([33364.08] * 9) - def it_provides_values_for_univariate_numeric(self): + def test_it_provides_values_for_univariate_numeric(self): strand = Cube(CR.NUM, population=9001).partitions[0] assert strand.counts.tolist() == [885, 105, 10] @@ -2169,13 +2177,13 @@ def it_provides_values_for_univariate_numeric(self): assert strand.table_proportions == pytest.approx([0.885, 0.105, 0.010]) assert strand.weighted_bases == pytest.approx([1000.0] * 3) - def it_provides_values_for_univariate_numeric_binned(self): + def test_it_provides_values_for_univariate_numeric_binned(self): strand = Cube( CR.NUM_BINNED, transforms={"rows_dimension": {"prune": True}} ).partitions[0] assert strand.counts == pytest.approx([118504.4, 155261.3, 182924.0]) - def it_provides_values_for_univariate_text(self): + def test_it_provides_values_for_univariate_text(self): strand = Cube(CR.TEXT, population=9001).partitions[0] assert strand.counts.tolist() == [1, 1, 1, 1, 1, 1] @@ -2196,7 +2204,7 @@ def it_provides_values_for_univariate_text(self): [0.1666667, 0.1666667, 0.1666667, 0.1666667, 0.1666667, 0.1666667], ) - def it_places_insertions_on_a_reordered_dimension_in_the_right_position(self): + def test_it_places_insertions_on_a_reordered_dimension_in_the_right_position(self): """Subtotal anchors follow re-ordered rows. The key fixture characteristic is that an ordering transform is combined with @@ -2241,7 +2249,7 @@ def it_places_insertions_on_a_reordered_dimension_in_the_right_position(self): ] assert strand.counts.tolist() == [31506, 16275, 3480, 31506, 4262, 15231, 7742] - def it_knows_the_row_order_and_the_payload_order(self): + def test_it_knows_the_row_order_and_the_payload_order(self): transforms = { "rows_dimension": { "insertions": [ @@ -2260,7 +2268,7 @@ def it_knows_the_row_order_and_the_payload_order(self): assert strand.payload_order == (0, 1, 2, 3, "ins_1") assert strand.row_order().tolist() == [1, 2, 3, 0, -1] - def it_can_sort_by_label(self): + def test_it_can_sort_by_label(self): transforms = { "rows_dimension": { "order": { @@ -2285,7 +2293,7 @@ def it_can_sort_by_label(self): actual = strand_.row_labels.tolist() assert expected == actual, "\n%s\n\n%s" % (expected, actual) - def it_knows_the_bogus_id_row_order(self): + def test_it_knows_the_bogus_id_row_order(self): strand_ = Cube(CR.CAT_HS_MT).partitions[0] assert tuple(strand_.row_order(format=ORDER_FORMAT.BOGUS_IDS)) == ( @@ -2298,41 +2306,41 @@ def it_knows_the_bogus_id_row_order(self): "ins_2", ) - def it_knows_when_it_is_empty(self): + def test_it_knows_when_it_is_empty(self): strand = Cube(CR.OM_SGP8334215_VN_2019_SEP_19_STRAND).partitions[0] assert strand.is_empty is True - def it_provides_stddev_measure_for_CAT(self): + def test_it_provides_stddev_measure_for_CAT(self): strand = Cube(CR.CAT_STDDEV).partitions[0] assert strand.stddev == pytest.approx([22.898325, 7.778174]) assert strand.table_base_range.tolist() == [5, 5] - def it_provides_stddev_measure_for_MR(self): + def test_it_provides_stddev_measure_for_MR(self): strand = Cube(CR.MR_STDDEV).partitions[0] assert strand.stddev == pytest.approx([3.22398, 1.23444, 9.23452]) assert strand.table_base_range.tolist() == [3, 3] - def it_provides_sum_measure_for_CAT(self): + def test_it_provides_sum_measure_for_CAT(self): strand = Cube(CR.CAT_SUM).partitions[0] assert strand.sums == pytest.approx([88.0, 77.0]) assert strand.table_base_range.tolist() == [5, 5] - def it_provides_median_measure_for_CAT(self): + def test_it_provides_median_measure_for_CAT(self): strand = Cube(CR.CAT_MEDIAN).partitions[0] assert strand.medians == pytest.approx([8.8, 7.445]) assert strand.table_base_range.tolist() == [5, 5] - def it_provides_median_measure_for_MR(self): + def test_it_provides_median_measure_for_MR(self): strand = Cube(CR.MR_MEDIAN).partitions[0] assert strand.medians == pytest.approx([2.22398, 0.23444, 7.23452]) assert strand.table_base_range.tolist() == [3, 3] - def it_provides_sum_measure_for_CAT_HS(self): + def test_it_provides_sum_measure_for_CAT_HS(self): transforms = { "rows_dimension": { "insertions": [ @@ -2350,20 +2358,20 @@ def it_provides_sum_measure_for_CAT_HS(self): assert strand.sums == pytest.approx([88.0, 77.0, 165.0]) - def it_provides_sum_measure_for_MR(self): + def test_it_provides_sum_measure_for_MR(self): strand = Cube(CR.MR_SUM).partitions[0] assert strand.sums == pytest.approx([3.0, 2.0, 2.0]) assert strand.table_base_range.tolist() == [3, 3] - def it_provides_sum_and_mean_measure_for_CAT(self): + def test_it_provides_sum_and_mean_measure_for_CAT(self): strand = Cube(CR.NUMERIC_MEASURES_X_CAT).partitions[0] assert strand.counts == pytest.approx([3, 2]) assert strand.means == pytest.approx([2.66666667, 3.5]) assert strand.sums == pytest.approx([8, 7]) - def it_provides_share_of_sum_measure_for_CAT(self): + def test_it_provides_share_of_sum_measure_for_CAT(self): strand = Cube(CR.CAT_SUM).partitions[0] assert strand.sums == pytest.approx([88.0, 77.0]) @@ -2372,7 +2380,7 @@ def it_provides_share_of_sum_measure_for_CAT(self): assert strand.share_sum.tolist() == [0.5333333333333333, 0.4666666666666667] assert strand.table_base_range.tolist() == [5, 5] - def it_provides_share_of_sum_measure_for_MR(self): + def test_it_provides_share_of_sum_measure_for_MR(self): strand = Cube(CR.MR_SUM).partitions[0] assert strand.share_sum.tolist() == [ @@ -2382,12 +2390,12 @@ def it_provides_share_of_sum_measure_for_MR(self): ] assert strand.table_base_range.tolist() == [3, 3] - def it_provides_unweighted_valid_counts_for_mr_mean(self): + def test_it_provides_unweighted_valid_counts_for_mr_mean(self): strand = Cube(CR.MR_MEAN).partitions[0] assert strand.unweighted_counts.tolist() == [3, 5, 5] - def it_provides_unweighted_valid_counts_for_mr_mean_weighted(self): + def test_it_provides_unweighted_valid_counts_for_mr_mean_weighted(self): strand = Cube(CR.MR_MEAN_WEIGHTED).partitions[0] assert strand.counts.tolist() == [ @@ -2396,7 +2404,7 @@ def it_provides_unweighted_valid_counts_for_mr_mean_weighted(self): 7.3559027778, ] - def it_provides_derived_indexes_for_univariate_mr_with_transforms(self): + def test_it_provides_derived_indexes_for_univariate_mr_with_transforms(self): transforms = { "rows_dimension": { "elements": {"2": {"hide": True}}, @@ -2411,21 +2419,35 @@ def it_provides_derived_indexes_for_univariate_mr_with_transforms(self): assert slice_.inserted_row_idxs == () -class Describe_Nub: +class Test_Nub: """Integration-test suite for `cr.cube.cubepart._Nub` object.""" - def it_is_not_empty(self): + def test_it_is_not_empty(self): cube = Cube(CR.ECON_MEAN_NO_DIMS) nub = cube.partitions[0] assert nub.is_empty is False - def it_is_empty(self): + def test_it_is_empty(self): cube = Cube(CR.ECON_NODATA_NO_DIMS) nub = cube.partitions[0] assert nub.is_empty is True + def test_mean_no_dims(self): + cube = Cube(CR.ECON_MEAN_NO_DIMS) + assert cube.description is None + assert cube.name is None + assert cube.missing == 0 -class Test_Slice: + nub = cube.partitions[0] + + np.testing.assert_almost_equal(nub.means, np.array([49.095])) + assert nub.ndim == 0 + np.testing.assert_almost_equal(nub.table_base, np.array([49.095])) + np.testing.assert_array_equal(nub.unweighted_count, 1000) + assert nub.table_name is None + + +class Test_LegacySlice: """Legacy unit tests for _Slice object. In general, these need to be consolidated into Describe_Slice above, and there are @@ -3858,21 +3880,3 @@ def test_mr_x_cat_mean_weighted(self): [1.89375, 2.7875, 4.68125], [2.8416666667, 1.915625, 4.7572916667000005], ] - - -class Test_Nub: - """Legacy unit-tests for 0D cube.""" - - def test_mean_no_dims(self): - cube = Cube(CR.ECON_MEAN_NO_DIMS) - assert cube.description is None - assert cube.name is None - assert cube.missing == 0 - - nub = cube.partitions[0] - - np.testing.assert_almost_equal(nub.means, np.array([49.095])) - assert nub.ndim == 0 - np.testing.assert_almost_equal(nub.table_base, np.array([49.095])) - np.testing.assert_array_equal(nub.unweighted_count, 1000) - assert nub.table_name is None diff --git a/tests/integration/test_dimension.py b/tests/integration/test_dimension.py index 1d219438d..124eb92f0 100644 --- a/tests/integration/test_dimension.py +++ b/tests/integration/test_dimension.py @@ -21,7 +21,7 @@ from ..unitutil import instance_mock -class DescribeIntegratedDimensions: +class TestIntegratedDimensions: """Integration-test suite for `cr.cube.dimension.Dimensions` object.""" @pytest.mark.parametrize( @@ -35,7 +35,9 @@ class DescribeIntegratedDimensions: ), ), ) - def it_resolves_the_type_of_each_dimension(self, cube_response, expected_types): + def test_it_resolves_the_type_of_each_dimension( + self, cube_response, expected_types + ): dimension_dicts = cube_response["result"]["dimensions"] all_dimensions = Dimensions.from_dicts(dimension_dicts) @@ -43,7 +45,7 @@ def it_resolves_the_type_of_each_dimension(self, cube_response, expected_types): assert dimension_types == expected_types - def it_provides_access_to_the_apparent_dimensions(self): + def test_it_provides_access_to_the_apparent_dimensions(self): dimension_dicts = CR.CA_X_MR_WEIGHTED_HS["result"]["dimensions"] all_dimensions = Dimensions.from_dicts(dimension_dicts) @@ -62,7 +64,7 @@ def it_provides_access_to_the_apparent_dimensions(self): ((DT.NUM_ARRAY,), (0,)), ), ) - def it_knows_if_its_dimensions_order(self, request, dim_types, expected_value): + def test_it_knows_if_its_dimensions_order(self, request, dim_types, expected_value): dims = Dimensions([Dimension({}, dt) for dt in dim_types]) assert dims.dimension_order == expected_value @@ -95,7 +97,7 @@ def it_knows_if_its_dimensions_order(self, request, dim_types, expected_value): ), ), ) - def it_know_how_to_repr_all_dimensions( + def test_it_know_how_to_repr_all_dimensions( self, cube_response, expected_str_representation ): dimension_dicts = cube_response["result"]["dimensions"] @@ -106,17 +108,17 @@ def it_know_how_to_repr_all_dimensions( assert str_representation == expected_str_representation.strip() -class DescribeIntegratedDimension: +class TestIntegratedDimension: """Integration-test suite for `cr.cube.dimension.Dimension` object.""" - def it_provides_access_to_all_elements_in_its_collection(self, dimension_dict): + def test_it_provides_access_to_all_elements_in_its_collection(self, dimension_dict): dimension = Dimension(dimension_dict, DT.CAT) elements = dimension.all_elements assert isinstance(elements, Elements) - def it_knows_its_transformed_description(self, dimension_dict): + def test_it_knows_its_transformed_description(self, dimension_dict): dimension_transforms = {"description": "foobar"} dimension = Dimension(dimension_dict, None, dimension_transforms) @@ -124,7 +126,7 @@ def it_knows_its_transformed_description(self, dimension_dict): assert description == "foobar" - def but_it_uses_element_description_when_not_transformed(self, dimension_dict): + def test_but_it_uses_element_description_when_not_transformed(self, dimension_dict): dimension = Dimension(dimension_dict, None) description = dimension.description @@ -136,7 +138,7 @@ def but_it_uses_element_description_when_not_transformed(self, dimension_dict): "s?" ) - def it_knows_its_transformed_name(self, dimension_dict): + def test_it_knows_its_transformed_name(self, dimension_dict): dimension_transforms = {"name": "barfoo"} dimension = Dimension(dimension_dict, None, dimension_transforms) @@ -144,7 +146,7 @@ def it_knows_its_transformed_name(self, dimension_dict): assert name == "barfoo" - def but_it_uses_the_dimension_name_when_no_transform(self, dimension_dict): + def test_but_it_uses_the_dimension_name_when_no_transform(self, dimension_dict): dimension_transforms = {} dimension = Dimension(dimension_dict, None, dimension_transforms) @@ -152,7 +154,7 @@ def but_it_uses_the_dimension_name_when_no_transform(self, dimension_dict): assert name == "ShutdownBlame" - def and_it_uses_alias_when_no_name(self, dimension_dict): + def test_and_it_uses_alias_when_no_name(self, dimension_dict): dimension_dict["references"].pop("name") dimension_transforms = {} dimension = Dimension(dimension_dict, None, dimension_transforms) @@ -161,7 +163,7 @@ def and_it_uses_alias_when_no_name(self, dimension_dict): assert name == "ShutdownBlame" - def it_knows_whether_it_should_be_pruned(self, dimension_dict): + def test_it_knows_whether_it_should_be_pruned(self, dimension_dict): dimension_transforms = {"prune": True} dimension = Dimension(dimension_dict, None, dimension_transforms) @@ -169,7 +171,7 @@ def it_knows_whether_it_should_be_pruned(self, dimension_dict): assert prune is True - def it_provides_access_to_its_inserted_subtotal_specs(self, dimension_dict): + def test_it_provides_access_to_its_inserted_subtotal_specs(self, dimension_dict): dimension_transforms = {} dimension = Dimension(dimension_dict, None, dimension_transforms) @@ -177,7 +179,7 @@ def it_provides_access_to_its_inserted_subtotal_specs(self, dimension_dict): assert len(subtotals) == 1 - def it_provides_access_to_its_inserted_subtotal_in_payload_order( + def test_it_provides_access_to_its_inserted_subtotal_in_payload_order( self, dimension_dict ): dimension_transforms = {} @@ -187,7 +189,9 @@ def it_provides_access_to_its_inserted_subtotal_in_payload_order( assert len(subtotals) == 1 - def but_it_uses_transforms_insertions_instead_when_present(self, dimension_dict): + def test_but_it_uses_transforms_insertions_instead_when_present( + self, dimension_dict + ): dimension_transforms = {"insertions": []} dimension = Dimension(dimension_dict, None, dimension_transforms) @@ -195,20 +199,20 @@ def but_it_uses_transforms_insertions_instead_when_present(self, dimension_dict) assert len(subtotals) == 0 - def it_allows_unicode_characters_in_a_subvariable_alias(self): + def test_it_allows_unicode_characters_in_a_subvariable_alias(self): slice_ = Cube(CR.CAT_X_MR_UNICODE_SV_ALIAS).partitions[0] sv_dimension = slice_._dimensions[1] assert sv_dimension.element_ids == ("\u2018dk\u2019", "fi", "is", "no", "se") - def it_ignores_bad_types_in_transform_dictionary(self): + def test_it_ignores_bad_types_in_transform_dictionary(self): transforms = {"columns_dimension": {"elements": {"fi": None, "is": []}}} slice_ = Cube(CR.CAT_X_MR, transforms=transforms).partitions[0] sv_dimension = slice_._dimensions[1] assert sv_dimension.hidden_idxs == tuple() - def it_knows_how_to_repr_itself(self): + def test_it_knows_how_to_repr_itself(self): dim = Cube(CR.ECON_BLAME_WITH_HS).dimensions[0] str_representation = str(dim) @@ -222,10 +226,10 @@ def dimension_dict(self): return CR.ECON_BLAME_WITH_HS["value"]["result"]["dimensions"][0] -class DescribeIntegratedElements: +class TestIntegratedElements: """Integration-test suite for `cr.cube.dimension.Elements` object.""" - def it_constructs_its_element_objects_to_help(self): + def test_it_constructs_its_element_objects_to_help(self): type_dict = Cube(CR.ECON_BLAME_WITH_HS).dimensions[0]._dimension_dict["type"] dimension_transforms = {} all_elements = Elements.from_typedef( @@ -233,7 +237,7 @@ def it_constructs_its_element_objects_to_help(self): ) assert all(isinstance(element, Element) for element in all_elements) - def it_hides_element_objects_by_subvariable_id_to_help(self): + def test_it_hides_element_objects_by_subvariable_id_to_help(self): transforms = { "rows_dimension": { "elements": {"S2": {"hide": True}}, @@ -249,7 +253,7 @@ def it_hides_element_objects_by_subvariable_id_to_help(self): assert len(all_elements) == 3 assert all_elements[1].is_hidden is True - def it_knows_how_to_repr_its_elements(self): + def test_it_knows_how_to_repr_its_elements(self): type_dict = Cube(CR.ECON_BLAME_WITH_HS).dimensions[0]._dimension_dict["type"] all_elements = Elements.from_typedef(type_dict, {}, None, None) @@ -261,8 +265,8 @@ def it_knows_how_to_repr_its_elements(self): ) -class DescribeIntegrated_Subtotals: - def it_can_generate_insertion_ids_from_view_when_needed(self): +class TestIntegrated_Subtotals: + def test_it_can_generate_insertion_ids_from_view_when_needed(self): base_ins = {"function": "subtotal", "args": [1]} insertion_dicts = [ {"name": "1, 1", "anchor": 1, **base_ins}, @@ -290,10 +294,10 @@ def it_can_generate_insertion_ids_from_view_when_needed(self): assert subtotals.insertion_ids == (2, 1, 4, 3, 5) -class DescribeIntegrated_Element: +class TestIntegrated_Element: """Integration-test suite for `cr.cube.dimension.Element` object.""" - def it_knows_its_transformed_label(self, element_dict, element_transforms_): + def test_it_knows_its_transformed_label(self, element_dict, element_transforms_): element_transforms_.name = "Xfinity Lounge" element = Element(element_dict, None, element_transforms_, str, DT.CATEGORICAL) @@ -301,7 +305,7 @@ def it_knows_its_transformed_label(self, element_dict, element_transforms_): assert label == "Xfinity Lounge" - def but_it_uses_its_base_name_if_no_transform_is_present( + def test_but_it_uses_its_base_name_if_no_transform_is_present( self, element_dict, element_transforms_ ): element_transforms_.name = None @@ -311,7 +315,9 @@ def but_it_uses_its_base_name_if_no_transform_is_present( assert label == "President Obama" - def it_knows_when_it_is_explicitly_hidden(self, element_dict, element_transforms_): + def test_it_knows_when_it_is_explicitly_hidden( + self, element_dict, element_transforms_ + ): element_transforms_.hide = True element = Element(element_dict, None, element_transforms_, None, DT.CATEGORICAL) @@ -319,7 +325,7 @@ def it_knows_when_it_is_explicitly_hidden(self, element_dict, element_transforms assert is_hidden is True - def but_it_is_not_hidden_by_default(self, element_transforms_): + def test_but_it_is_not_hidden_by_default(self, element_transforms_): element_transforms_.hide = None element = Element(None, None, element_transforms_, None, DT.CATEGORICAL) @@ -327,7 +333,7 @@ def but_it_is_not_hidden_by_default(self, element_transforms_): assert is_hidden is False - def it_knows_how_to_repr(self, element_dict, element_transforms_): + def test_it_knows_how_to_repr(self, element_dict, element_transforms_): element_transforms_.name = None element = Element(element_dict, None, element_transforms_, None, DT.CATEGORICAL) diff --git a/tests/integration/test_headers_and_subtotals.py b/tests/integration/test_headers_and_subtotals.py index d24f9a86a..2bd4892ef 100644 --- a/tests/integration/test_headers_and_subtotals.py +++ b/tests/integration/test_headers_and_subtotals.py @@ -1009,7 +1009,7 @@ def test_col_labels_with_top_hs(self): "Latino and other voters", ] - def it_calculate_col_residuals_for_subtotals(self): + def test_it_calculate_col_residuals_for_subtotals(self): slice_ = Cube(CR.CAT_X_CAT_HS_2ROWS_1COL).partitions[0] np.testing.assert_almost_equal( slice_.column_std_dev, @@ -1024,7 +1024,7 @@ def it_calculate_col_residuals_for_subtotals(self): load_python_expression("col-per-moe-cat-x-cat-hs-2rows-1col"), ) - def it_computes_residuals_for_subtotals_1col_2rows(self): + def test_it_computes_residuals_for_subtotals_1col_2rows(self): slice_ = Cube(CR.CAT_X_CAT_HS_2ROWS_1COL).partitions[0] np.testing.assert_almost_equal( @@ -1265,7 +1265,7 @@ def it_computes_residuals_for_subtotals_1col_2rows(self): ], ) - def it_calculates_residuals_for_multiple_insertions(self): + def test_it_calculates_residuals_for_multiple_insertions(self): slice_ = Cube(CR.FOOD_GROUP_X_SHAPE_PASTA_2ROWS1COL_INSERTION).partitions[0] assert slice_.inserted_column_idxs == (3,) @@ -1832,7 +1832,7 @@ def it_calculates_residuals_for_multiple_insertions(self): ], ) - def it_calculates_residuals_for_columns_insertion(self): + def test_it_calculates_residuals_for_columns_insertion(self): transforms = { "columns_dimension": { "insertions": [ @@ -2021,7 +2021,7 @@ def it_calculates_residuals_for_columns_insertion(self): ], ) - def it_calculates_residuals_for_rows_insertion(self): + def test_it_calculates_residuals_for_rows_insertion(self): transforms = {"columns_dimension": {"insertions": {}}} slice_ = Cube(CR.CAT_HS_MT_X_CAT_HS_MT, transforms=transforms).partitions[0] @@ -2385,7 +2385,7 @@ def it_calculates_residuals_for_rows_insertion(self): ], ) - def it_calculates_residuals_for_cat_x_cat_with_missing_1_col_insertion(self): + def test_it_calculates_residuals_for_cat_x_cat_with_missing_1_col_insertion(self): slice_ = Cube(CR.CAT_X_CAT_HS_MISSING).partitions[0] assert slice_.inserted_column_idxs == (0,) @@ -2481,7 +2481,9 @@ def it_calculates_residuals_for_cat_x_cat_with_missing_1_col_insertion(self): ], ) - def it_calculates_residuals_for_cat_x_num_hs_pruned_with_3_rows_insertions(self): + def test_it_calculates_residuals_for_cat_x_num_hs_pruned_with_3_rows_insertions( + self, + ): transforms = { "rows_dimension": {"prune": True}, "columns_dimension": {"prune": True}, @@ -2522,7 +2524,7 @@ def it_calculates_residuals_for_cat_x_num_hs_pruned_with_3_rows_insertions(self) ], ) - def it_calculates_residuals_for_cat_x_items_x_cats_with_col_insertion(self): + def test_it_calculates_residuals_for_cat_x_items_x_cats_with_col_insertion(self): slice_ = Cube(CR.CAT_X_ITEMS_X_CATS_HS).partitions[2] assert slice_.zscores == pytest.approx(np.full((8, 11), np.nan), nan_ok=True) @@ -2753,7 +2755,7 @@ def it_calculates_residuals_for_cat_x_items_x_cats_with_col_insertion(self): ) ) - def it_provide_residual_test_stats_including_hs(self): + def test_it_provide_residual_test_stats_including_hs(self): slice_ = Cube(CR.CAT_X_CAT_HS_2ROWS_1COL).partitions[0] np.testing.assert_array_equal(slice_.pvals, slice_.residual_test_stats[0]) np.testing.assert_array_equal(slice_.zscores, slice_.residual_test_stats[1]) @@ -2761,10 +2763,10 @@ def it_provide_residual_test_stats_including_hs(self): assert slice_.residual_test_stats.shape == (2, 6, 7) -class DescribeIntegrated_SubtotalDifferences: +class TestIntegrated_SubtotalDifferences: """TDD driver(s) for Subtotal Difference insertions.""" - def it_computes_diff_for_cat_date_on_a_3D_cube(self): + def test_it_computes_diff_for_cat_date_on_a_3D_cube(self): cube = Cube( CR.CAT_X_MR_X_CAT_DATE, transforms={ @@ -2801,7 +2803,7 @@ def it_computes_diff_for_cat_date_on_a_3D_cube(self): ) ) - def it_computes_diff_for_cat_date(self): + def test_it_computes_diff_for_cat_date(self): strand = Cube( CR.CAT_DATE, transforms={ @@ -2843,7 +2845,7 @@ def it_computes_diff_for_cat_date(self): ) ) - def it_computes_nan_diff_for_cat_date_with_multiple_addend_or_subtrahend(self): + def test_it_computes_nan_diff_for_cat_date_with_multiple_addend_or_subtrahend(self): strand = Cube( CR.CAT_DATE, transforms={ @@ -2871,7 +2873,7 @@ def it_computes_nan_diff_for_cat_date_with_multiple_addend_or_subtrahend(self): strand.table_proportions[0] ) # nan insertion because the diff subtotal has multiple positive terms - def it_computes_diff_for_cat_x_cat_date_with_subdiffs_on_column(self): + def test_it_computes_diff_for_cat_x_cat_date_with_subdiffs_on_column(self): insertions = [ { "function": "subtotal", @@ -2917,7 +2919,7 @@ def it_computes_diff_for_cat_x_cat_date_with_subdiffs_on_column(self): np.array([np.nan, np.nan, np.nan, np.nan, np.nan]), nan_ok=True ) - def it_computes_diff_for_cat_x_cat_date_with_subdiffs_on_both(self): + def test_it_computes_diff_for_cat_x_cat_date_with_subdiffs_on_both(self): slice_ = Cube( CR.CAT_X_CAT_DATE, transforms={ @@ -2979,7 +2981,7 @@ def it_computes_diff_for_cat_x_cat_date_with_subdiffs_on_both(self): rel=1e-4, ) - def it_computes_diff_for_cat_date_x_cat_with_subdiffs_on_both(self): + def test_it_computes_diff_for_cat_date_x_cat_with_subdiffs_on_both(self): slice_ = Cube( CR.CAT_DATE_X_CAT, transforms={ @@ -3082,7 +3084,7 @@ def it_computes_diff_for_cat_date_x_cat_with_subdiffs_on_both(self): nan_ok=True, ) - def it_computes_diff_for_cat_date_x_cat_with_subdiffs_on_rows(self): + def test_it_computes_diff_for_cat_date_x_cat_with_subdiffs_on_rows(self): insertions = [ { "function": "subtotal", @@ -3136,7 +3138,7 @@ def it_computes_diff_for_cat_date_x_cat_with_subdiffs_on_rows(self): nan_ok=True, ) - def it_computes_measures_for_1D_cat_with_subdiffs(self): + def test_it_computes_measures_for_1D_cat_with_subdiffs(self): strand = Cube( CR.CAT, transforms={ @@ -3161,7 +3163,7 @@ def it_computes_measures_for_1D_cat_with_subdiffs(self): assert strand.table_proportion_moes[0] == pytest.approx(0.05216430) assert strand.population_counts[0] == pytest.approx(np.nan, nan_ok=True) - def it_computes_measures_for_cat_x_cat_with_subdiffs_on_both(self): + def test_it_computes_measures_for_cat_x_cat_with_subdiffs_on_both(self): slice_ = Cube( CR.CAT_4_X_CAT_4, transforms={ @@ -3276,7 +3278,7 @@ def it_computes_measures_for_cat_x_cat_with_subdiffs_on_both(self): np.full(5, np.nan), nan_ok=True ) - def it_computes_measures_for_cat_x_cat_with_subdiffs_and_subtot_on_both(self): + def test_it_computes_measures_for_cat_x_cat_with_subdiffs_and_subtot_on_both(self): slice_ = Cube( CR.CAT_4_X_CAT_4, transforms={ @@ -3358,7 +3360,7 @@ def it_computes_measures_for_cat_x_cat_with_subdiffs_and_subtot_on_both(self): assert slice_.pvals[:, 0] == pytest.approx(np.full(6, np.nan), nan_ok=True) assert slice_.pvals[0, :] == pytest.approx(np.full(6, np.nan), nan_ok=True) - def it_computes_measures_for_ca_with_subdiff(self): + def test_it_computes_measures_for_ca_with_subdiff(self): slice_ = Cube( CR.CA_CAT_X_CA_SUBVAR, transforms={ @@ -3393,7 +3395,7 @@ def it_computes_measures_for_ca_with_subdiff(self): assert slice_.zscores[0, :] == pytest.approx(np.full(3, np.nan), nan_ok=True) assert slice_.pvals[0, :] == pytest.approx(np.full(3, np.nan), nan_ok=True) - def it_computes_measures_for_mr_x_cat_subdiff(self): + def test_it_computes_measures_for_mr_x_cat_subdiff(self): slice_ = Cube( CR.MR_X_CAT, transforms={ @@ -3435,7 +3437,7 @@ def it_computes_measures_for_mr_x_cat_subdiff(self): assert slice_.zscores[:, 0] == pytest.approx(np.full(5, np.nan), nan_ok=True) assert slice_.pvals[:, 0] == pytest.approx(np.full(5, np.nan), nan_ok=True) - def it_computes_scale_median_for_cat_with_subdiff_x_cat_with_subdiff(self): + def test_it_computes_scale_median_for_cat_with_subdiff_x_cat_with_subdiff(self): slice_ = Cube( CR.CAT_HS_MT_X_CAT_HS_MT, transforms={ @@ -3472,7 +3474,7 @@ def it_computes_scale_median_for_cat_with_subdiff_x_cat_with_subdiff(self): [np.nan, 2, 1, 2, 2, np.nan, 2], nan_ok=True ) - def it_computes_sum_for_numarray_with_subdiffs_and_subtot_on_columns(self): + def test_it_computes_sum_for_numarray_with_subdiffs_and_subtot_on_columns(self): slice_ = Cube( NA.NUM_ARR_SUM_GROUPED_BY_CAT, transforms={ @@ -3518,7 +3520,9 @@ def it_computes_sum_for_numarray_with_subdiffs_and_subtot_on_columns(self): ) ) - def it_computes_share_of_sum_for_numarray_with_subdiffs_and_subtot_on_columns(self): + def test_it_computes_share_of_sum_for_numarray_with_subdiffs_and_subtot_on_columns( + self, + ): slice_ = Cube( NA.NUM_ARR_SUM_GROUPED_BY_CAT, transforms={ @@ -3604,7 +3608,7 @@ def it_computes_share_of_sum_for_numarray_with_subdiffs_and_subtot_on_columns(se nan_ok=True, ) - def it_computes_diff_indexes_for_cat_x_cat_with_subdiffs_on_both(self): + def test_it_computes_diff_indexes_for_cat_x_cat_with_subdiffs_on_both(self): slice_ = Cube( CR.CAT_4_X_CAT_4, transforms={ diff --git a/tests/integration/test_matrix.py b/tests/integration/test_matrix.py index 1fc2db503..739a7cbe1 100644 --- a/tests/integration/test_matrix.py +++ b/tests/integration/test_matrix.py @@ -15,10 +15,10 @@ from ..fixtures import CR, OL -class DescribeAssembler: +class TestAssembler: """Integration-test suite for `cr.cube.matrix.Assembler`.""" - def it_computes_column_proportions_for_cat_x_cat(self): + def test_it_computes_column_proportions_for_cat_x_cat(self): slice_ = _Slice(Cube(CR.CAT_4_X_CAT_5), 0, None, None, 0) assert np.round(slice_.column_proportions, 2) == pytest.approx( np.array( @@ -31,7 +31,7 @@ def it_computes_column_proportions_for_cat_x_cat(self): ) ) - def it_computes_column_unweighted_bases_for_cat_hs_x_cat_hs(self): + def test_it_computes_column_unweighted_bases_for_cat_hs_x_cat_hs(self): slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), slice_idx=0, @@ -61,7 +61,7 @@ def it_computes_column_unweighted_bases_for_cat_hs_x_cat_hs(self): [549, 328, 276, 273, 328], ] - def it_computes_column_unweighted_bases_for_cat_hs_x_mr(self): + def test_it_computes_column_unweighted_bases_for_cat_hs_x_mr(self): slice_ = Cube(CR.CAT_HS_X_MR).partitions[0] assert slice_.column_unweighted_bases == pytest.approx( np.array( @@ -78,7 +78,7 @@ def it_computes_column_unweighted_bases_for_cat_hs_x_mr(self): ) ) - def it_computes_column_unweighted_bases_for_mr_x_cat_hs(self): + def test_it_computes_column_unweighted_bases_for_mr_x_cat_hs(self): slice_ = Cube(CR.MR_X_CAT_HS_MT).partitions[0] assert slice_.column_unweighted_bases.tolist() == [ [15, 24, 39, 0, 57, 69, 0, 126], @@ -88,7 +88,7 @@ def it_computes_column_unweighted_bases_for_mr_x_cat_hs(self): [32, 69, 101, 0, 167, 208, 0, 375], ] - def it_computes_column_unweighted_bases_for_mr_x_mr(self): + def test_it_computes_column_unweighted_bases_for_mr_x_mr(self): slice_ = Cube(CR.MR_X_MR).partitions[0] assert slice_.column_unweighted_bases.tolist() == [ [12, 18, 26, 44], @@ -97,7 +97,7 @@ def it_computes_column_unweighted_bases_for_mr_x_mr(self): [12, 29, 34, 61], ] - def it_computes_column_weighted_bases_for_cat_hs_x_cat_hs(self): + def test_it_computes_column_weighted_bases_for_cat_hs_x_cat_hs(self): slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), slice_idx=0, @@ -127,7 +127,7 @@ def it_computes_column_weighted_bases_for_cat_hs_x_cat_hs(self): [549, 328, 276, 273, 328], ] - def it_computes_column_weighted_bases_for_cat_hs_x_mr(self): + def test_it_computes_column_weighted_bases_for_cat_hs_x_mr(self): slice_ = Cube(CR.CAT_HS_X_MR).partitions[0] assert slice_.column_weighted_bases == pytest.approx( np.array( @@ -144,7 +144,7 @@ def it_computes_column_weighted_bases_for_cat_hs_x_mr(self): ) ) - def it_computes_column_weighted_bases_for_mr_x_cat_hs(self): + def test_it_computes_column_weighted_bases_for_mr_x_cat_hs(self): slice_ = Cube(CR.MR_X_CAT_HS_MT).partitions[0] assert slice_.column_weighted_bases == pytest.approx( np.array( @@ -203,7 +203,7 @@ def it_computes_column_weighted_bases_for_mr_x_cat_hs(self): ) ) - def it_computes_column_weighted_bases_for_mr_x_mr(self): + def test_it_computes_column_weighted_bases_for_mr_x_mr(self): slice_ = Cube(CR.MR_X_MR).partitions[0] assert slice_.column_weighted_bases == pytest.approx( np.array( @@ -216,7 +216,7 @@ def it_computes_column_weighted_bases_for_mr_x_mr(self): ) ) - def it_computes_row_unweighted_bases_for_cat_hs_x_cat_hs(self): + def test_it_computes_row_unweighted_bases_for_cat_hs_x_cat_hs(self): slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), slice_idx=0, @@ -246,7 +246,7 @@ def it_computes_row_unweighted_bases_for_cat_hs_x_cat_hs(self): [575, 575, 575, 575, 575], ] - def it_computes_row_unweighted_bases_for_cat_hs_x_mr_for(self): + def test_it_computes_row_unweighted_bases_for_cat_hs_x_mr_for(self): slice_ = Cube(CR.CAT_HS_X_MR).partitions[0] assert slice_.row_unweighted_bases.tolist() == [ [15, 15, 13, 20, 32], @@ -259,7 +259,7 @@ def it_computes_row_unweighted_bases_for_cat_hs_x_mr_for(self): [126, 161, 192, 380, 375], ] - def it_computes_row_unweighted_bases_for_mr_x_cat_hs_for(self): + def test_it_computes_row_unweighted_bases_for_mr_x_cat_hs_for(self): slice_ = Cube(CR.MR_X_CAT_HS_MT).partitions[0] assert slice_.row_unweighted_bases.tolist() == [ [26, 26, 26, 26, 26, 26, 26, 26], @@ -269,7 +269,7 @@ def it_computes_row_unweighted_bases_for_mr_x_cat_hs_for(self): [385, 385, 385, 385, 385, 385, 385, 385], ] - def it_computes_row_unweighted_bases_for_mr_x_mr_for(self): + def test_it_computes_row_unweighted_bases_for_mr_x_mr_for(self): slice_ = Cube(CR.MR_X_MR).partitions[0] assert slice_.row_unweighted_bases.tolist() == [ [12, 7, 10, 12], @@ -278,7 +278,7 @@ def it_computes_row_unweighted_bases_for_mr_x_mr_for(self): [44, 45, 53, 61], ] - def it_computes_row_weighted_bases_for_cat_hs_x_cat_hs(self): + def test_it_computes_row_weighted_bases_for_cat_hs_x_cat_hs(self): slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), slice_idx=0, @@ -308,7 +308,7 @@ def it_computes_row_weighted_bases_for_cat_hs_x_cat_hs(self): [575, 575, 575, 575, 575], ] - def it_computes_row_weighted_bases_for_cat_hs_x_mr(self): + def test_it_computes_row_weighted_bases_for_cat_hs_x_mr(self): slice_ = Cube(CR.CAT_HS_X_MR).partitions[0] assert slice_.row_weighted_bases == pytest.approx( np.array( @@ -325,7 +325,7 @@ def it_computes_row_weighted_bases_for_cat_hs_x_mr(self): ) ) - def it_computes_row_weighted_bases_for_mr_x_cat_hs(self): + def test_it_computes_row_weighted_bases_for_mr_x_cat_hs(self): slice_ = Cube(CR.MR_X_CAT_HS_MT).partitions[0] assert slice_.row_weighted_bases == pytest.approx( np.array( @@ -384,7 +384,7 @@ def it_computes_row_weighted_bases_for_mr_x_cat_hs(self): ) ) - def it_computes_row_weighted_bases_for_mr_x_mr(self): + def test_it_computes_row_weighted_bases_for_mr_x_mr(self): slice_ = Cube(CR.MR_X_MR).partitions[0] assert slice_.row_weighted_bases == pytest.approx( np.array( @@ -397,7 +397,7 @@ def it_computes_row_weighted_bases_for_mr_x_mr(self): ) ) - def it_computes_table_unweighted_bases_for_cat_hs_x_cat_hs(self): + def test_it_computes_table_unweighted_bases_for_cat_hs_x_cat_hs(self): slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), slice_idx=0, @@ -427,7 +427,7 @@ def it_computes_table_unweighted_bases_for_cat_hs_x_cat_hs(self): [877, 877, 877, 877, 877], ] - def it_computes_table_unweighted_bases_for_cat_hs_x_mr(self): + def test_it_computes_table_unweighted_bases_for_cat_hs_x_mr(self): slice_ = Cube(CR.CAT_HS_X_MR).partitions[0] assert slice_.table_unweighted_bases.tolist() == [ [165, 210, 242, 450, 476], @@ -440,7 +440,7 @@ def it_computes_table_unweighted_bases_for_cat_hs_x_mr(self): [165, 210, 242, 450, 476], ] - def it_computes_table_unweighted_bases_for_mr_x_cat_hs(self): + def test_it_computes_table_unweighted_bases_for_mr_x_cat_hs(self): slice_ = Cube(CR.MR_X_CAT_HS_MT).partitions[0] assert slice_.table_unweighted_bases.tolist() == [ [165, 165, 165, 165, 165, 165, 165, 165], @@ -450,7 +450,7 @@ def it_computes_table_unweighted_bases_for_mr_x_cat_hs(self): [476, 476, 476, 476, 476, 476, 476, 476], ] - def it_computes_table_unweighted_bases_for_mr_x_mr(self): + def test_it_computes_table_unweighted_bases_for_mr_x_mr(self): slice_ = Cube(CR.MR_X_MR).partitions[0] assert slice_.table_unweighted_bases.tolist() == [ [68, 43, 51, 68], @@ -459,7 +459,7 @@ def it_computes_table_unweighted_bases_for_mr_x_mr(self): [68, 60, 72, 96], ] - def it_computes_table_weighted_bases_for_cat_hs_x_cat_hs(self): + def test_it_computes_table_weighted_bases_for_cat_hs_x_cat_hs(self): slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), slice_idx=0, @@ -489,7 +489,7 @@ def it_computes_table_weighted_bases_for_cat_hs_x_cat_hs(self): [877, 877, 877, 877, 877], ] - def it_computes_table_weighted_bases_for_cat_hs_x_mr(self): + def test_it_computes_table_weighted_bases_for_cat_hs_x_mr(self): slice_ = Cube(CR.CAT_HS_X_MR).partitions[0] assert slice_.table_weighted_bases == pytest.approx( np.array( @@ -506,7 +506,7 @@ def it_computes_table_weighted_bases_for_cat_hs_x_mr(self): ) ) - def it_computes_table_weighted_bases_for_mr_x_cat_hs(self): + def test_it_computes_table_weighted_bases_for_mr_x_cat_hs(self): slice_ = Cube(CR.MR_X_CAT_HS_MT).partitions[0] assert slice_.table_weighted_bases == pytest.approx( np.array( @@ -565,7 +565,7 @@ def it_computes_table_weighted_bases_for_mr_x_cat_hs(self): ) ) - def it_computes_table_weighted_bases_for_mr_x_mr(self): + def test_it_computes_table_weighted_bases_for_mr_x_mr(self): slice_ = Cube(CR.MR_X_MR).partitions[0] assert slice_.table_weighted_bases == pytest.approx( np.array( @@ -578,7 +578,7 @@ def it_computes_table_weighted_bases_for_mr_x_mr(self): ) ) - def it_computes_unweighted_counts_for_cat_hs_x_cat_hs_hiddens(self): + def test_it_computes_unweighted_counts_for_cat_hs_x_cat_hs_hiddens(self): """Assembler inserts, hides, prunes, and places in payload order.""" slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), @@ -604,7 +604,9 @@ def it_computes_unweighted_counts_for_cat_hs_x_cat_hs_hiddens(self): @pytest.mark.parametrize( "hidden_rows", ({"5": {"hide": True}}, {"00004": {"hide": True}}) ) - def it_computes_unweighted_counts_for_ca_subvar_x_ca_cat_hiddens(self, hidden_rows): + def test_it_computes_unweighted_counts_for_ca_subvar_x_ca_cat_hiddens( + self, hidden_rows + ): """Assembler hides, prunes, and places in payload order. This fixture has no insertions, and exercises the "no-insertions" case which @@ -630,7 +632,9 @@ def it_computes_unweighted_counts_for_ca_subvar_x_ca_cat_hiddens(self, hidden_ro [347, 2577, 4467], ] - def it_computes_unweighted_counts_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): + def test_it_computes_unweighted_counts_for_cat_hs_x_cat_hs_hiddens_explicit_order( + self, + ): """Assembler inserts, hides, prunes, and places in explicit order.""" slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), @@ -661,7 +665,7 @@ def it_computes_unweighted_counts_for_cat_hs_x_cat_hs_hiddens_explicit_order(sel [341, 234, 166, 175, 234], ] - def it_computes_unweighted_counts_for_cat_hs_x_mr_hiddens_explicit_order(self): + def test_it_computes_unweighted_counts_for_cat_hs_x_mr_hiddens_explicit_order(self): """Assembler inserts, hides, prunes, and places in explicit order.""" slice_ = _Slice( Cube(CR.CAT_HS_X_MR), @@ -689,7 +693,7 @@ def it_computes_unweighted_counts_for_cat_hs_x_mr_hiddens_explicit_order(self): [134, 130, 26, 39], ] - def it_computes_unweighted_counts_for_mr_x_cat(self): + def test_it_computes_unweighted_counts_for_mr_x_cat(self): slice_ = Cube(CR.MR_X_CAT).partitions[0] assert slice_.unweighted_counts.tolist() == [ [8, 7, 0, 6, 5, 0], @@ -699,7 +703,7 @@ def it_computes_unweighted_counts_for_mr_x_cat(self): [27, 58, 0, 134, 166, 0], ] - def it_computes_unweighted_counts_for_mr_x_mr_slices(self): + def test_it_computes_unweighted_counts_for_mr_x_mr_slices(self): slice_ = Cube(CR.CAT_X_MR_X_MR).partitions[0] assert slice_.unweighted_counts.tolist() == [ [1159, 3597], @@ -714,13 +718,13 @@ def it_computes_unweighted_counts_for_mr_x_mr_slices(self): [1142, 623], ] - def it_computes_ca_x_mr_hs_columns_base(self): + def test_it_computes_ca_x_mr_hs_columns_base(self): slice_ = Cube(CR.CA_X_MR_WEIGHTED_HS).partitions[0] np.testing.assert_array_equal( slice_.columns_base, np.array([504, 215, 224, 76, 8, 439]) ) - def it_computes_mr_x_mr_columns_base(self): + def test_it_computes_mr_x_mr_columns_base(self): slice_ = Cube(CR.MR_X_MR).partitions[0] np.testing.assert_array_equal( slice_.columns_base, @@ -729,11 +733,13 @@ def it_computes_mr_x_mr_columns_base(self): ), ) - def it_computes_cat_x_mr_columns_base(self): + def test_it_computes_cat_x_mr_columns_base(self): slice_ = Cube(CR.CAT_X_MR).partitions[0] np.testing.assert_array_equal(slice_.columns_base, np.array([40, 34, 38])) - def it_computes_weighted_counts_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): + def test_it_computes_weighted_counts_for_cat_hs_x_cat_hs_hiddens_explicit_order( + self, + ): slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), slice_idx=0, @@ -763,14 +769,14 @@ def it_computes_weighted_counts_for_cat_hs_x_cat_hs_hiddens_explicit_order(self) [341, 234, 166, 175, 234], ] - def it_computes_weighted_counts_for_cat_x_mr(self): + def test_it_computes_weighted_counts_for_cat_x_mr(self): slice_ = Cube(CR.CAT_X_MR).partitions[0] assert slice_.counts.tolist() == [ [12, 12, 12], [28, 22, 26], ] - def it_computes_weighted_counts_for_mr_x_cat(self): + def test_it_computes_weighted_counts_for_mr_x_cat(self): slice_ = Cube(CR.MR_X_CAT).partitions[0] assert slice_.counts == pytest.approx( np.array( @@ -784,7 +790,7 @@ def it_computes_weighted_counts_for_mr_x_cat(self): ) ) - def it_computes_weighted_counts_for_mr_x_mr(self): + def test_it_computes_weighted_counts_for_mr_x_mr(self): slice_ = Cube(CR.MR_X_MR).partitions[0] assert slice_.counts == pytest.approx( np.array( @@ -797,7 +803,7 @@ def it_computes_weighted_counts_for_mr_x_mr(self): ) ) - def it_computes_table_margin_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): + def test_it_computes_table_margin_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), slice_idx=0, @@ -819,7 +825,7 @@ def it_computes_table_margin_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): assert slice_.table_margin == 877 - def it_computes_cat_x_mr_table_margin_with_explicit_ordering(self): + def test_it_computes_cat_x_mr_table_margin_with_explicit_ordering(self): transforms = { "columns_dimension": { "order": {"type": "explicit", "element_ids": [5, 1, 6, 4, 0, 2]} @@ -832,7 +838,7 @@ def it_computes_cat_x_mr_table_margin_with_explicit_ordering(self): np.array([471.9317685, 176.3655518, 457.0509557, 211.4205877, 247.7407379]), ) - def it_computes_mr_x_cat_table_margin_with_explicit_ordering(self): + def test_it_computes_mr_x_cat_table_margin_with_explicit_ordering(self): transforms = { "rows_dimension": { "order": {"type": "explicit", "element_ids": [5, 1, 6, 4, 0, 2]} @@ -845,7 +851,7 @@ def it_computes_mr_x_cat_table_margin_with_explicit_ordering(self): np.array([471.9317685, 176.3655516, 457.0509557, 211.4205878, 247.740738]), ) - def it_computes_mr_x_mr_table_margin(self): + def test_it_computes_mr_x_mr_table_margin(self): slice_ = Cube(CR.MR_X_MR).partitions[0] np.testing.assert_almost_equal( slice_.table_margin, @@ -857,7 +863,7 @@ def it_computes_mr_x_mr_table_margin(self): ], ) - def it_knows_the_column_labels(self): + def test_it_knows_the_column_labels(self): transforms = { "columns_dimension": { "order": {"type": "explicit", "element_ids": [1, 3, 0, 2]} @@ -868,7 +874,7 @@ def it_knows_the_column_labels(self): slice_.column_labels, ["Bravo", "Delta", "Alpha", "Charlie", "Last 2"] ) - def it_computes_rows_base_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): + def test_it_computes_rows_base_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), slice_idx=0, @@ -890,7 +896,7 @@ def it_computes_rows_base_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): assert np.array_equal(slice_.rows_base, [151, 353, 603, 52, 250, 123, 575]) - def it_computes_cat_x_mr_rows_base(self): + def test_it_computes_cat_x_mr_rows_base(self): slice_ = Cube(CR.CAT_X_MR_2).partitions[0] np.testing.assert_almost_equal( slice_.rows_base, @@ -906,13 +912,13 @@ def it_computes_cat_x_mr_rows_base(self): ), ) - def it_computes_mr_x_cat_rows_base(self): + def test_it_computes_mr_x_cat_rows_base(self): slice_ = Cube(CR.MR_X_CAT).partitions[0] np.testing.assert_almost_equal( slice_.rows_base, np.array([26, 76, 118, 369, 385]) ) - def it_computes_mr_x_mr_rows_base(self): + def test_it_computes_mr_x_mr_rows_base(self): slice_ = Cube(CR.MR_X_MR).partitions[0] np.testing.assert_equal( slice_.rows_base, @@ -924,7 +930,7 @@ def it_computes_mr_x_mr_rows_base(self): ], ) - def it_computes_table_base_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): + def test_it_computes_table_base_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), slice_idx=0, @@ -946,19 +952,19 @@ def it_computes_table_base_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): assert np.array_equal(slice_.table_base, 877) - def it_computes_cat_x_mr_table_base(self): + def test_it_computes_cat_x_mr_table_base(self): slice_ = Cube(CR.CAT_X_MR_2).partitions[0] np.testing.assert_almost_equal( slice_.table_base, np.array([165, 210, 242, 450, 476]) ) - def it_computes_mr_x_cat_table_base(self): + def test_it_computes_mr_x_cat_table_base(self): slice_ = Cube(CR.MR_X_CAT).partitions[0] np.testing.assert_almost_equal( slice_.table_base, np.array([165, 210, 242, 450, 476]) ) - def it_computes_mr_x_mr_table_base(self): + def test_it_computes_mr_x_mr_table_base(self): slice_ = Cube(CR.MR_X_MR).partitions[0] np.testing.assert_equal( slice_.table_base, @@ -970,7 +976,9 @@ def it_computes_mr_x_mr_table_base(self): ], ) - def it_computes_columns_margin_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): + def test_it_computes_columns_margin_for_cat_hs_x_cat_hs_hiddens_explicit_order( + self, + ): slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), slice_idx=0, @@ -992,19 +1000,19 @@ def it_computes_columns_margin_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): assert np.array_equal(slice_.columns_margin, [549, 328, 276, 273, 328]) - def it_computes_means_cat_x_cat_columns_margin(self): + def test_it_computes_means_cat_x_cat_columns_margin(self): slice_ = Cube(CR.MEANS_CAT_HS_X_CAT_HS).partitions[0] assert slice_.columns_margin.tolist() == [431, 494, 294, 1219, 433] - def it_computes_cat_x_mr_columns_margin(self): + def test_it_computes_cat_x_mr_columns_margin(self): slice_ = Cube(CR.CAT_X_MR_2).partitions[0] assert slice_.columns_margin == pytest.approx( [31.63152, 70.730734, 125.759113, 366.888391, 376.765640] ) - def it_computes_mr_x_cat_columns_margin(self): + def test_it_computes_mr_x_cat_columns_margin(self): slice_ = Cube(CR.MR_X_CAT).partitions[0] np.testing.assert_almost_equal( slice_.columns_margin, @@ -1019,7 +1027,7 @@ def it_computes_mr_x_cat_columns_margin(self): ), ) - def it_computes_mr_x_mr_columns_margin(self): + def test_it_computes_mr_x_mr_columns_margin(self): slice_ = Cube(CR.MR_X_MR).partitions[0] np.testing.assert_almost_equal( slice_.columns_margin, @@ -1031,7 +1039,7 @@ def it_computes_mr_x_mr_columns_margin(self): ], ) - def it_computes_rows_margin_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): + def test_it_computes_rows_margin_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), slice_idx=0, @@ -1053,12 +1061,12 @@ def it_computes_rows_margin_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): assert np.array_equal(slice_.rows_margin, [151, 353, 603, 52, 250, 123, 575]) - def it_computes_means_cat_x_cat_rows_margin(self): + def test_it_computes_means_cat_x_cat_rows_margin(self): slice_ = Cube(CR.MEANS_CAT_HS_X_CAT_HS).partitions[0] assert slice_.rows_margin.tolist() == [55, 126, 613, 710, 310, 400, 148] - def it_computes_cat_x_mr_rows_margin(self): + def test_it_computes_cat_x_mr_rows_margin(self): slice_ = Cube(CR.CAT_X_MR_2).partitions[0] np.testing.assert_almost_equal( slice_.rows_margin, @@ -1074,14 +1082,14 @@ def it_computes_cat_x_mr_rows_margin(self): ), ) - def it_computes_mr_x_cat_rows_margin(self): + def test_it_computes_mr_x_cat_rows_margin(self): slice_ = Cube(CR.MR_X_CAT).partitions[0] np.testing.assert_almost_equal( slice_.rows_margin, np.array([31.6315209, 70.7307341, 125.7591136, 366.8883915, 376.7656406]), ) - def it_computes_mr_x_mr_rows_margin(self): + def test_it_computes_mr_x_mr_rows_margin(self): slice_ = Cube(CR.MR_X_MR).partitions[0] np.testing.assert_almost_equal( slice_.rows_margin, @@ -1093,7 +1101,7 @@ def it_computes_mr_x_mr_rows_margin(self): ], ) - def it_computes_column_index_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): + def test_it_computes_column_index_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): slice_ = _Slice( Cube(CR.CAT_HS_X_CAT_HS_EMPTIES), slice_idx=0, @@ -1128,7 +1136,7 @@ def it_computes_column_index_for_cat_hs_x_cat_hs_hiddens_explicit_order(self): ), ) - def it_computes_cat_x_mr_column_index(self): + def test_it_computes_cat_x_mr_column_index(self): slice_ = Cube(CR.CAT_X_MR_2).partitions[0] np.testing.assert_almost_equal( slice_.column_index, @@ -1144,7 +1152,7 @@ def it_computes_cat_x_mr_column_index(self): ), ) - def it_computes_mr_x_cat_column_index(self): + def test_it_computes_mr_x_cat_column_index(self): slice_ = Cube(CR.MR_X_CAT).partitions[0] np.testing.assert_almost_equal( slice_.column_index, @@ -1159,7 +1167,7 @@ def it_computes_mr_x_cat_column_index(self): ), ) - def it_computes_mr_x_mr_column_index(self): + def test_it_computes_mr_x_mr_column_index(self): slice_ = Cube(CR.MR_X_MR).partitions[0] np.testing.assert_almost_equal( slice_.column_index, @@ -1173,7 +1181,7 @@ def it_computes_mr_x_mr_column_index(self): ), ) - def it_computes_cat_hs_x_cat_hs_zscore_subtotals(self): + def test_it_computes_cat_hs_x_cat_hs_zscore_subtotals(self): slice_ = Cube(CR.CAT_HS_X_CAT_HS).partitions[0] np.testing.assert_almost_equal( slice_.zscores, @@ -1190,7 +1198,7 @@ def it_computes_cat_hs_x_cat_hs_zscore_subtotals(self): ), ) - def it_computes_cat_x_mr_zscores(self): + def test_it_computes_cat_x_mr_zscores(self): slice_ = Cube(CR.CAT_X_MR_2).partitions[0] assert slice_.zscores == pytest.approx( np.array( @@ -1206,7 +1214,7 @@ def it_computes_cat_x_mr_zscores(self): nan_ok=True, ) - def it_computes_mr_x_cat_zscores(self): + def test_it_computes_mr_x_cat_zscores(self): slice_ = Cube(CR.MR_X_CAT).partitions[0] np.testing.assert_almost_equal( slice_.zscores, @@ -1221,7 +1229,7 @@ def it_computes_mr_x_cat_zscores(self): ), ) - def it_computes_mr_x_mr_zscores(self): + def test_it_computes_mr_x_mr_zscores(self): slice_ = Cube(CR.MR_X_MR).partitions[0] np.testing.assert_almost_equal( slice_.zscores, @@ -1235,7 +1243,7 @@ def it_computes_mr_x_mr_zscores(self): ), ) - def it_computes_means_cat_hs_x_cat_hs(self): + def test_it_computes_means_cat_hs_x_cat_hs(self): slice_ = Cube(CR.MEANS_CAT_HS_X_CAT_HS).partitions[0] np.testing.assert_almost_equal( slice_.means, @@ -1252,7 +1260,7 @@ def it_computes_means_cat_hs_x_cat_hs(self): ), ) - def it_computes_means_cat_x_mr(self): + def test_it_computes_means_cat_x_mr(self): slice_ = Cube(CR.MEANS_CAT_X_MR).partitions[0] np.testing.assert_almost_equal( slice_.means, @@ -1268,7 +1276,7 @@ def it_computes_means_cat_x_mr(self): ), ) - def it_computes_median_cat_x_mr(self): + def test_it_computes_median_cat_x_mr(self): slice_ = Cube(CR.MEDIAN_CAT_X_MR).partitions[0] np.testing.assert_almost_equal( slice_.medians, @@ -1284,7 +1292,7 @@ def it_computes_median_cat_x_mr(self): ), ) - def it_computes_median_for_mr_x_mr(self): + def test_it_computes_median_for_mr_x_mr(self): slice_ = Cube(CR.MR_X_MR_MEDIAN).partitions[0] assert slice_.medians == pytest.approx( @@ -1298,7 +1306,7 @@ def it_computes_median_for_mr_x_mr(self): nan_ok=True, ) - def it_computes_means_mr_x_cat(self): + def test_it_computes_means_mr_x_cat(self): slice_ = Cube(CR.MEANS_MR_X_CAT).partitions[0] np.testing.assert_almost_equal( slice_.means, @@ -1434,7 +1442,7 @@ def it_computes_means_mr_x_cat(self): ), ) - def it_computes_cat_hs_mt_x_cat_hs_mt_tbl_stderr(self): + def test_it_computes_cat_hs_mt_x_cat_hs_mt_tbl_stderr(self): slice_ = Cube(CR.CAT_HS_MT_X_CAT_HS_MT).partitions[0] np.testing.assert_almost_equal( slice_.table_std_err, @@ -1451,7 +1459,7 @@ def it_computes_cat_hs_mt_x_cat_hs_mt_tbl_stderr(self): ), ) - def it_computes_cat_x_mr_table_stderr(self): + def test_it_computes_cat_x_mr_table_stderr(self): slice_ = Cube(CR.CAT_X_MR_2).partitions[0] np.testing.assert_almost_equal( slice_.table_std_err, @@ -1467,7 +1475,7 @@ def it_computes_cat_x_mr_table_stderr(self): ), ) - def it_computes_mr_x_cat_table_stderr(self): + def test_it_computes_mr_x_cat_table_stderr(self): slice_ = Cube(CR.MR_X_CAT).partitions[0] np.testing.assert_almost_equal( slice_.table_std_err, @@ -1482,7 +1490,7 @@ def it_computes_mr_x_cat_table_stderr(self): ), ) - def it_computes_mr_x_mr_table_stderr(self): + def test_it_computes_mr_x_mr_table_stderr(self): slice_ = Cube(CR.MR_X_MR).partitions[0] np.testing.assert_almost_equal( slice_.table_std_err, @@ -1505,7 +1513,7 @@ def it_computes_mr_x_mr_table_stderr(self): (CR.MR_X_MR, 3, True, [3, 2, 1, 0]), ), ) - def it_computes_the_sort_by_value_row_order_to_help( + def test_it_computes_the_sort_by_value_row_order_to_help( self, fixture, element_id, descending, expected_value ): transforms = { @@ -1522,21 +1530,21 @@ def it_computes_the_sort_by_value_row_order_to_help( assert slice_.row_order().tolist() == expected_value - def it_computes_sum_cat_x_mr(self): + def test_it_computes_sum_cat_x_mr(self): slice_ = Cube(CR.SUM_CAT_X_MR).partitions[0] assert slice_.sums == pytest.approx( np.array([[3.0, 2.0, 2.0], [0.0, 0.0, 0.0]]) ) - def it_computes_sum_mr_x_cat(self): + def test_it_computes_sum_mr_x_cat(self): slice_ = Cube(CR.SUM_MR_X_CAT).partitions[0] assert slice_.sums == pytest.approx( np.array([[3.0, 0.0], [2.0, 0.0], [2.0, 0.0]]) ) - def it_computes_median_mr_x_cat(self): + def test_it_computes_median_mr_x_cat(self): slice_ = Cube(CR.MEDIAN_MR_X_CAT).partitions[0] assert slice_.medians == pytest.approx( @@ -1544,8 +1552,8 @@ def it_computes_median_mr_x_cat(self): ) -class DescribeCubemeasure: - def it_provides_overlaps_for_cat_x_mr_sub_x_mr_sel(self): +class TestCubemeasure: + def test_it_provides_overlaps_for_cat_x_mr_sub_x_mr_sel(self): cube_dict = OL.CAT_X_MR_SUB_X_MR_SEL overlaps_measure = _BaseCubeOverlaps.factory( cube=Cube(cube_dict), @@ -1567,7 +1575,7 @@ def it_provides_overlaps_for_cat_x_mr_sub_x_mr_sel(self): ], ] - def it_provides_valid_overlaps_for_cat_x_mr_sub_x_mr_sel(self): + def test_it_provides_valid_overlaps_for_cat_x_mr_sub_x_mr_sel(self): cube_dict = OL.CAT_X_MR_SUB_X_MR_SEL overlaps_measure = _BaseCubeOverlaps.factory( cube=Cube(cube_dict), @@ -1588,7 +1596,7 @@ def it_provides_valid_overlaps_for_cat_x_mr_sub_x_mr_sel(self): ], ] - def it_provides_overlaps_for_ca_sub_x_ca_cat_x_mr_sub_x_mr_sel_subvar_0(self): + def test_it_provides_overlaps_for_ca_sub_x_ca_cat_x_mr_sub_x_mr_sel_subvar_0(self): # Test subvar X (partitiions[0]) cube_dict = OL.CA_SUB_X_CA_CAT_X_MR_SUB_X_MR_SEL overlaps_measure = _BaseCubeOverlaps.factory( @@ -1615,7 +1623,9 @@ def it_provides_overlaps_for_ca_sub_x_ca_cat_x_mr_sub_x_mr_sel_subvar_0(self): ], ] - def it_provides_valid_overlaps_for_ca_sub_x_ca_cat_x_mr_sub_x_mr_sel_subvar_0(self): + def test_it_provides_valid_overlaps_for_ca_sub_x_ca_cat_x_mr_sub_x_mr_sel_subvar_0( + self, + ): # Test subvar X (partitiions[0]) cube_dict = OL.CA_SUB_X_CA_CAT_X_MR_SUB_X_MR_SEL overlaps_measure = _BaseCubeOverlaps.factory( @@ -1642,7 +1652,7 @@ def it_provides_valid_overlaps_for_ca_sub_x_ca_cat_x_mr_sub_x_mr_sel_subvar_0(se ], ] - def it_provides_overlaps_for_ca_sub_x_ca_cat_x_mr_sub_x_mr_sel_subvar_1(self): + def test_it_provides_overlaps_for_ca_sub_x_ca_cat_x_mr_sub_x_mr_sel_subvar_1(self): # Test subvar Y (partitions[1]) cube_dict = OL.CA_SUB_X_CA_CAT_X_MR_SUB_X_MR_SEL overlaps_measure = _BaseCubeOverlaps.factory( @@ -1669,7 +1679,9 @@ def it_provides_overlaps_for_ca_sub_x_ca_cat_x_mr_sub_x_mr_sel_subvar_1(self): ], ] - def it_provides_valid_overlaps_for_ca_sub_x_ca_cat_x_mr_sub_x_mr_sel_subvar_1(self): + def test_it_provides_valid_overlaps_for_ca_sub_x_ca_cat_x_mr_sub_x_mr_sel_subvar_1( + self, + ): # Test subvar X (partitiions[1]) cube_dict = OL.CA_SUB_X_CA_CAT_X_MR_SUB_X_MR_SEL overlaps_measure = _BaseCubeOverlaps.factory( @@ -1697,7 +1709,7 @@ def it_provides_valid_overlaps_for_ca_sub_x_ca_cat_x_mr_sub_x_mr_sel_subvar_1(se ] -class Describe_BaseOrderHelper: +class Test_BaseOrderHelper: """Integration-test suite for `cr.cube.matrix._BaseOrderHelper`.""" @pytest.mark.parametrize( @@ -1709,7 +1721,7 @@ class Describe_BaseOrderHelper: (CR.MR_X_MR, [2, 0, 3, 1], [1, 3, 2, 0]), ), ) - def it_can_compute_an_explicit_row_order( + def test_it_can_compute_an_explicit_row_order( self, fixture, element_ids, expected_value ): transforms = { @@ -1736,7 +1748,7 @@ def it_can_compute_an_explicit_row_order( (CR.MR_X_MR, [2, 0, 3, 1], [1, 3, 2, 0]), ), ) - def it_can_compute_an_explicit_column_order( + def test_it_can_compute_an_explicit_column_order( self, fixture, element_ids, expected_value ): transforms = { @@ -1755,7 +1767,7 @@ def it_can_compute_an_explicit_column_order( assert column_display_order.tolist() == expected_value -class Describe_SortRowsByColumnValueHelper: +class Test_SortRowsByColumnValueHelper: """Integration-test suite for `cr.cube.matrix._SortRowsByColumnValueHelper`.""" @pytest.mark.parametrize( @@ -1808,7 +1820,7 @@ class Describe_SortRowsByColumnValueHelper: (CR.MR_X_CAT, "z_score", 2, "ascending", [3, 2, 1, 0, 4]), ), ) - def it_can_compute_a_sort_by_column_values_row_order( + def test_it_can_compute_a_sort_by_column_values_row_order( self, fixture, measure, element_id, direction, expected_value ): transforms = { @@ -1826,7 +1838,7 @@ def it_can_compute_a_sort_by_column_values_row_order( assert slice_.row_order().tolist() == expected_value -class Describe_SortRowsByInsertedColumnHelper: +class Test_SortRowsByInsertedColumnHelper: """Integration-test suite for `cr.cube.matrix._SortRowsByInsertedColumnHelper`.""" @pytest.mark.parametrize( @@ -1848,7 +1860,7 @@ class Describe_SortRowsByInsertedColumnHelper: ), ), ) - def it_can_compute_a_sort_by_insertion_values_row_order( + def test_it_can_compute_a_sort_by_insertion_values_row_order( self, fixture, measure, direction, fixed, expected_value ): transforms = { @@ -1866,7 +1878,7 @@ def it_can_compute_a_sort_by_insertion_values_row_order( assert slice_.row_order().tolist() == expected_value - def but_it_fallback_to_payload_order_when_sort_by_value_is_not_supported(self): + def test_but_it_fallback_to_payload_order_when_sort_by_value_is_not_supported(self): transforms = { "rows_dimension": { "order": { diff --git a/tests/integration/test_numeric_array.py b/tests/integration/test_numeric_array.py index febb92ef9..313bef707 100644 --- a/tests/integration/test_numeric_array.py +++ b/tests/integration/test_numeric_array.py @@ -10,10 +10,10 @@ from ..fixtures import NA -class DescribeNumericArrays: +class TestNumericArrays: """Test-suite for numeric-array behaviors.""" - def it_provides_means_scale_measures(self): + def test_it_provides_means_scale_measures(self): slice_ = Cube(NA.NUM_ARR_MEANS_SCALE_MEASURES).partitions[0] assert slice_.means == pytest.approx( @@ -31,7 +31,7 @@ def it_provides_means_scale_measures(self): ) assert slice_.rows_scale_median == pytest.approx([3.0, 3.0, 3.0, 3.0]) - def it_provides_means_for_num_array_grouped_by_cat(self): + def test_it_provides_means_for_num_array_grouped_by_cat(self): """Test means on numeric array, grouped by single categorical dimension.""" slice_ = Cube(NA.NUM_ARR_MEANS_GROUPED_BY_CAT).partitions[0] @@ -56,7 +56,7 @@ def it_provides_means_for_num_array_grouped_by_cat(self): {"1": {"hide": True}}, ), ) - def it_provides_means_for_num_array_hiding_transforms_grouped_by_cat( + def test_it_provides_means_for_num_array_hiding_transforms_grouped_by_cat( self, element_transform ): transforms = {"rows_dimension": {"elements": element_transform}} @@ -76,7 +76,7 @@ def it_provides_means_for_num_array_hiding_transforms_grouped_by_cat( ) assert slice_.columns_base == pytest.approx(np.array([[3, 2], [1, 1]])) - def it_provides_means_for_num_array_grouped_by_date(self): + def test_it_provides_means_for_num_array_grouped_by_date(self): """Test means on numeric array, grouped by single categorical dimension.""" slice_ = Cube(NA.NUM_ARR_MEANS_GROUPED_BY_DATE).partitions[0] @@ -94,7 +94,7 @@ def it_provides_means_for_num_array_grouped_by_date(self): np.array([[10, 9], [8, 10], [9, 10]]) ) - def it_provides_means_for_num_array_grouped_by_cat_weighted(self): + def test_it_provides_means_for_num_array_grouped_by_cat_weighted(self): """Test means on numeric array, grouped by single categorical dimension.""" slice_ = Cube(NA.NUM_ARR_MEANS_GROUPED_BY_CAT_WEIGHTED).partitions[0] @@ -111,7 +111,7 @@ def it_provides_means_for_num_array_grouped_by_cat_weighted(self): ) assert slice_.columns_base == pytest.approx(np.array([[3, 2], [3, 1], [1, 1]])) - def it_provides_means_for_num_array_x_mr(self): + def test_it_provides_means_for_num_array_x_mr(self): slice_ = Cube(NA.NUM_ARR_MEANS_X_MR).partitions[0] expected_means = [ # -------------------------MR-------------------------- @@ -127,7 +127,7 @@ def it_provides_means_for_num_array_x_mr(self): np.array([[38, 14, 6, 18, 38], [38, 14, 6, 18, 38]]) ) - def it_provides_means_for_numeric_array_with_no_grouping(self): + def test_it_provides_means_for_numeric_array_with_no_grouping(self): """Test means on no-dimensions measure of numeric array.""" strand = Cube(NA.NUM_ARR_MEANS_NO_GROUPING).partitions[0] @@ -136,7 +136,7 @@ def it_provides_means_for_numeric_array_with_no_grouping(self): assert strand.unweighted_bases.tolist() == [6, 6] assert strand.table_base_range.tolist() == [6, 6] - def it_provides_sum_for_num_array_grouped_by_cat(self): + def test_it_provides_sum_for_num_array_grouped_by_cat(self): """Test sum on numeric array, grouped by single categorical dimension.""" slice_ = Cube(NA.NUM_ARR_SUM_GROUPED_BY_CAT).partitions[0] @@ -153,7 +153,7 @@ def it_provides_sum_for_num_array_grouped_by_cat(self): ) assert slice_.columns_base == pytest.approx(np.array([[3, 2], [3, 2], [3, 2]])) - def it_provides_sum_for_num_array_grouped_by_cat_hs(self): + def test_it_provides_sum_for_num_array_grouped_by_cat_hs(self): slice_ = Cube(NA.NUM_ARR_SUM_GROUPED_BY_CAT_HS).partitions[0] assert slice_.sums == pytest.approx( @@ -177,7 +177,7 @@ def it_provides_sum_for_num_array_grouped_by_cat_hs(self): ) ) - def it_provides_stddev_for_numeric_array_with_no_grouping(self): + def test_it_provides_stddev_for_numeric_array_with_no_grouping(self): """Test stddev on no-dimensions measure of numeric array.""" strand = Cube(NA.NUM_ARR_STDDEV_NO_GROUPING).partitions[0] @@ -186,7 +186,7 @@ def it_provides_stddev_for_numeric_array_with_no_grouping(self): assert strand.unweighted_bases.tolist() == [4, 3, 2] assert strand.table_base_range.tolist() == [2, 4] - def it_provides_median_for_numeric_array_with_no_grouping(self): + def test_it_provides_median_for_numeric_array_with_no_grouping(self): """Test stddev on no-dimensions measure of numeric array.""" strand = Cube(NA.NUM_ARR_MEDIAN_NO_GROUPING).partitions[0] @@ -195,7 +195,7 @@ def it_provides_median_for_numeric_array_with_no_grouping(self): assert strand.unweighted_bases.tolist() == [4, 3, 2] assert strand.table_base_range.tolist() == [2, 4] - def it_provides_stddev_for_num_array_grouped_by_cat(self): + def test_it_provides_stddev_for_num_array_grouped_by_cat(self): """Test stddev on numeric array, grouped by single categorical dimension.""" slice_ = Cube(NA.NUM_ARR_STDDEV_GROUPED_BY_CAT).partitions[0] @@ -213,7 +213,7 @@ def it_provides_stddev_for_num_array_grouped_by_cat(self): ) assert slice_.columns_base == pytest.approx(np.array([[3, 2], [3, 1], [1, 1]])) - def it_provides_median_for_num_array_grouped_by_cat(self): + def test_it_provides_median_for_num_array_grouped_by_cat(self): slice_ = Cube(NA.NUM_ARR_MEDIAN_GROUPED_BY_CAT).partitions[0] assert slice_.medians == pytest.approx( @@ -230,7 +230,7 @@ def it_provides_median_for_num_array_grouped_by_cat(self): ) assert slice_.columns_base == pytest.approx(np.array([[3, 2], [3, 1], [1, 1]])) - def it_provides_stddev_for_num_array_x_mr(self): + def test_it_provides_stddev_for_num_array_x_mr(self): slice_ = Cube(NA.NUM_ARR_STDDEV_X_MR).partitions[0] assert slice_.stddev == pytest.approx( @@ -249,7 +249,7 @@ def it_provides_stddev_for_num_array_x_mr(self): np.array([[2, 1, 1], [1, 0, 0], [1, 1, 1]]) ) - def it_provides_median_for_num_array_x_mr(self): + def test_it_provides_median_for_num_array_x_mr(self): slice_ = Cube(NA.NUM_ARR_MEDIAN_X_MR).partitions[0] assert slice_.stddev == pytest.approx( @@ -268,7 +268,7 @@ def it_provides_median_for_num_array_x_mr(self): np.array([[2, 1, 1], [1, 0, 0], [1, 1, 1]]) ) - def it_provides_share_of_sum_for_numeric_array_with_no_grouping(self): + def test_it_provides_share_of_sum_for_numeric_array_with_no_grouping(self): strand = Cube(NA.NUM_ARR_SUM_NO_GROUPING).partitions[0] assert strand.sums == pytest.approx([25, 44]) @@ -277,7 +277,7 @@ def it_provides_share_of_sum_for_numeric_array_with_no_grouping(self): assert strand.unweighted_bases.tolist() == [6, 6] assert strand.table_base_range.tolist() == [6, 6] - def it_provides_share_of_sum_for_num_array_grouped_by_cat(self): + def test_it_provides_share_of_sum_for_num_array_grouped_by_cat(self): """Test share of sum on num array, grouped by single categorical dimension.""" slice_ = Cube(NA.NUM_ARR_SUM_GROUPED_BY_CAT).partitions[0] @@ -318,7 +318,7 @@ def it_provides_share_of_sum_for_num_array_grouped_by_cat(self): ) assert slice_.columns_base == pytest.approx(np.array([[3, 2], [3, 2], [3, 2]])) - def it_provides_share_of_sum_for_num_array_x_mr(self): + def test_it_provides_share_of_sum_for_num_array_x_mr(self): slice_ = Cube(NA.NUM_ARR_SUM_X_MR).partitions[0] assert slice_.sums == pytest.approx( @@ -370,7 +370,7 @@ def it_provides_share_of_sum_for_num_array_x_mr(self): nan_ok=True, ) - def it_provides_unweighted_valid_counts_for_num_array_grouped_by_cat(self): + def test_it_provides_unweighted_valid_counts_for_num_array_grouped_by_cat(self): slice_ = Cube(NA.NUM_ARR_SUM_GROUPED_BY_CAT).partitions[0] # unweighted valid counts @@ -380,7 +380,7 @@ def it_provides_unweighted_valid_counts_for_num_array_grouped_by_cat(self): [3.0, 2.0], ] - def it_provides_valid_counts_for_num_array_grouped_by_cat_hs(self): + def test_it_provides_valid_counts_for_num_array_grouped_by_cat_hs(self): transforms = { "columns_dimension": { "insertions": [ @@ -436,7 +436,7 @@ def it_provides_valid_counts_for_num_array_grouped_by_cat_hs(self): nan_ok=True, ) - def it_provides_unweighted_valid_counts_for_num_array_x_mr(self): + def test_it_provides_unweighted_valid_counts_for_num_array_x_mr(self): slice_ = Cube(NA.NUM_ARR_MEANS_X_MR).partitions[0] # unweighted valid counts @@ -445,7 +445,7 @@ def it_provides_unweighted_valid_counts_for_num_array_x_mr(self): [38.0, 14.0, 6.0, 18.0, 38.0], ] - def it_provides_weighted_and_unweighted_valid_counbts_for_num_array_x_mr(self): + def test_it_provides_weighted_and_unweighted_valid_counbts_for_num_array_x_mr(self): slice_ = Cube(NA.NUM_ARR_MEANS_GROUPED_BY_CAT_WEIGHTED).partitions[0] # unweighted valid counts @@ -461,13 +461,15 @@ def it_provides_weighted_and_unweighted_valid_counbts_for_num_array_x_mr(self): [0.2, 0.3], ] - def it_provides_unweighted_valid_counts_for_numeric_array_with_no_grouping(self): + def test_it_provides_unweighted_valid_counts_for_numeric_array_with_no_grouping( + self, + ): strand = Cube(NA.NUM_ARR_MEANS_NO_GROUPING).partitions[0] # unweighted valid counts assert strand.unweighted_counts.tolist() == [6.0, 6.0] - def it_provides_weighted_and_unweighted_valid_counts_for_num_arr_no_grouping_wgtd( + def test_it_provides_wgtd_and_unwgtd_valid_counts_for_num_arr_no_grouping_wgtd( self, ): strand = Cube(NA.NUM_ARR_MEANS_NO_GROUPING_WEIGHTED).partitions[0] @@ -477,7 +479,9 @@ def it_provides_weighted_and_unweighted_valid_counts_for_num_arr_no_grouping_wgt # weighted valid counts assert strand.counts.tolist() == [10.33, 11.22, 18.99, 14.55] - def it_provides_weighted_and_unweighted_valid_counts_for_num_arr_x_mr_wgtd(self): + def test_it_provides_weighted_and_unweighted_valid_counts_for_num_arr_x_mr_wgtd( + self, + ): slice_ = Cube(NA.NUM_ARR_MEANS_X_MR_WEIGHTED).partitions[0] # unweighted valid counts @@ -495,7 +499,7 @@ def it_provides_weighted_and_unweighted_valid_counts_for_num_arr_x_mr_wgtd(self) [1.898, 6.1], ] - def it_has_bases_that_dont_sum_across_num_array_subvars_x_cat(self): + def test_it_has_bases_that_dont_sum_across_num_array_subvars_x_cat(self): slice_ = Cube(NA.NUM_ARR_MEANS_GROUPED_BY_CAT).partitions[0] assert slice_.row_weighted_bases.tolist() == [ @@ -507,7 +511,9 @@ def it_has_bases_that_dont_sum_across_num_array_subvars_x_cat(self): # --- Can't sum across subvariables so column bases are the same as counts --- assert slice_.column_weighted_bases == pytest.approx(slice_.counts) - def it_has_bases_that_dont_sum_across_num_array_subvars_x_cat_with_insertion(self): + def test_it_has_bases_that_dont_sum_across_num_array_subvars_x_cat_with_insertion( + self, + ): slice_ = Cube(NA.NUM_ARR_MEANS_GROUPED_BY_CAT_HS).partitions[0] assert slice_.row_weighted_bases.tolist() == [ @@ -522,7 +528,7 @@ def it_has_bases_that_dont_sum_across_num_array_subvars_x_cat_with_insertion(sel # --- Can't sum across subvariables so column bases are the same as counts --- assert slice_.column_weighted_bases.tolist() == slice_.counts.tolist() - def it_has_bases_that_dont_sum_across_num_array_subvars_x_mr(self): + def test_it_has_bases_that_dont_sum_across_num_array_subvars_x_mr(self): slice_ = Cube(NA.NUM_ARR_MEANS_X_MR_WEIGHTED).partitions[0] row_bases = np.array( [[4.66, 8.9992], [8.243, 9.011], [5.781, 7.523445], [6.228, 8.553]] @@ -537,7 +543,7 @@ def it_has_bases_that_dont_sum_across_num_array_subvars_x_mr(self): np.array([[2.33, 7.009], [4.123, 6.777], [4.67, 6.4], [1.898, 6.1]]) ) - def it_provides_share_of_sum_for_numeric_array_with_nan_values(self): + def test_it_provides_share_of_sum_for_numeric_array_with_nan_values(self): strand = Cube(NA.NUM_ARR_SUMS_WITH_NAN_VALUES).partitions[0] assert strand.share_sum == pytest.approx( diff --git a/tests/integration/test_pairwise_significance.py b/tests/integration/test_pairwise_significance.py index 1dad43b45..678eb22e0 100644 --- a/tests/integration/test_pairwise_significance.py +++ b/tests/integration/test_pairwise_significance.py @@ -12,7 +12,7 @@ from ..util import load_python_expression -class Describe_Slice: +class Test_Slice: """Integration-test suite for pairwise-t aspects of _Slice object.""" @pytest.mark.parametrize( @@ -36,7 +36,7 @@ class Describe_Slice: (CR.MR_X_MR, {}, "mr-x-mr-pw-idxs"), ), ) - def it_provides_pairwise_indices(self, fixture, pw_indices_dict, expectation): + def test_it_provides_pairwise_indices(self, fixture, pw_indices_dict, expectation): slice_ = _Slice( Cube(fixture), slice_idx=0, @@ -61,7 +61,9 @@ def it_provides_pairwise_indices(self, fixture, pw_indices_dict, expectation): (CR.MR_X_CAT, {"alpha": [0.175, 0.01]}, "mr-x-cat-pw-idxs-alt"), ), ) - def it_provides_pairwise_indices_alt(self, fixture, pw_indices_dict, expectation): + def test_it_provides_pairwise_indices_alt( + self, fixture, pw_indices_dict, expectation + ): """Provides indicies meeting secondary sig-test threshold, when specified.""" slice_ = _Slice( Cube(fixture), @@ -87,7 +89,9 @@ def it_provides_pairwise_indices_alt(self, fixture, pw_indices_dict, expectation (CR.CAT_X_MR_2, "cat-x-mr-scale-mean-pw-idxs"), ), ) - def it_provides_columns_scale_mean_pairwise_indices(self, fixture, expectation): + def test_it_provides_columns_scale_mean_pairwise_indices( + self, fixture, expectation + ): """Provides column-indicies meeting sig-test threshold on column scale means.""" slice_ = _Slice( Cube(fixture), slice_idx=0, transforms={}, population=None, mask_size=0 @@ -112,7 +116,9 @@ def it_provides_columns_scale_mean_pairwise_indices(self, fixture, expectation): (CR.CAT_X_MR_2, "cat-x-mr-scale-mean-pw-idxs-alt"), ), ) - def it_provides_columns_scale_mean_pairwise_indices_alt(self, fixture, expectation): + def test_it_provides_columns_scale_mean_pairwise_indices_alt( + self, fixture, expectation + ): """Provides col idxs meeting secondary sig-test threshold on scale mean.""" slice_ = _Slice( Cube(fixture), diff --git a/tests/integration/test_smoothing.py b/tests/integration/test_smoothing.py index beeab7e77..72e1f5fa3 100644 --- a/tests/integration/test_smoothing.py +++ b/tests/integration/test_smoothing.py @@ -11,7 +11,7 @@ from ..util import load_python_expression -class DescribeSliceSmoothing: +class TestSliceSmoothing: """Integration-test suite for _Slice.evaluate() method.""" @pytest.mark.parametrize( @@ -31,7 +31,7 @@ class DescribeSliceSmoothing: (CR.DATETIME_X_CAT_DATE, 3, "datetime-x-cat-date-smoothed-col-idx-w3"), ), ) - def it_provides_smoothed_col_index_for_compatible_cubes( + def test_it_provides_smoothed_col_index_for_compatible_cubes( self, fixture, window, expectation ): transforms = { @@ -65,7 +65,7 @@ def it_provides_smoothed_col_index_for_compatible_cubes( (CR.DATETIME_X_CAT_DATE, 3, "datetime-x-cat-date-smoothed-col-pct-w3"), ), ) - def it_provides_smoothed_col_percent_for_compatible_cubes( + def test_it_provides_smoothed_col_percent_for_compatible_cubes( self, fixture, window, expectation ): transforms = { @@ -93,7 +93,7 @@ def it_provides_smoothed_col_percent_for_compatible_cubes( ), ), ) - def it_provides_smoothed_scale_means_for_compatible_cubes( + def test_it_provides_smoothed_scale_means_for_compatible_cubes( self, fixture, expectation ): transforms = { @@ -110,7 +110,7 @@ def it_provides_smoothed_scale_means_for_compatible_cubes( slice_.smoothed_columns_scale_mean, load_python_expression(expectation) ) - def it_provides_smoothed_means_for_numeric_array(self): + def test_it_provides_smoothed_means_for_numeric_array(self): transforms = { "columns_dimension": { "smoother": { @@ -132,7 +132,9 @@ def it_provides_smoothed_means_for_numeric_array(self): "fixture", (CR.CAT_X_MR, CR.MR_X_MR, CR.MR_X_CA_CAT_X_CA_SUBVAR, CR.CAT_DATE_X_CAT), ) - def it_warns_and_does_not_smooth_when_dimension_is_not_smoothable(self, fixture): + def test_it_warns_and_does_not_smooth_when_dimension_is_not_smoothable( + self, fixture + ): transforms = { "columns_dimension": { "smoother": { @@ -174,7 +176,7 @@ def it_warns_and_does_not_smooth_when_dimension_is_not_smoothable(self, fixture) ), ), ) - def it_warns_and_does_not_smooth_when_window_is_invalid( + def test_it_warns_and_does_not_smooth_when_window_is_invalid( self, fixture, smoothed_prop_name, prop_name, periods, window ): transforms = { @@ -198,7 +200,7 @@ def it_warns_and_does_not_smooth_when_window_is_invalid( np.testing.assert_array_almost_equal(smoothed_values, base_values) - def it_uses_default_smoothing_if_smoother_is_not_specified(self): + def test_it_uses_default_smoothing_if_smoother_is_not_specified(self): slice_ = Cube(CR.CAT_X_CAT_DATE).partitions[0] assert slice_.smoothed_column_percentages == pytest.approx( @@ -215,10 +217,10 @@ def it_uses_default_smoothing_if_smoother_is_not_specified(self): ) -class DescribeStrandMeansSmoothing: +class TestStrandMeansSmoothing: """Integration-test suite for _Strand method.""" - def it_provides_smoothed_means_cat_date(self): + def test_it_provides_smoothed_means_cat_date(self): transforms = { "rows_dimension": { "smoother": {"function": "one_sided_moving_avg", "window": 3} @@ -231,7 +233,7 @@ def it_provides_smoothed_means_cat_date(self): [np.nan, np.nan, 2.65670765025029, 2.5774816240050358], ) - def it_does_not_smooth_means_mr_mean_filt_wgtd(self): + def test_it_does_not_smooth_means_mr_mean_filt_wgtd(self): transforms = { "rows_dimension": { "smoother": {"function": "one_sided_moving_avg", "window": 3} diff --git a/tests/integration/test_stripe.py b/tests/integration/test_stripe.py index 32c151d5b..b5614e090 100644 --- a/tests/integration/test_stripe.py +++ b/tests/integration/test_stripe.py @@ -11,10 +11,10 @@ from ..fixtures import CR -class DescribeStripeAssembler: +class TestStripeAssembler: """Integration-test suite for `cr.cube.stripe.assembler.StripeAssembler` object.""" - def it_provides_values_for_univariate_cat(self): + def test_it_provides_values_for_univariate_cat(self): cube = Cube(CR.UNIVARIATE_CATEGORICAL) strand = _Strand(cube, None, None, False, 0, None) @@ -36,7 +36,7 @@ def it_provides_values_for_univariate_cat(self): assert strand.weighted_bases.tolist() == [15, 15] assert strand.weighted_counts.tolist() == [10, 5] - def it_provides_values_for_univariate_cat_means(self): + def test_it_provides_values_for_univariate_cat_means(self): cube = Cube(CR.CAT_MEANS_HS) strand = _Strand(cube, None, None, False, 0, None) @@ -62,7 +62,7 @@ def it_provides_values_for_univariate_cat_means(self): # same because they are both calculated on the (unweighted) valid-counts. assert strand.table_margin_range == pytest.approx([661, 661]) - def it_provides_values_for_univariate_mr(self): + def test_it_provides_values_for_univariate_mr(self): cube = Cube(CR.MR_WGTD) strand = _Strand(cube, None, None, False, 0, None) @@ -184,7 +184,7 @@ def it_provides_values_for_univariate_mr(self): ] ) - def it_provides_values_for_univariate_mr_means(self): + def test_it_provides_values_for_univariate_mr_means(self): cube = Cube(CR.MR_MEAN_FILT_WGTD) strand = _Strand(cube, None, None, False, 0, None) @@ -218,7 +218,7 @@ def it_provides_values_for_univariate_mr_means(self): (CR.CAT_MEAN, "sum", "descending", [4, 2, 0, 3, 1]), ), ) - def it_computes_the_sort_by_measure_value_row_order_to_help( + def test_it_computes_the_sort_by_measure_value_row_order_to_help( self, fixture, measure, direction, expected_value ): transforms = { diff --git a/tests/unit/matrix/test_assembler.py b/tests/unit/matrix/test_assembler.py index 3494fb5bb..592ae6a56 100644 --- a/tests/unit/matrix/test_assembler.py +++ b/tests/unit/matrix/test_assembler.py @@ -78,7 +78,7 @@ ) -class DescribeAssembler: +class TestAssembler: """Unit test suite for `cr.cube.cubepart` assembly methods.""" @pytest.mark.parametrize( @@ -114,7 +114,7 @@ class DescribeAssembler: ("zscores", _Zscores), ), ) - def it_assembles_various_measures( + def test_it_assembles_various_measures( self, request, _measures_prop_, @@ -152,7 +152,7 @@ def it_assembles_various_measures( ("columns_scale_median", _ScaleMedian), ), ) - def it_assembles_various_marginals( + def test_it_assembles_various_marginals( self, request, _assemble_marginal_, @@ -172,7 +172,7 @@ def it_assembles_various_marginals( _assemble_marginal_.assert_called_once_with(slice_, measure_) assert value == [[1, 2, 3], [4, 5, 6]] - def it_knows_the_column_labels(self, dimension_, _column_order_prop_): + def test_it_knows_the_column_labels(self, dimension_, _column_order_prop_): _column_order_prop_.return_value = [0, 2, 1] dimension_.element_labels = ("Alpha", "Baker") dimension_.subtotal_labels = ("Charlie",) @@ -183,7 +183,7 @@ def it_knows_the_column_labels(self, dimension_, _column_order_prop_): column_labels = slice_.column_labels assert column_labels.tolist() == ["Alpha", "Charlie", "Baker"] - def it_provides_a_1D_columns_base_for_an_X_CAT_cube_result( + def test_it_provides_a_1D_columns_base_for_an_X_CAT_cube_result( self, _measures_prop_, second_order_measures_, @@ -201,7 +201,7 @@ def it_provides_a_1D_columns_base_for_an_X_CAT_cube_result( _assemble_marginal_.assert_called_once_with(slice_, margin_unweighted_base_) assert rows_base == [[1, 2, 3], [4, 5, 6]] - def but_it_provides_a_2D_columns_base_for_an_X_MR_cube_result( + def test_but_it_provides_a_2D_columns_base_for_an_X_MR_cube_result( self, request, _measures_prop_, @@ -223,7 +223,7 @@ def but_it_provides_a_2D_columns_base_for_an_X_MR_cube_result( assert rows_base == [[1, 2, 3], [4, 5, 6], [7, 8, 9]] - def it_knows_the_columns_dimension_numeric_values( + def test_it_knows_the_columns_dimension_numeric_values( self, request, dimension_, _column_order_prop_ ): dimension_.valid_elements = tuple( @@ -241,7 +241,7 @@ def it_knows_the_columns_dimension_numeric_values( [3.0, np.nan, 1.0, np.nan], ) - def it_provides_a_1D_columns_margin_for_a_CAT_X_cube_result( + def test_it_provides_a_1D_columns_margin_for_a_CAT_X_cube_result( self, _rows_dimension_prop_, dimension_, @@ -262,7 +262,7 @@ def it_provides_a_1D_columns_margin_for_a_CAT_X_cube_result( _assemble_marginal_.assert_called_once_with(slice_, margin_weighted_base_) assert columns_margin == [[1, 2, 3], [4, 5, 6]] - def but_it_provides_a_2D_columns_margin_for_an_MR_X_cube_result( + def test_but_it_provides_a_2D_columns_margin_for_an_MR_X_cube_result( self, request, _measures_prop_, @@ -281,7 +281,7 @@ def but_it_provides_a_2D_columns_margin_for_an_MR_X_cube_result( assert columns_margin == [[1, 2], [3, 4]] - def it_provides_a_1D_columns_margin_proportion_for_a_CAT_X_cube_result( + def test_it_provides_a_1D_columns_margin_proportion_for_a_CAT_X_cube_result( self, _rows_dimension_prop_, dimension_, @@ -303,7 +303,7 @@ def it_provides_a_1D_columns_margin_proportion_for_a_CAT_X_cube_result( _assemble_marginal_.assert_called_once_with(slice_, margin_table_proportion_) assert columns_margin_proportion == [[1, 2, 3], [4, 5, 6]] - def but_it_provides_a_2D_columns_margin_proportion_for_an_MR_X_cube_result( + def test_but_it_provides_a_2D_columns_margin_proportion_for_an_MR_X_cube_result( self, request, dimensions_, @@ -343,27 +343,27 @@ def but_it_provides_a_2D_columns_margin_proportion_for_an_MR_X_cube_result( _assemble_matrix_.assert_called_once_with(slice_, [[[1], [2]], [[3], [4]]]) assert columns_margin_proportion == [[1, 2, 3], [4, 5, 6], [7, 8, 9]] - def it_knows_the_inserted_column_idxs(self, _column_order_prop_): + def test_it_knows_the_inserted_column_idxs(self, _column_order_prop_): _column_order_prop_.return_value = [2, -1, 0, -2] assert _Slice(None, None, None, None, None).inserted_column_idxs == (1, 3) - def it_knows_the_inserted_row_idxs(self, _row_order_prop_): + def test_it_knows_the_inserted_row_idxs(self, _row_order_prop_): _row_order_prop_.return_value = [0, 1, -2, 2, -1, 3] assert _Slice(None, None, None, None, None).inserted_row_idxs == (2, 4) - def it_knows_the_means(self, request, dimensions_): + def test_it_knows_the_means(self, request, dimensions_): property_mock(request, _Slice, "means", return_value=np.array([1.2, 1.34, 3.3])) slice_ = _Slice(None, dimensions_, None, None, None) assert slice_.means == pytest.approx([1.2, 1.34, 3.3]) - def it_knows_the_sum(self, request, dimensions_): + def test_it_knows_the_sum(self, request, dimensions_): property_mock(request, _Slice, "sums", return_value=np.array([4, 5, 6])) slice_ = _Slice(None, dimensions_, None, None, None) assert slice_.sums == pytest.approx([4, 5, 6]) - def it_knows_the_row_labels(self, dimension_, _row_order_prop_): + def test_it_knows_the_row_labels(self, dimension_, _row_order_prop_): _row_order_prop_.return_value = [0, 2, 1] dimension_.element_labels = ("Alpha", "Baker") dimension_.subtotal_labels = ("Charlie",) @@ -374,7 +374,7 @@ def it_knows_the_row_labels(self, dimension_, _row_order_prop_): row_labels = slice_.row_labels assert row_labels.tolist() == ["Alpha", "Charlie", "Baker"] - def it_provides_a_1D_rows_base_for_an_X_CAT_cube_result( + def test_it_provides_a_1D_rows_base_for_an_X_CAT_cube_result( self, _measures_prop_, second_order_measures_, @@ -392,7 +392,7 @@ def it_provides_a_1D_rows_base_for_an_X_CAT_cube_result( _assemble_marginal_.assert_called_once_with(slice_, margin_unweighted_base_) assert rows_base == [[1, 2, 3], [4, 5, 6]] - def but_it_provides_a_2D_rows_base_for_an_X_MR_cube_result( + def test_but_it_provides_a_2D_rows_base_for_an_X_MR_cube_result( self, request, _measures_prop_, @@ -423,7 +423,7 @@ def but_it_provides_a_2D_rows_base_for_an_X_MR_cube_result( ((-1, -2, 2, 1, 0), ("STF2", "STF1", "#f00ba5", "#111111", "#000000")), ), ) - def it_knows_the_rows_dimension_fills( + def test_it_knows_the_rows_dimension_fills( self, request, _rows_dimension_prop_, @@ -446,7 +446,7 @@ def it_knows_the_rows_dimension_fills( assert slice_.rows_dimension_fills == expected_fills - def it_knows_the_rows_dimension_numeric_values( + def test_it_knows_the_rows_dimension_numeric_values( self, request, dimension_, _row_order_prop_ ): dimension_.valid_elements = tuple( @@ -464,7 +464,7 @@ def it_knows_the_rows_dimension_numeric_values( [3.0, np.nan, 1.0, np.nan], ) - def it_provides_a_1D_rows_margin_for_an_X_CAT_cube_result( + def test_it_provides_a_1D_rows_margin_for_an_X_CAT_cube_result( self, dimension_, _measures_prop_, @@ -485,7 +485,7 @@ def it_provides_a_1D_rows_margin_for_an_X_CAT_cube_result( _assemble_marginal_.assert_called_once_with(slice_, margin_weighted_base_) assert rows_margin == [[1, 2, 3], [4, 5, 6]] - def but_it_provides_a_2D_rows_margin_for_an_X_MR_cube_result( + def test_but_it_provides_a_2D_rows_margin_for_an_X_MR_cube_result( self, request, _measures_prop_, @@ -504,7 +504,7 @@ def but_it_provides_a_2D_rows_margin_for_an_X_MR_cube_result( assert rows_margin == [[1, 2], [3, 4]] - def it_provides_a_1D_rows_margin_proportion_for_an_X_CAT_cube_result( + def test_it_provides_a_1D_rows_margin_proportion_for_an_X_CAT_cube_result( self, request, dimension_, @@ -525,7 +525,7 @@ def it_provides_a_1D_rows_margin_proportion_for_an_X_CAT_cube_result( _assemble_marginal_.assert_called_once_with(slice_, measure_) assert rows_margin_proportion == [[1, 2, 3], [4, 5, 6]] - def but_it_provides_a_2D_rows_margin_proportion_for_an_X_MR_cube_result( + def test_but_it_provides_a_2D_rows_margin_proportion_for_an_X_MR_cube_result( self, request, dimensions_, @@ -562,7 +562,7 @@ def but_it_provides_a_2D_rows_margin_proportion_for_an_X_MR_cube_result( _assemble_matrix_.assert_called_once_with(slice_, [[[1], [2]], [[3], [4]]]) assert rows_margin_proportion == [[1, 2, 3], [4, 5, 6], [7, 8, 9]] - def it_knows_the_2D_table_base_of_an_ARRAY_X_ARRAY_matrix( + def test_it_knows_the_2D_table_base_of_an_ARRAY_X_ARRAY_matrix( self, request, _measures_prop_, @@ -590,7 +590,7 @@ def it_knows_the_2D_table_base_of_an_ARRAY_X_ARRAY_matrix( assert slice_.table_base == [[5, 4, 6], [2, 1, 3]] - def and_it_knows_the_1D_table_base_of_an_ARRAY_X_CAT_matrix( + def test_and_it_knows_the_1D_table_base_of_an_ARRAY_X_CAT_matrix( self, _measures_prop_, second_order_measures_, @@ -615,7 +615,7 @@ def and_it_knows_the_1D_table_base_of_an_ARRAY_X_CAT_matrix( ) assert table_base == [2, 1, 3] - def and_it_knows_the_1D_table_base_of_a_CAT_X_ARRAY_matrix( + def test_and_it_knows_the_1D_table_base_of_a_CAT_X_ARRAY_matrix( self, _measures_prop_, second_order_measures_, @@ -641,7 +641,7 @@ def and_it_knows_the_1D_table_base_of_a_CAT_X_ARRAY_matrix( _assemble_marginal_.assert_called_once_with(slice_, rows_table_unweighted_base_) assert table_base == [2, 1, 3] - def and_it_knows_the_scalar_table_base_of_a_CAT_X_CAT_matrix( + def test_and_it_knows_the_scalar_table_base_of_a_CAT_X_CAT_matrix( self, _measures_prop_, second_order_measures_, @@ -655,7 +655,7 @@ def and_it_knows_the_scalar_table_base_of_a_CAT_X_CAT_matrix( assert slice_.table_base == 4242 - def it_knows_the_2D_table_margin_of_an_ARRAY_X_ARRAY_matrix( + def test_it_knows_the_2D_table_margin_of_an_ARRAY_X_ARRAY_matrix( self, request, _measures_prop_, @@ -683,7 +683,7 @@ def it_knows_the_2D_table_margin_of_an_ARRAY_X_ARRAY_matrix( assert slice_.table_margin == [[5, 4, 6], [2, 1, 3]] - def and_it_knows_the_1D_table_margin_of_an_ARRAY_X_CAT_matrix( + def test_and_it_knows_the_1D_table_margin_of_an_ARRAY_X_CAT_matrix( self, _measures_prop_, second_order_measures_, @@ -708,7 +708,7 @@ def and_it_knows_the_1D_table_margin_of_an_ARRAY_X_CAT_matrix( ) assert table_margin == [2, 1, 3] - def and_it_knows_the_1D_table_margin_of_a_CAT_X_ARRAY_matrix( + def test_and_it_knows_the_1D_table_margin_of_a_CAT_X_ARRAY_matrix( self, _measures_prop_, second_order_measures_, @@ -734,7 +734,7 @@ def and_it_knows_the_1D_table_margin_of_a_CAT_X_ARRAY_matrix( _assemble_marginal_.assert_called_once_with(slice_, rows_table_weighted_base_) assert table_margin == [2, 1, 3] - def and_it_knows_the_scalar_table_margin_of_a_CAT_X_CAT_matrix( + def test_and_it_knows_the_scalar_table_margin_of_a_CAT_X_CAT_matrix( self, _measures_prop_, second_order_measures_, @@ -748,7 +748,7 @@ def and_it_knows_the_scalar_table_margin_of_a_CAT_X_CAT_matrix( assert slice_.table_margin == 4242 - def it_knows_the_table_base_range( + def test_it_knows_the_table_base_range( self, request, _measures_prop_, @@ -761,7 +761,7 @@ def it_knows_the_table_base_range( assert slice_.table_base_range == 42 - def it_knows_the_table_margin_range( + def test_it_knows_the_table_margin_range( self, request, _measures_prop_, @@ -788,7 +788,7 @@ def it_knows_the_table_margin_range( ([0], [0], [[1, 2, 3], [4, 5, 6]], [[1]]), ), ) - def it_can_assemble_a_matrix_from_blocks( + def test_it_can_assemble_a_matrix_from_blocks( self, _row_order_prop_, row_order, @@ -803,7 +803,7 @@ def it_can_assemble_a_matrix_from_blocks( assert slice_._assemble_matrix(blocks).tolist() == expected_value - def it_can_assemble_a_vector(self, request): + def test_it_can_assemble_a_vector(self, request): base_vector = np.array([1, 2, 3, 4]) subtotals_ = tuple( instance_mock( @@ -825,7 +825,7 @@ def it_can_assemble_a_vector(self, request): assert vector.tolist() == [3, 2, 1, 5, 4, 3, 7] - def it_knows_the_column_order_to_help( + def test_it_knows_the_column_order_to_help( self, _BaseOrderHelper_, dimensions_, @@ -853,7 +853,7 @@ def it_knows_the_column_order_to_help( (ORDER_FORMAT.BOGUS_IDS, ("ins_1", 1, "ins_2", 2, "ins_3", 3)), ), ) - def it_knows_the_row_order_to_help( + def test_it_knows_the_row_order_to_help( self, _BaseOrderHelper_, dimensions_, @@ -874,7 +874,7 @@ def it_knows_the_row_order_to_help( ) assert row_order.tolist() == list(row_order) - def it_knows_the_payload_order_to_help( + def test_it_knows_the_payload_order_to_help( self, request, dimensions_, @@ -988,10 +988,10 @@ def table_weighted_base_(self, request): return instance_mock(request, _TableBase) -class Describe_BaseOrderHelper: +class Test_BaseOrderHelper: """Unit test suite for `cr.cube.matrix.assembler._BaseOrderHelper` object.""" - def it_dispatches_to_the_right_column_order_helper( + def test_it_dispatches_to_the_right_column_order_helper( self, request, dimensions_, second_order_measures_ ): column_order_helper_ = instance_mock( @@ -1020,7 +1020,7 @@ def it_dispatches_to_the_right_column_order_helper( (CM.PAYLOAD_ORDER, _RowOrderHelper), ), ) - def it_dispatches_to_the_right_row_order_helper( + def test_it_dispatches_to_the_right_row_order_helper( self, request, dimensions_, second_order_measures_, collation_method, HelperCls ): dimensions_[0].order_spec = instance_mock( @@ -1044,7 +1044,7 @@ def it_dispatches_to_the_right_row_order_helper( ) assert row_order.tolist() == [-1, 1, -2, 2] - def it_provides_access_to_the_columns_dimension_to_help(self, dimension_): + def test_it_provides_access_to_the_columns_dimension_to_help(self, dimension_): order_helper = _BaseOrderHelper((None, dimension_), None) assert order_helper._columns_dimension is dimension_ @@ -1056,7 +1056,7 @@ def it_provides_access_to_the_columns_dimension_to_help(self, dimension_): (False, (-1, 1, -2, 2, -3, 3), [-1, 1, -2, 2, -3, 3]), ), ) - def it_post_processes_the_display_order_to_help( + def test_it_post_processes_the_display_order_to_help( self, request, prune_subtotals, order, expected_value ): property_mock( @@ -1077,7 +1077,7 @@ def it_post_processes_the_display_order_to_help( ([True, True, True], (0, 1, 2)), ), ) - def it_knows_its_empty_column_idxs_to_help( + def test_it_knows_its_empty_column_idxs_to_help( self, second_order_measures_, base, expected_value ): second_order_measures_.columns_pruning_mask = np.array(base) @@ -1093,7 +1093,7 @@ def it_knows_its_empty_column_idxs_to_help( ([True, True, True], (0, 1, 2)), ), ) - def it_knows_its_empty_row_idxs_to_help( + def test_it_knows_its_empty_row_idxs_to_help( self, second_order_measures_, base, expected_value ): second_order_measures_.rows_pruning_mask = np.array(base) @@ -1139,7 +1139,7 @@ def it_knows_its_empty_row_idxs_to_help( ("z_score", "zscores"), ), ) - def it_retrieves_the_measure_object_to_help( + def test_it_retrieves_the_measure_object_to_help( self, request, second_order_measures_, json_name, internal_name ): property_mock( @@ -1154,7 +1154,7 @@ def it_retrieves_the_measure_object_to_help( assert order_helper._measure is measure_ - def it_provides_access_to_the_rows_dimension_to_help(self, dimension_): + def test_it_provides_access_to_the_rows_dimension_to_help(self, dimension_): order_helper = _BaseOrderHelper((dimension_, None), None) assert order_helper._rows_dimension is dimension_ @@ -1173,7 +1173,7 @@ def second_order_measures_(self, request): return instance_mock(request, SecondOrderMeasures) -class Describe_ColumnOrderHelper: +class Test_ColumnOrderHelper: """Unit test suite for `cr.cube.matrix.assembler._ColumnOrderHelper` object.""" @pytest.mark.parametrize( @@ -1183,7 +1183,7 @@ class Describe_ColumnOrderHelper: (CM.EXPLICIT_ORDER, "ExplicitOrderCollator"), ), ) - def it_computes_the_order_of_a_columns_dimension_to_help( + def test_it_computes_the_order_of_a_columns_dimension_to_help( self, request, dimension_, collation_method, collator_class_name ): property_mock( @@ -1216,7 +1216,7 @@ def it_computes_the_order_of_a_columns_dimension_to_help( (True, (0, 1, 2), True), ), ) - def it_knows_whether_to_prune_the_subtotal_columns_to_help( + def test_it_knows_whether_to_prune_the_subtotal_columns_to_help( self, request, dimension_, prune, empty_row_idxs, expected_value ): property_mock( @@ -1241,7 +1241,7 @@ def dimension_(self, request): return instance_mock(request, Dimension) -class Describe_RowOrderHelper: +class Test_RowOrderHelper: """Unit test suite for `cr.cube.matrix.assembler._RowOrderHelper` object.""" @pytest.mark.parametrize( @@ -1251,7 +1251,7 @@ class Describe_RowOrderHelper: (CM.EXPLICIT_ORDER, "ExplicitOrderCollator"), ), ) - def it_computes_the_order_of_a_rows_dimension_to_help( + def test_it_computes_the_order_of_a_rows_dimension_to_help( self, request, dimension_, collation_method, collator_class_name ): property_mock( @@ -1276,7 +1276,7 @@ def it_computes_the_order_of_a_rows_dimension_to_help( ) assert order == (1, -2, 3, 5, -1) - def it_provides_access_to_the_order_spec_to_help(self, request, dimension_): + def test_it_provides_access_to_the_order_spec_to_help(self, request, dimension_): property_mock( request, _RowOrderHelper, "_rows_dimension", return_value=dimension_ ) @@ -1294,7 +1294,7 @@ def it_provides_access_to_the_order_spec_to_help(self, request, dimension_): (True, (0, 1, 2), True), ), ) - def it_knows_whether_to_prune_the_subtotal_rows_to_help( + def test_it_knows_whether_to_prune_the_subtotal_rows_to_help( self, request, dimension_, prune, empty_column_idxs, expected_value ): property_mock( @@ -1319,10 +1319,10 @@ def dimension_(self, request): return instance_mock(request, Dimension) -class Describe_BaseSortRowsByValueHelper: +class Test_BaseSortRowsByValueHelper: """Unit test suite for `cr.cube.matrix.assembler._BaseSortRowsByValueHelper`.""" - def it_provides_the_order( + def test_it_provides_the_order( self, SortByValueCollator_, _rows_dimension_prop_, @@ -1340,7 +1340,7 @@ def it_provides_the_order( ORDER_FORMAT.SIGNED_INDEXES, ) - def but_it_falls_back_to_payload_order_on_value_error( + def test_but_it_falls_back_to_payload_order_on_value_error( self, request, dimensions_, @@ -1393,10 +1393,10 @@ def _subtotal_values_prop_(self, request): return property_mock(request, _BaseSortRowsByValueHelper, "_subtotal_values") -class Describe_SortRowsByBaseColumnHelper: +class Test_SortRowsByBaseColumnHelper: """Unit test suite for `cr.cube.matrix.assembler._SortRowsByBaseColumnHelper`.""" - def it_derives_the_sort_column_idx_from_the_order_spec_to_help( + def test_it_derives_the_sort_column_idx_from_the_order_spec_to_help( self, _columns_dimension_prop_, dimension_, _order_spec_prop_, order_spec_ ): _columns_dimension_prop_.return_value = dimension_ @@ -1411,7 +1411,7 @@ def it_derives_the_sort_column_idx_from_the_order_spec_to_help( dimension_.translate_element_id.assert_called_once_with("c") assert column_idx == 2 - def it_extracts_the_element_values_to_help( + def test_it_extracts_the_element_values_to_help( self, _measure_prop_, measure_, _column_idx_prop_ ): _measure_prop_.return_value = measure_ @@ -1421,7 +1421,7 @@ def it_extracts_the_element_values_to_help( assert order_helper._element_values.tolist() == [2, 7, 12, 17] - def but_it_raises_when_an_unsupported_sort_by_value_measure_is_requested( + def test_but_it_raises_when_an_unsupported_sort_by_value_measure_is_requested( self, _order_spec_prop_, order_spec_ ): _order_spec_prop_.return_value = order_spec_ @@ -1433,7 +1433,7 @@ def but_it_raises_when_an_unsupported_sort_by_value_measure_is_requested( assert str(e.value) == ("sort-by-value for measure 'foo' is not yet supported") - def it_extracts_the_subtotal_values_to_help( + def test_it_extracts_the_subtotal_values_to_help( self, _measure_prop_, measure_, _column_idx_prop_ ): _measure_prop_.return_value = measure_ @@ -1474,10 +1474,10 @@ def _order_spec_prop_(self, request): return property_mock(request, _SortRowsByBaseColumnHelper, "_order_spec") -class Describe_SortRowsByDerivedColumnHelper: +class Test_SortRowsByDerivedColumnHelper: """Unit test suite for `cr.cube.matrix.assembler._SortRowsByDerivedColumnHelper`.""" - def it_derives_the_sort_column_idx_from_the_order_spec_to_help( + def test_it_derives_the_sort_column_idx_from_the_order_spec_to_help( self, _columns_dimension_prop_, dimension_, _order_spec_prop_, order_spec_ ): _columns_dimension_prop_.return_value = dimension_ @@ -1511,10 +1511,10 @@ def _order_spec_prop_(self, request): return property_mock(request, _SortRowsByBaseColumnHelper, "_order_spec") -class Describe_SortRowsByInsertedColumnHelper: +class Test_SortRowsByInsertedColumnHelper: """Unit test suite for `cr.cube.matrix.assembler._SortRowsByInsertedColumnHelper`""" - def it_extracts_the_element_values_to_help( + def test_it_extracts_the_element_values_to_help( self, _measure_prop_, measure_, _insertion_idx_prop_ ): _measure_prop_.return_value = measure_ @@ -1524,7 +1524,7 @@ def it_extracts_the_element_values_to_help( assert order_helper._element_values.tolist() == [1, 4, 7, 10] - def it_derives_the_sort_insertion_idx_from_the_order_spec_to_help( + def test_it_derives_the_sort_insertion_idx_from_the_order_spec_to_help( self, _columns_dimension_prop_, dimension_, _order_spec_prop_, order_spec_ ): _columns_dimension_prop_.return_value = dimension_ @@ -1535,7 +1535,7 @@ def it_derives_the_sort_insertion_idx_from_the_order_spec_to_help( assert order_helper._insertion_idx == 1 - def it_extracts_the_subtotal_values_to_help( + def test_it_extracts_the_subtotal_values_to_help( self, _measure_prop_, measure_, _insertion_idx_prop_ ): _measure_prop_.return_value = measure_ @@ -1578,10 +1578,10 @@ def _order_spec_prop_(self, request): return property_mock(request, _SortRowsByInsertedColumnHelper, "_order_spec") -class Describe_SortRowsByLabelHelper: +class Test_SortRowsByLabelHelper: """Unit test suite for `cr.cube.matrix.assembler._SortRowsByLabelHelper`.""" - def it_provides_the_element_values_to_help(self, dimensions_): + def test_it_provides_the_element_values_to_help(self, dimensions_): dimensions_[0].element_labels = ("c", "a", "b") assert _SortRowsByLabelHelper(dimensions_, None)._element_values.tolist() == [ @@ -1590,7 +1590,7 @@ def it_provides_the_element_values_to_help(self, dimensions_): "b", ] - def it_provides_the_subtotal_values_to_help(self, dimensions_): + def test_it_provides_the_subtotal_values_to_help(self, dimensions_): dimensions_[0].subtotal_labels = ("c", "a", "b") assert _SortRowsByLabelHelper(dimensions_, None)._subtotal_values.tolist() == [ @@ -1606,10 +1606,10 @@ def dimensions_(self, request): return (instance_mock(request, Dimension), instance_mock(request, Dimension)) -class Describe_SortRowsByMarginalHelper: +class Test_SortRowsByMarginalHelper: """Unit test suite for `cr.cube.matrix.assembler._SortRowsByMarginalHelper`.""" - def it_provides_the_element_values_to_help(self, _marginal_prop_, marginal_): + def test_it_provides_the_element_values_to_help(self, _marginal_prop_, marginal_): marginal_.blocks = ["a", "b"] _marginal_prop_.return_value = marginal_ @@ -1627,7 +1627,7 @@ def it_provides_the_element_values_to_help(self, _marginal_prop_, marginal_): (MARGINAL.SCALE_MEDIAN, "rows_scale_median"), ), ) - def it_provides_the_marginal_to_help( + def test_it_provides_the_marginal_to_help( self, second_order_measures_, marginal, @@ -1642,7 +1642,7 @@ def it_provides_the_marginal_to_help( assert order_helper._marginal == "foo" - def but_it_raises_on_unknown_marginal( + def test_but_it_raises_on_unknown_marginal( self, second_order_measures_, _order_spec_, _order_spec_prop_ ): _order_spec_.marginal = "bar" @@ -1654,7 +1654,7 @@ def but_it_raises_on_unknown_marginal( assert str(e.value) == "sort-by-value for marginal 'bar' is not yet supported" - def it_provides_the_subtotal_values_to_help(self, _marginal_prop_, marginal_): + def test_it_provides_the_subtotal_values_to_help(self, _marginal_prop_, marginal_): marginal_.blocks = ["a", "b"] _marginal_prop_.return_value = marginal_ diff --git a/tests/unit/matrix/test_cubemeasure.py b/tests/unit/matrix/test_cubemeasure.py index a37461d72..b9df654f6 100644 --- a/tests/unit/matrix/test_cubemeasure.py +++ b/tests/unit/matrix/test_cubemeasure.py @@ -52,7 +52,7 @@ from ...unitutil import class_mock, instance_mock, method_mock, property_mock -class DescribeCubeMeasures: +class TestCubeMeasures: """Unit test suite for `cr.cube.matrix.cubemeasure.CubeMeasures` object.""" @pytest.mark.parametrize( @@ -65,7 +65,7 @@ class DescribeCubeMeasures: ("cube_stddev", _BaseCubeStdDev), ), ) - def it_provides_access_to_cube_measures_object( + def test_it_provides_access_to_cube_measures_object( self, request, cube_, dimensions_, cube_measure_, CubeMeasureCls ): _cube_measure_ = instance_mock(request, CubeMeasureCls) @@ -92,7 +92,7 @@ def dimensions_(self, request): return (instance_mock(request, Dimension), instance_mock(request, Dimension)) -class Describe_BaseCubeMeasure: +class Test_BaseCubeMeasure: """Unit test suite for `cr.cube.matrix.cubemeasure._BaseCubeMeasure`.""" @pytest.mark.parametrize( @@ -103,7 +103,7 @@ class Describe_BaseCubeMeasure: (3, DT.CAT, 3), ), ) - def it_computes_index_expression_that_selects_measure_values_from_cube_to_help( + def test_it_computes_index_expression_that_selects_measure_values_from_cube_to_help( self, request, ndim, tab_dim_type, expected_value ): cube_ = instance_mock(request, Cube, ndim=ndim, dimension_types=(tab_dim_type,)) @@ -115,7 +115,7 @@ def it_computes_index_expression_that_selects_measure_values_from_cube_to_help( # === COUNTS (UNWEIGHTED & WEIGHTED) -class Describe_BaseCubeCounts: +class Test_BaseCubeCounts: """Unit test suite for `cr.cube.matrix.cubemeasure._BaseCubeCounts`.""" @pytest.mark.parametrize( @@ -131,7 +131,7 @@ class Describe_BaseCubeCounts: ((DT.MR, DT.CA_SUBVAR), _MrXArrCubeCounts), ), ) - def it_provides_a_factory_for_constructing_cube_count_objects( + def test_it_provides_a_factory_for_constructing_cube_count_objects( self, request, cube_, @@ -162,7 +162,7 @@ def it_provides_a_factory_for_constructing_cube_count_objects( CubeCountsCls_.assert_called_once_with(dimensions_, [3, 4], "diff_nans") assert cube_counts is cube_counts_ - def it_provides_columns_pruning_mask(self, request): + def test_it_provides_columns_pruning_mask(self, request): property_mock( request, _BaseCubeCounts, @@ -173,7 +173,7 @@ def it_provides_columns_pruning_mask(self, request): assert cube_counts.columns_pruning_mask.tolist() == [True, False, True, False] - def it_provides_rows_pruning_mask(self, request): + def test_it_provides_rows_pruning_mask(self, request): property_mock( request, _BaseCubeCounts, @@ -198,62 +198,62 @@ def dimensions_(self, request): ) -class Describe_ArrXArrCubeCounts: +class Test_ArrXArrCubeCounts: """Unit test suite for `cr.cube.matrix.cubemeasure._ArrXArrCubeCounts`.""" - def it_knows_its_column_bases(self, raw_counts): + def test_it_knows_its_column_bases(self, raw_counts): cube_counts = _ArrXArrCubeCounts(None, raw_counts, None) assert cube_counts.column_bases == pytest.approx(raw_counts) - def it_knows_its_columns_base(self, raw_counts): + def test_it_knows_its_columns_base(self, raw_counts): cube_counts = _ArrXArrCubeCounts(None, raw_counts, None) assert cube_counts.columns_base is None - def it_knows_its_columns_table_base(self, raw_counts): + def test_it_knows_its_columns_table_base(self, raw_counts): cube_counts = _ArrXArrCubeCounts(None, raw_counts, None) assert cube_counts.columns_table_base is None - def it_knows_its_counts(self, raw_counts): + def test_it_knows_its_counts(self, raw_counts): cube_counts = _ArrXArrCubeCounts(None, raw_counts, None) assert cube_counts.counts == pytest.approx(raw_counts) - def it_knows_its_row_bases(self, raw_counts): + def test_it_knows_its_row_bases(self, raw_counts): cube_counts = _ArrXArrCubeCounts(None, raw_counts, None) assert cube_counts.row_bases == pytest.approx(raw_counts) - def it_knows_its_rows_base(self, raw_counts): + def test_it_knows_its_rows_base(self, raw_counts): cube_counts = _ArrXArrCubeCounts(None, raw_counts, None) assert cube_counts.rows_base is None - def it_knows_its_rows_table_base(self, raw_counts): + def test_it_knows_its_rows_table_base(self, raw_counts): cube_counts = _ArrXArrCubeCounts(None, raw_counts, None) assert cube_counts.rows_table_base is None - def it_knows_its_table_base(self, raw_counts): + def test_it_knows_its_table_base(self, raw_counts): cube_counts = _ArrXArrCubeCounts(None, raw_counts, None) assert cube_counts.table_base is None - def it_knows_its_table_bases(self, raw_counts): + def test_it_knows_its_table_bases(self, raw_counts): cube_counts = _ArrXArrCubeCounts(None, raw_counts, None) assert cube_counts.table_bases == pytest.approx(raw_counts) - def it_provides_the_columns_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_columns_pruning_base_to_help(self, raw_counts): cube_counts = _ArrXArrCubeCounts(None, raw_counts, None) assert cube_counts._columns_pruning_base == pytest.approx( np.array([4.5, 3.8, 4.9]) ) - def it_provides_the_rows_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_rows_pruning_base_to_help(self, raw_counts): cube_counts = _ArrXArrCubeCounts(None, raw_counts, None) assert cube_counts._rows_pruning_base == pytest.approx(np.array([6.7, 6.5])) @@ -271,30 +271,30 @@ def raw_counts(self): ) -class Describe_ArrXCatCubeCounts: +class Test_ArrXCatCubeCounts: """Unit test suite for `cr.cube.matrix.cubemeasure._ArrXCatCubeCounts`.""" - def it_knows_its_column_bases(self, raw_counts): + def test_it_knows_its_column_bases(self, raw_counts): cube_counts = _ArrXCatCubeCounts(None, raw_counts, None) assert cube_counts.column_bases == pytest.approx(raw_counts) - def it_knows_its_columns_base(self, raw_counts): + def test_it_knows_its_columns_base(self, raw_counts): cube_counts = _ArrXCatCubeCounts(None, raw_counts, None) assert cube_counts.columns_base is None - def it_knows_its_columns_table_base(self, raw_counts): + def test_it_knows_its_columns_table_base(self, raw_counts): cube_counts = _ArrXCatCubeCounts(None, raw_counts, None) assert cube_counts.columns_table_base is None - def it_knows_its_counts(self, raw_counts): + def test_it_knows_its_counts(self, raw_counts): cube_counts = _ArrXCatCubeCounts(None, raw_counts, None) assert cube_counts.counts == pytest.approx(raw_counts) - def it_knows_its_row_bases(self, raw_counts): + def test_it_knows_its_row_bases(self, raw_counts): cube_counts = _ArrXCatCubeCounts(None, raw_counts, None) assert cube_counts.row_bases == pytest.approx( @@ -306,22 +306,22 @@ def it_knows_its_row_bases(self, raw_counts): ) ) - def it_knows_its_rows_base(self, raw_counts): + def test_it_knows_its_rows_base(self, raw_counts): cube_counts = _ArrXCatCubeCounts(None, raw_counts, None) assert cube_counts.rows_base == pytest.approx([6.7, 6.5]) - def it_knows_its_rows_table_base(self, raw_counts): + def test_it_knows_its_rows_table_base(self, raw_counts): cube_counts = _ArrXCatCubeCounts(None, raw_counts, None) assert cube_counts.rows_table_base == pytest.approx([6.7, 6.5]) - def it_knows_its_table_base(self, raw_counts): + def test_it_knows_its_table_base(self, raw_counts): cube_counts = _ArrXCatCubeCounts(None, raw_counts, None) assert cube_counts.table_base is None - def it_knows_its_table_bases(self, raw_counts): + def test_it_knows_its_table_bases(self, raw_counts): cube_counts = _ArrXCatCubeCounts(None, raw_counts, None) assert cube_counts.table_bases == pytest.approx( @@ -333,14 +333,14 @@ def it_knows_its_table_bases(self, raw_counts): ) ) - def it_provides_the_columns_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_columns_pruning_base_to_help(self, raw_counts): cube_counts = _ArrXCatCubeCounts(None, raw_counts, None) assert cube_counts._columns_pruning_base == pytest.approx( np.array([4.5, 3.8, 4.9]) ) - def it_provides_the_rows_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_rows_pruning_base_to_help(self, raw_counts): cube_counts = _ArrXCatCubeCounts(None, raw_counts, None) assert cube_counts._rows_pruning_base == pytest.approx(np.array([20.1, 19.5])) @@ -358,10 +358,10 @@ def raw_counts(self): ) -class Describe_ArrXMrCubeCounts: +class Test_ArrXMrCubeCounts: """Unit test suite for `cr.cube.matrix.cubemeasure._ArrXMrCubeCounts`.""" - def it_knows_its_column_bases(self, raw_counts): + def test_it_knows_its_column_bases(self, raw_counts): cube_counts = _ArrXMrCubeCounts(None, raw_counts, None) assert cube_counts.column_bases == pytest.approx( @@ -373,17 +373,17 @@ def it_knows_its_column_bases(self, raw_counts): ) ) - def it_knows_its_columns_base(self, raw_counts): + def test_it_knows_its_columns_base(self, raw_counts): cube_counts = _ArrXMrCubeCounts(None, raw_counts, None) assert cube_counts.columns_base is None - def it_knows_its_columns_table_base(self, raw_counts): + def test_it_knows_its_columns_table_base(self, raw_counts): cube_counts = _ArrXMrCubeCounts(None, raw_counts, None) assert cube_counts.columns_table_base is None - def it_knows_its_counts(self, raw_counts): + def test_it_knows_its_counts(self, raw_counts): cube_counts = _ArrXMrCubeCounts(None, raw_counts, None) assert cube_counts.counts == pytest.approx( @@ -395,7 +395,7 @@ def it_knows_its_counts(self, raw_counts): ) ) - def it_knows_its_row_bases(self, raw_counts): + def test_it_knows_its_row_bases(self, raw_counts): cube_counts = _ArrXMrCubeCounts(None, raw_counts, None) assert cube_counts.row_bases == pytest.approx( @@ -407,22 +407,22 @@ def it_knows_its_row_bases(self, raw_counts): ) ) - def it_knows_its_rows_base(self, raw_counts): + def test_it_knows_its_rows_base(self, raw_counts): cube_counts = _ArrXMrCubeCounts(None, raw_counts, None) assert cube_counts.rows_base is None - def it_knows_its_rows_table_base(self, raw_counts): + def test_it_knows_its_rows_table_base(self, raw_counts): cube_counts = _ArrXMrCubeCounts(None, raw_counts, None) assert cube_counts.rows_table_base is None - def it_knows_its_table_base(self, raw_counts): + def test_it_knows_its_table_base(self, raw_counts): cube_counts = _ArrXMrCubeCounts(None, raw_counts, None) assert cube_counts.table_base is None - def it_knows_its_table_bases(self, raw_counts): + def test_it_knows_its_table_bases(self, raw_counts): cube_counts = _ArrXMrCubeCounts(None, raw_counts, None) assert cube_counts.table_bases == pytest.approx( @@ -434,7 +434,7 @@ def it_knows_its_table_bases(self, raw_counts): ) ) - def it_provides_the_columns_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_columns_pruning_base_to_help(self, raw_counts): cube_counts = _ArrXMrCubeCounts(None, raw_counts, None) assert cube_counts._columns_pruning_base == pytest.approx( @@ -445,7 +445,7 @@ def it_provides_the_columns_pruning_base_to_help(self, raw_counts): ) ) - def it_provides_the_rows_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_rows_pruning_base_to_help(self, raw_counts): cube_counts = _ArrXMrCubeCounts(None, raw_counts, None) assert cube_counts._rows_pruning_base == pytest.approx(np.array([20.4, 23.7])) @@ -472,10 +472,10 @@ def raw_counts(self): ) -class Describe_CatXArrCubeCounts: +class Test_CatXArrCubeCounts: """Unit test suite for `cr.cube.matrix.cubemeasure._CatXArrCubeCounts`.""" - def it_knows_its_column_bases(self, raw_counts): + def test_it_knows_its_column_bases(self, raw_counts): cube_counts = _CatXArrCubeCounts(None, raw_counts, None) assert cube_counts.column_bases == pytest.approx( @@ -487,44 +487,44 @@ def it_knows_its_column_bases(self, raw_counts): ) ) - def it_knows_its_columns_base(self, raw_counts): + def test_it_knows_its_columns_base(self, raw_counts): cube_counts = _CatXArrCubeCounts(None, raw_counts, None) assert cube_counts.columns_base == pytest.approx(np.array([4.5, 3.8, 4.9])) - def it_knows_its_columns_table_base(self, raw_counts): + def test_it_knows_its_columns_table_base(self, raw_counts): cube_counts = _CatXArrCubeCounts(None, raw_counts, None) assert cube_counts.columns_table_base == pytest.approx( np.array([4.5, 3.8, 4.9]) ) - def it_knows_its_counts(self, raw_counts): + def test_it_knows_its_counts(self, raw_counts): cube_counts = _CatXArrCubeCounts(None, raw_counts, None) assert cube_counts.counts == pytest.approx(raw_counts) - def it_knows_its_row_bases(self, raw_counts): + def test_it_knows_its_row_bases(self, raw_counts): cube_counts = _CatXArrCubeCounts(None, raw_counts, None) assert cube_counts.row_bases == pytest.approx(raw_counts) - def it_knows_its_rows_base(self, raw_counts): + def test_it_knows_its_rows_base(self, raw_counts): cube_counts = _CatXArrCubeCounts(None, raw_counts, None) assert cube_counts.rows_base is None - def it_knows_its_rows_table_base(self, raw_counts): + def test_it_knows_its_rows_table_base(self, raw_counts): cube_counts = _CatXArrCubeCounts(None, raw_counts, None) assert cube_counts.rows_table_base is None - def it_knows_its_table_base(self, raw_counts): + def test_it_knows_its_table_base(self, raw_counts): cube_counts = _CatXArrCubeCounts(None, raw_counts, None) assert cube_counts.table_base is None - def it_knows_its_table_bases(self, raw_counts): + def test_it_knows_its_table_bases(self, raw_counts): cube_counts = _CatXArrCubeCounts(None, raw_counts, None) assert cube_counts.table_bases == pytest.approx( @@ -536,14 +536,14 @@ def it_knows_its_table_bases(self, raw_counts): ) ) - def it_provides_the_columns_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_columns_pruning_base_to_help(self, raw_counts): cube_counts = _CatXArrCubeCounts(None, raw_counts, None) assert cube_counts._columns_pruning_base == pytest.approx( np.array([9.0, 7.6, 9.8]) ) - def it_provides_the_rows_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_rows_pruning_base_to_help(self, raw_counts): cube_counts = _CatXArrCubeCounts(None, raw_counts, None) assert cube_counts._rows_pruning_base == pytest.approx(np.array([6.7, 6.5])) @@ -561,10 +561,10 @@ def raw_counts(self): ) -class Describe_CatXCatCubeCounts: +class Test_CatXCatCubeCounts: """Unit test suite for `cr.cube.matrix.cubemeasure._CatXCatCubeCounts`.""" - def it_knows_its_column_bases(self, raw_counts): + def test_it_knows_its_column_bases(self, raw_counts): cube_counts = _CatXCatCubeCounts(None, raw_counts, None) assert cube_counts.column_bases == pytest.approx( @@ -576,24 +576,24 @@ def it_knows_its_column_bases(self, raw_counts): ) ) - def it_knows_its_columns_base(self, raw_counts): + def test_it_knows_its_columns_base(self, raw_counts): cube_counts = _CatXCatCubeCounts(None, raw_counts, None) assert cube_counts.columns_base == pytest.approx(np.array([4.5, 3.8, 4.9])) - def it_knows_its_columns_table_base(self, raw_counts): + def test_it_knows_its_columns_table_base(self, raw_counts): cube_counts = _CatXCatCubeCounts(None, raw_counts, None) assert cube_counts.columns_table_base == pytest.approx( np.array([13.2, 13.2, 13.2]) ) - def it_knows_its_counts(self, raw_counts): + def test_it_knows_its_counts(self, raw_counts): cube_counts = _CatXCatCubeCounts(None, raw_counts, None) assert cube_counts.counts == pytest.approx(raw_counts) - def it_knows_its_row_bases(self, raw_counts): + def test_it_knows_its_row_bases(self, raw_counts): cube_counts = _CatXCatCubeCounts(None, raw_counts, None) assert cube_counts.row_bases == pytest.approx( @@ -605,22 +605,22 @@ def it_knows_its_row_bases(self, raw_counts): ) ) - def it_knows_its_rows_base(self, raw_counts): + def test_it_knows_its_rows_base(self, raw_counts): cube_counts = _CatXCatCubeCounts(None, raw_counts, None) assert cube_counts.rows_base == pytest.approx(np.array([6.7, 6.5])) - def it_knows_its_rows_table_base(self, raw_counts): + def test_it_knows_its_rows_table_base(self, raw_counts): cube_counts = _CatXCatCubeCounts(None, raw_counts, None) assert cube_counts.rows_table_base == pytest.approx(np.array([13.2, 13.2])) - def it_knows_its_table_base(self, raw_counts): + def test_it_knows_its_table_base(self, raw_counts): cube_counts = _CatXCatCubeCounts(None, raw_counts, None) assert cube_counts.table_base == pytest.approx(np.array([13.2, 13.2])) - def it_knows_its_table_bases(self, raw_counts): + def test_it_knows_its_table_bases(self, raw_counts): cube_counts = _CatXCatCubeCounts(None, raw_counts, None) assert cube_counts.table_bases == pytest.approx( @@ -632,14 +632,14 @@ def it_knows_its_table_bases(self, raw_counts): ) ) - def it_provides_the_columns_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_columns_pruning_base_to_help(self, raw_counts): cube_counts = _CatXCatCubeCounts(None, raw_counts, None) assert cube_counts._columns_pruning_base == pytest.approx( np.array([9.0, 7.6, 9.8]) ) - def it_provides_the_rows_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_rows_pruning_base_to_help(self, raw_counts): cube_counts = _CatXCatCubeCounts(None, raw_counts, None) assert cube_counts._rows_pruning_base == pytest.approx(np.array([20.1, 19.5])) @@ -657,65 +657,65 @@ def raw_counts(self): ) -class Describe_CatXMrCubeCounts: +class Test_CatXMrCubeCounts: """Unit test suite for `cr.cube.matrix.cubemeasure._CatXMrCubeCounts`.""" - def it_knows_its_column_bases(self, raw_counts): + def test_it_knows_its_column_bases(self, raw_counts): cube_counts = _CatXMrCubeCounts(None, raw_counts, None) assert cube_counts.column_bases == pytest.approx( np.array([[5.5, 7.7, 9.9], [5.5, 7.7, 9.9]]) ) - def it_knows_its_columns_base(self, raw_counts): + def test_it_knows_its_columns_base(self, raw_counts): cube_counts = _CatXMrCubeCounts(None, raw_counts, None) assert cube_counts.columns_base == pytest.approx(np.array([5.5, 7.7, 9.9])) - def it_knows_its_columns_table_base(self, raw_counts): + def test_it_knows_its_columns_table_base(self, raw_counts): cube_counts = _CatXMrCubeCounts(None, raw_counts, None) assert cube_counts.columns_table_base == pytest.approx( np.array([10.7, 14.7, 18.7]) ) - def it_knows_its_counts(self, raw_counts): + def test_it_knows_its_counts(self, raw_counts): cube_counts = _CatXMrCubeCounts(None, raw_counts, None) assert cube_counts.counts == pytest.approx( np.array([[1.1, 2.2, 3.3], [4.4, 5.5, 6.6]]) ) - def it_knows_its_row_bases(self, raw_counts): + def test_it_knows_its_row_bases(self, raw_counts): cube_counts = _CatXMrCubeCounts(None, raw_counts, None) assert cube_counts.row_bases == pytest.approx( np.array([[4.8, 6.8, 8.8], [5.9, 7.9, 9.9]]) ) - def it_knows_its_rows_base(self, raw_counts): + def test_it_knows_its_rows_base(self, raw_counts): cube_counts = _CatXMrCubeCounts(None, raw_counts, None) assert cube_counts.rows_base is None - def it_knows_its_rows_table_base(self, raw_counts): + def test_it_knows_its_rows_table_base(self, raw_counts): cube_counts = _CatXMrCubeCounts(None, raw_counts, None) assert cube_counts.rows_table_base is None - def it_knows_its_table_base(self, raw_counts): + def test_it_knows_its_table_base(self, raw_counts): cube_counts = _CatXMrCubeCounts(None, raw_counts, None) assert cube_counts.table_base is None - def it_knows_its_table_bases(self, raw_counts): + def test_it_knows_its_table_bases(self, raw_counts): cube_counts = _CatXMrCubeCounts(None, raw_counts, None) assert cube_counts.table_bases == pytest.approx( np.array([[10.7, 14.7, 18.7], [10.7, 14.7, 18.7]]) ) - def it_provides_the_columns_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_columns_pruning_base_to_help(self, raw_counts): cube_counts = _CatXMrCubeCounts(None, raw_counts, None) assert cube_counts._columns_pruning_base == pytest.approx( @@ -726,7 +726,7 @@ def it_provides_the_columns_pruning_base_to_help(self, raw_counts): ) ) - def it_provides_the_rows_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_rows_pruning_base_to_help(self, raw_counts): cube_counts = _CatXMrCubeCounts(None, raw_counts, None) assert cube_counts._rows_pruning_base == pytest.approx(np.array([20.4, 23.7])) @@ -753,70 +753,70 @@ def raw_counts(self): ) -class Describe_MrXArrCubeCounts: +class Test_MrXArrCubeCounts: """Unit test suite for `cr.cube.matrix.cubemeasure._MrXArrCubeCounts`.""" - def it_knows_its_column_bases(self, raw_counts): + def test_it_knows_its_column_bases(self, raw_counts): cube_counts = _MrXArrCubeCounts(None, raw_counts, None) assert cube_counts.column_bases == pytest.approx( np.array([[4.5, 6.5, 8.5], [5.9, 7.9, 9.9]]) ) - def it_knows_its_columns_base(self, raw_counts): + def test_it_knows_its_columns_base(self, raw_counts): cube_counts = _MrXArrCubeCounts(None, raw_counts, None) assert cube_counts.columns_base is None - def it_knows_its_columns_table_base(self, raw_counts): + def test_it_knows_its_columns_table_base(self, raw_counts): cube_counts = _MrXArrCubeCounts(None, raw_counts, None) assert cube_counts.columns_table_base is None - def it_knows_its_counts(self, raw_counts): + def test_it_knows_its_counts(self, raw_counts): cube_counts = _MrXArrCubeCounts(None, raw_counts, None) assert cube_counts.counts == pytest.approx( np.array([[1.1, 2.2, 3.3], [4.4, 5.5, 6.6]]) ) - def it_knows_its_row_bases(self, raw_counts): + def test_it_knows_its_row_bases(self, raw_counts): cube_counts = _MrXArrCubeCounts(None, raw_counts, None) assert cube_counts.row_bases == pytest.approx( np.array([[1.1, 2.2, 3.3], [4.4, 5.5, 6.6]]) ) - def it_knows_its_rows_base(self, raw_counts): + def test_it_knows_its_rows_base(self, raw_counts): cube_counts = _MrXArrCubeCounts(None, raw_counts, None) assert cube_counts.rows_base is None - def it_knows_its_rows_table_base(self, raw_counts): + def test_it_knows_its_rows_table_base(self, raw_counts): cube_counts = _MrXArrCubeCounts(None, raw_counts, None) assert cube_counts.rows_table_base is None - def it_knows_its_table_base(self, raw_counts): + def test_it_knows_its_table_base(self, raw_counts): cube_counts = _MrXArrCubeCounts(None, raw_counts, None) assert cube_counts.table_base is None - def it_knows_its_table_bases(self, raw_counts): + def test_it_knows_its_table_bases(self, raw_counts): cube_counts = _MrXArrCubeCounts(None, raw_counts, None) assert cube_counts.table_bases == pytest.approx( np.array([[4.5, 6.5, 8.5], [5.9, 7.9, 9.9]]) ) - def it_provides_the_columns_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_columns_pruning_base_to_help(self, raw_counts): cube_counts = _MrXArrCubeCounts(None, raw_counts, None) assert cube_counts._columns_pruning_base == pytest.approx( np.array([10.4, 14.4, 18.4]) ) - def it_provides_the_rows_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_rows_pruning_base_to_help(self, raw_counts): cube_counts = _MrXArrCubeCounts(None, raw_counts, None) assert cube_counts._rows_pruning_base == pytest.approx( @@ -844,70 +844,70 @@ def raw_counts(self): ) -class Describe_MrXCatCubeCounts: +class Test_MrXCatCubeCounts: """Unit test suite for `cr.cube.matrix.cubemeasure._MrXCatCubeCounts`.""" - def it_knows_its_column_bases(self, raw_counts): + def test_it_knows_its_column_bases(self, raw_counts): cube_counts = _MrXCatCubeCounts(None, raw_counts, None) assert cube_counts.column_bases == pytest.approx( np.array([[4.5, 6.5, 8.5], [5.9, 7.9, 9.9]]) ) - def it_knows_its_columns_base(self, raw_counts): + def test_it_knows_its_columns_base(self, raw_counts): cube_counts = _MrXCatCubeCounts(None, raw_counts, None) assert cube_counts.columns_base is None - def it_knows_its_columns_table_base(self, raw_counts): + def test_it_knows_its_columns_table_base(self, raw_counts): cube_counts = _MrXCatCubeCounts(None, raw_counts, None) assert cube_counts.columns_table_base is None - def it_knows_its_counts(self, raw_counts): + def test_it_knows_its_counts(self, raw_counts): cube_counts = _MrXCatCubeCounts(None, raw_counts, None) assert cube_counts.counts == pytest.approx( np.array([[1.1, 2.2, 3.3], [4.4, 5.5, 6.6]]) ) - def it_knows_its_row_bases(self, raw_counts): + def test_it_knows_its_row_bases(self, raw_counts): cube_counts = _MrXCatCubeCounts(None, raw_counts, None) assert cube_counts.row_bases == pytest.approx( np.array([[6.6, 6.6, 6.6], [16.5, 16.5, 16.5]]) ) - def it_knows_its_rows_base(self, raw_counts): + def test_it_knows_its_rows_base(self, raw_counts): cube_counts = _MrXCatCubeCounts(None, raw_counts, None) assert cube_counts.rows_base == pytest.approx(np.array([6.6, 16.5])) - def it_knows_its_rows_table_base(self, raw_counts): + def test_it_knows_its_rows_table_base(self, raw_counts): cube_counts = _MrXCatCubeCounts(None, raw_counts, None) assert cube_counts.rows_table_base == pytest.approx(np.array([19.5, 23.7])) - def it_knows_its_table_base(self, raw_counts): + def test_it_knows_its_table_base(self, raw_counts): cube_counts = _MrXCatCubeCounts(None, raw_counts, None) assert cube_counts.table_base is None - def it_knows_its_table_bases(self, raw_counts): + def test_it_knows_its_table_bases(self, raw_counts): cube_counts = _MrXCatCubeCounts(None, raw_counts, None) assert cube_counts.table_bases == pytest.approx( np.array([[19.5, 19.5, 19.5], [23.7, 23.7, 23.7]]) ) - def it_provides_the_columns_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_columns_pruning_base_to_help(self, raw_counts): cube_counts = _MrXCatCubeCounts(None, raw_counts, None) assert cube_counts._columns_pruning_base == pytest.approx( np.array([10.4, 14.4, 18.4]) ) - def it_provides_the_rows_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_rows_pruning_base_to_help(self, raw_counts): cube_counts = _MrXCatCubeCounts(None, raw_counts, None) assert cube_counts._rows_pruning_base == pytest.approx( @@ -935,10 +935,10 @@ def raw_counts(self): ) -class Describe_MrXMrCubeCounts: +class Test_MrXMrCubeCounts: """Unit test suite for `cr.cube.matrix.cubemeasure._MrXMrCubeCounts`.""" - def it_knows_its_column_bases(self, raw_counts): + def test_it_knows_its_column_bases(self, raw_counts): cube_counts = _MrXMrCubeCounts(None, raw_counts, None) assert cube_counts.column_bases == pytest.approx( @@ -947,22 +947,22 @@ def it_knows_its_column_bases(self, raw_counts): np.array([[4.6, 8.0], [4.2, 12.6]]) ) - def it_knows_its_columns_base(self, raw_counts): + def test_it_knows_its_columns_base(self, raw_counts): cube_counts = _MrXMrCubeCounts(None, raw_counts, None) assert cube_counts.columns_base is None - def it_knows_its_columns_table_base(self, raw_counts): + def test_it_knows_its_columns_table_base(self, raw_counts): cube_counts = _MrXMrCubeCounts(None, raw_counts, None) assert cube_counts.columns_table_base is None - def it_knows_its_counts(self, raw_counts): + def test_it_knows_its_counts(self, raw_counts): cube_counts = _MrXMrCubeCounts(None, raw_counts, None) assert cube_counts.counts == pytest.approx(np.array([[1.1, 3.1], [2.8, 7.3]])) - def it_knows_its_row_bases(self, raw_counts): + def test_it_knows_its_row_bases(self, raw_counts): cube_counts = _MrXMrCubeCounts(None, raw_counts, None) assert cube_counts.row_bases == pytest.approx( @@ -971,22 +971,22 @@ def it_knows_its_row_bases(self, raw_counts): np.array([[3.4, 7.1], [6.3, 15.5]]) ) - def it_knows_its_rows_base(self, raw_counts): + def test_it_knows_its_rows_base(self, raw_counts): cube_counts = _MrXMrCubeCounts(None, raw_counts, None) assert cube_counts.rows_base is None - def it_knows_its_rows_table_base(self, raw_counts): + def test_it_knows_its_rows_table_base(self, raw_counts): cube_counts = _MrXMrCubeCounts(None, raw_counts, None) assert cube_counts.rows_table_base is None - def it_knows_its_table_base(self, raw_counts): + def test_it_knows_its_table_base(self, raw_counts): cube_counts = _MrXMrCubeCounts(None, raw_counts, None) assert cube_counts.table_base is None - def it_knows_its_table_bases(self, raw_counts): + def test_it_knows_its_table_bases(self, raw_counts): cube_counts = _MrXMrCubeCounts(None, raw_counts, None) assert cube_counts.table_bases == pytest.approx( @@ -995,7 +995,7 @@ def it_knows_its_table_bases(self, raw_counts): np.array([[12.2, 18.8], [14.1, 30.6]]) ) - def it_provides_the_columns_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_columns_pruning_base_to_help(self, raw_counts): cube_counts = _MrXMrCubeCounts(None, raw_counts, None) assert cube_counts._columns_pruning_base == pytest.approx( @@ -1004,7 +1004,7 @@ def it_provides_the_columns_pruning_base_to_help(self, raw_counts): np.array([8.8, 20.6]) ) - def it_provides_the_rows_pruning_base_to_help(self, raw_counts): + def test_it_provides_the_rows_pruning_base_to_help(self, raw_counts): cube_counts = _MrXMrCubeCounts(None, raw_counts, None) assert cube_counts._rows_pruning_base == pytest.approx( @@ -1047,7 +1047,7 @@ def raw_counts(self): # === MEANS === -class Describe_BaseCubeMeans: +class Test_BaseCubeMeans: """Unit test suite for `cr.cube.matrix.cubemeasure._BaseCubeMeans`.""" @pytest.mark.parametrize( @@ -1059,7 +1059,7 @@ class Describe_BaseCubeMeans: ((DT.CAT, DT.CAT), _CatXCatCubeMeans), ), ) - def it_provides_a_factory_for_constructing_cube_means_objects( + def test_it_provides_a_factory_for_constructing_cube_means_objects( self, request, dimension_types, CubeMeansCls ): cube_ = instance_mock(request, Cube) @@ -1089,7 +1089,7 @@ def it_provides_a_factory_for_constructing_cube_means_objects( CubeMeanCls_.assert_called_once_with(dimensions_, [3, 4]) assert cube_means is cube_means_ - def but_it_raises_a_value_error_when_cube_result_does_not_contain_mean_measure( + def test_but_it_raises_a_value_error_when_cube_result_does_not_contain_mean_measure( self, cube_ ): cube_.means = None @@ -1106,10 +1106,10 @@ def cube_(self, request): return instance_mock(request, Cube) -class Describe_CatXCatCubeMeans: +class Test_CatXCatCubeMeans: """Unit test suite for `cr.cube.matrix.cubemeasure._CatXCatCubeMeans`.""" - def it_knows_its_means(self, raw_means): + def test_it_knows_its_means(self, raw_means): cube_means = _CatXCatCubeMeans(None, raw_means) assert cube_means.means.tolist() == [ @@ -1130,10 +1130,10 @@ def raw_means(self): ) -class Describe_CatXMrCubeMeans: +class Test_CatXMrCubeMeans: """Unit test suite for `cr.cube.matrix.cubemeasure._CatXMrCubeMeans`.""" - def it_knows_its_means(self, raw_means): + def test_it_knows_its_means(self, raw_means): cube_means = _CatXMrCubeMeans(None, raw_means) assert cube_means.means.tolist() == [ @@ -1164,10 +1164,10 @@ def raw_means(self): ) -class Describe_MrXCatCubeMeans: +class Test_MrXCatCubeMeans: """Unit test suite for `cr.cube.matrix.cubemeasure._MrXCatCubeMeans`.""" - def it_knows_its_means(self, raw_means): + def test_it_knows_its_means(self, raw_means): cube_means = _MrXCatCubeMeans(None, raw_means) assert cube_means.means.tolist() == [ @@ -1198,10 +1198,10 @@ def raw_means(self): ) -class Describe_MrXMrCubeMeans: +class Test_MrXMrCubeMeans: """Unit test suite for `cr.cube.matrix.cubemeasure._MrXMrCubeMeans`.""" - def it_knows_its_means(self, raw_means): + def test_it_knows_its_means(self, raw_means): cube_means = _MrXMrCubeMeans(None, raw_means) assert cube_means.means.tolist() == [ @@ -1245,7 +1245,7 @@ def raw_means(self): # === MEDIANS === -class Describe_BaseCubeMedians: +class Test_BaseCubeMedians: """Unit test suite for `cr.cube.matrix.cubemeasure._BaseCubeMedians`.""" @pytest.mark.parametrize( @@ -1257,7 +1257,7 @@ class Describe_BaseCubeMedians: ((DT.CAT, DT.CAT), _CatXCatCubeMedians), ), ) - def it_provides_a_factory_for_constructing_cube_medians_objects( + def test_it_provides_a_factory_for_constructing_cube_medians_objects( self, request, dimension_types, CubeMediansCls ): cube_ = instance_mock(request, Cube) @@ -1287,7 +1287,7 @@ def it_provides_a_factory_for_constructing_cube_medians_objects( CubeMediansCls_.assert_called_once_with(dimensions_, [3, 4]) assert cube_medians is cube_medians_ - def but_it_raises_a_value_error_when_cube_result_does_not_contain_mean_measure( + def test_but_it_raises_a_value_error_when_cube_result_does_not_contain_mean_measure( self, cube_ ): cube_.means = None @@ -1304,10 +1304,10 @@ def cube_(self, request): return instance_mock(request, Cube) -class Describe_CatXCatCubeMedians: +class Test_CatXCatCubeMedians: """Unit test suite for `cr.cube.matrix.cubemeasure._CatXCatCubeMedians`.""" - def it_knows_its_medians(self): + def test_it_knows_its_medians(self): raw_medians = np.array( [ [1.1, 2.3, 3.3], @@ -1322,10 +1322,10 @@ def it_knows_its_medians(self): ] -class Describe_CatXMrCubeMedians: +class Test_CatXMrCubeMedians: """Unit test suite for `cr.cube.matrix.cubemeasure._CatXMrCubeMedians`.""" - def it_knows_its_means(self, raw_medians): + def test_it_knows_its_means(self, raw_medians): cube_medians = _CatXMrCubeMedians(None, raw_medians) assert cube_medians.medians.tolist() == [ @@ -1356,10 +1356,10 @@ def raw_medians(self): ) -class Describe_MrXCatCubeMedians: +class Test_MrXCatCubeMedians: """Unit test suite for `cr.cube.matrix.cubemeasure._MrXCatCubeMedians`.""" - def it_knows_its_means(self, raw_medians): + def test_it_knows_its_means(self, raw_medians): cube_medians = _MrXCatCubeMedians(None, raw_medians) assert cube_medians.medians.tolist() == [ @@ -1390,10 +1390,10 @@ def raw_medians(self): ) -class Describe_MrXMrCubeMedians: +class Test_MrXMrCubeMedians: """Unit test suite for `cr.cube.matrix.cubemeasure._MrXMrCubeMedians`.""" - def it_knows_its_means(self, raw_medians): + def test_it_knows_its_means(self, raw_medians): cube_medians = _MrXMrCubeMedians(None, raw_medians) assert cube_medians.medians.tolist() == [[0.1, 0.1], [0.4, 0.5]] @@ -1434,7 +1434,7 @@ def raw_medians(self): # === STD DEV === -class Describe_BaseCubeStdDev: +class Test_BaseCubeStdDev: """Unit test suite for `cr.cube.matrix.cubemeasure._BaseCubeStdDev`.""" @pytest.mark.parametrize( @@ -1446,7 +1446,7 @@ class Describe_BaseCubeStdDev: ((DT.CAT, DT.CAT), _CatXCatCubeStdDev), ), ) - def it_provides_a_factory_for_constructing_cube_stddev_objects( + def test_it_provides_a_factory_for_constructing_cube_stddev_objects( self, request, dimension_types, CubeStdDevCls, cube_ ): dimensions_ = ( @@ -1475,7 +1475,7 @@ def it_provides_a_factory_for_constructing_cube_stddev_objects( CubeStdDevCls_.assert_called_once_with(dimensions_, [3, 4]) assert cube_stddev is cube_stddev_ - def but_it_raises_a_value_error_when_cube_result_does_not_contain_stddev_measure( + def test_it_raises_a_value_error_when_cube_result_does_not_contain_stddev_measure( self, cube_ ): cube_.stddev = None @@ -1492,10 +1492,10 @@ def cube_(self, request): return instance_mock(request, Cube) -class Describe_CatXCatCubeStdDev: +class Test_CatXCatCubeStdDev: """Unit test suite for `cr.cube.matrix.cubemeasure._CatXCatCubeStdDev`.""" - def it_knows_its_stddev(self, raw_stddev): + def test_it_knows_its_stddev(self, raw_stddev): cube_stddev = _CatXCatCubeStdDev(None, raw_stddev) assert cube_stddev.stddev.tolist() == [ @@ -1516,10 +1516,10 @@ def raw_stddev(self): ) -class Describe_CatXMrCubeStdDev: +class Test_CatXMrCubeStdDev: """Unit test suite for `cr.cube.matrix.cubemeasure._CatXMrCubeStdDev`.""" - def it_knows_its_stddev(self, raw_stddev): + def test_it_knows_its_stddev(self, raw_stddev): cube_stddev = _CatXMrCubeStdDev(None, raw_stddev) assert cube_stddev.stddev.tolist() == [ @@ -1550,10 +1550,10 @@ def raw_stddev(self): ) -class Describe_MrXCatCubeStdDev: +class Test_MrXCatCubeStdDev: """Unit test suite for `cr.cube.matrix.cubemeasure._MrXCatCubeStdDev`.""" - def it_knows_its_stddev(self, raw_stddev): + def test_it_knows_its_stddev(self, raw_stddev): cube_stddev = _MrXCatCubeStdDev(None, raw_stddev) assert cube_stddev.stddev.tolist() == [ @@ -1584,10 +1584,10 @@ def raw_stddev(self): ) -class Describe_MrXMrCubeStdDev: +class Test_MrXMrCubeStdDev: """Unit test suite for `cr.cube.matrix.cubemeasure._MrXMrCubeStdDev`.""" - def it_knows_its_stddev(self, raw_stddev): + def test_it_knows_its_stddev(self, raw_stddev): cube_stddev = _MrXMrCubeStdDev(None, raw_stddev) assert cube_stddev.stddev.tolist() == [ @@ -1631,7 +1631,7 @@ def raw_stddev(self): # === SUM === -class Describe_BaseCubeSum: +class Test_BaseCubeSum: """Unit test suite for `cr.cube.matrix.cubemeasure._BaseCubeSum`.""" @pytest.mark.parametrize( @@ -1643,7 +1643,7 @@ class Describe_BaseCubeSum: ((DT.CAT, DT.CAT), _CatXCatCubeSums), ), ) - def it_provides_a_factory_for_constructing_cube_sum_objects( + def test_it_provides_a_factory_for_constructing_cube_sum_objects( self, request, dimension_types, CubeSumCls, cube_ ): dimensions_ = ( @@ -1672,7 +1672,7 @@ def it_provides_a_factory_for_constructing_cube_sum_objects( CubeSumCls_.assert_called_once_with(dimensions_, [3, 4]) assert cube_sums is cube_sums_ - def but_it_raises_a_value_error_when_cube_result_does_not_contain_sum_measure( + def test_but_it_raises_a_value_error_when_cube_result_does_not_contain_sum_measure( self, cube_ ): cube_.sums = None @@ -1689,10 +1689,10 @@ def cube_(self, request): return instance_mock(request, Cube) -class Describe_CatXCatCubeSums: +class Test_CatXCatCubeSums: """Unit test suite for `cr.cube.matrix.cubemeasure._CatXCatCubeSums`.""" - def it_knows_its_sum(self, raw_sums): + def test_it_knows_its_sum(self, raw_sums): cube_sum = _CatXCatCubeSums(None, raw_sums) assert cube_sum.sums.tolist() == [ @@ -1713,10 +1713,10 @@ def raw_sums(self): ) -class Describe_CatXMrCubeSum: +class Test_CatXMrCubeSum: """Unit test suite for `cr.cube.matrix.cubemeasure._CatXMrCubeSums`.""" - def it_knows_its_sum(self, raw_sums): + def test_it_knows_its_sum(self, raw_sums): cube_sum = _CatXMrCubeSums(None, raw_sums) assert cube_sum.sums.tolist() == [ @@ -1747,10 +1747,10 @@ def raw_sums(self): ) -class Describe_MrXCatCubeSum: +class Test_MrXCatCubeSum: """Unit test suite for `cr.cube.matrix.cubemeasure._MrXCatCubeSums`.""" - def it_knows_its_sum(self, raw_sums): + def test_it_knows_its_sum(self, raw_sums): cube_sum = _MrXCatCubeSums(None, raw_sums) assert cube_sum.sums.tolist() == [ @@ -1781,10 +1781,10 @@ def raw_sums(self): ) -class Describe_MrXMrCubeSum: +class Test_MrXMrCubeSum: """Unit test suite for `cr.cube.matrix.cubemeasure._MrXMrCubeSums`.""" - def it_knows_its_sums(self, raw_sums): + def test_it_knows_its_sums(self, raw_sums): cube_sum = _MrXMrCubeSums(None, raw_sums) assert cube_sum.sums.tolist() == [ @@ -1828,7 +1828,7 @@ def raw_sums(self): # === (WEIGHTED) UNCONDITIONAL COUNTS === -class Describe_BaseUnconditionalCubeCounts: +class Test_BaseUnconditionalCubeCounts: """Unit test suite for `cr.cube.matrix.cubemeasure._BaseUnconditionalCubeCounts`.""" @pytest.mark.parametrize( @@ -1865,7 +1865,7 @@ class Describe_BaseUnconditionalCubeCounts: ), ), ) - def it_provides_a_factory_for_constructing_weighted_cube_count_objects( + def test_it_provides_a_factory_for_constructing_weighted_cube_count_objects( self, request, cube_, @@ -1904,7 +1904,7 @@ def it_provides_a_factory_for_constructing_weighted_cube_count_objects( ) assert weighted_cube_counts is uncond_cube_counts_ - def it_provides_valid_row_idxs_to_help(self, request, dimensions_): + def test_it_provides_valid_row_idxs_to_help(self, request, dimensions_): valid_elements_ = instance_mock(request, Elements, element_idxs=(0, 2, 4)) dimensions_[0].valid_elements = valid_elements_ unconditional_counts = _BaseUnconditionalCubeCounts(dimensions_, None) diff --git a/tests/unit/matrix/test_measure.py b/tests/unit/matrix/test_measure.py index 3f02f547b..232887482 100644 --- a/tests/unit/matrix/test_measure.py +++ b/tests/unit/matrix/test_measure.py @@ -70,7 +70,7 @@ from ...unitutil import ANY, call, class_mock, instance_mock, method_mock, property_mock -class DescribeSecondOrderMeasures: +class TestSecondOrderMeasures: """Unit test suite for `cr.cube.matrix.measure.SecondOrderMeasures` object.""" @pytest.mark.parametrize( @@ -102,7 +102,7 @@ class DescribeSecondOrderMeasures: ("zscores", _Zscores), ), ) - def it_provides_access_to_various_measure_objects( + def test_it_provides_access_to_various_measure_objects( self, request, _cube_measures_prop_, @@ -126,7 +126,7 @@ def it_provides_access_to_various_measure_objects( assert measure is measure_ @pytest.mark.parametrize("measure_type", ("column", "row", "table")) - def it_provides_access_to_proportion_variance_measures( + def test_it_provides_access_to_proportion_variance_measures( self, request, _cube_measures_prop_, cube_measures_, measure_type ): Dimension_ = class_mock(request, "cr.cube.dimension.Dimension") @@ -164,7 +164,7 @@ def it_provides_access_to_proportion_variance_measures( ) assert measure is measure_ - def it_provides_access_to_the_columns_pruning_base( + def test_it_provides_access_to_the_columns_pruning_base( self, _cube_measures_prop_, cube_measures_, unweighted_cube_counts_ ): _cube_measures_prop_.return_value = cube_measures_ @@ -174,7 +174,7 @@ def it_provides_access_to_the_columns_pruning_base( assert measures.columns_pruning_mask == [True, False, True, False] - def it_provides_access_to_the_rows_pruning_base( + def test_it_provides_access_to_the_rows_pruning_base( self, _cube_measures_prop_, cube_measures_, unweighted_cube_counts_ ): _cube_measures_prop_.return_value = cube_measures_ @@ -184,7 +184,7 @@ def it_provides_access_to_the_rows_pruning_base( assert measures.rows_pruning_mask == [False, False, True, False] - def it_provides_access_to_the_cube_measures_to_help( + def test_it_provides_access_to_the_cube_measures_to_help( self, request, cube_, dimensions_, cube_measures_ ): CubeMeasures_ = class_mock( @@ -216,7 +216,7 @@ def it_provides_access_to_the_cube_measures_to_help( ("columns", "columns_scale_mean_stderr", _ScaleMeanStderr), ), ) - def it_provides_access_to_the_marginals( + def test_it_provides_access_to_the_marginals( self, request, _cube_measures_prop_, @@ -243,7 +243,7 @@ def it_provides_access_to_the_marginals( ) assert marginal is marginal_ - def it_provides_access_to_the_table_weighted_base_scalar( + def test_it_provides_access_to_the_table_weighted_base_scalar( self, request, dimensions_, @@ -275,7 +275,7 @@ def it_provides_access_to_the_table_weighted_base_scalar( ("pairwise_significance_means_t_stats", _PairwiseMeansSigTStats), ), ) - def it_provides_access_to_pairwise_significance_measure_objects( + def test_it_provides_access_to_pairwise_significance_measure_objects( self, request, dimensions_, @@ -324,10 +324,10 @@ def unweighted_cube_counts_(self, request): return instance_mock(request, _BaseCubeCounts) -class Describe_BaseSecondOrderMeasure: +class Test_BaseSecondOrderMeasure: """Unit test suite for `cr.cube.matrix.measure._BaseSecondOrderMeasure` object.""" - def it_assembles_the_blocks_for_the_measure(self, request): + def test_it_assembles_the_blocks_for_the_measure(self, request): property_mock( request, _BaseSecondOrderMeasure, "_base_values", return_value="A" ) @@ -353,10 +353,10 @@ def dimensions_(self, request): return (instance_mock(request, Dimension), instance_mock(request, Dimension)) -class Describe_ColumnComparableCounts: +class Test_ColumnComparableCounts: """Unit test suite for `cr.cube.matrix.measure._ColumnComparableCounts` object.""" - def it_computes_its_blocks(self, request, is_defined_prop_, dimensions_): + def test_it_computes_its_blocks(self, request, is_defined_prop_, dimensions_): is_defined_prop_.return_value = True counts = np.arange(12).reshape(3, 4).tolist() cube_counts_ = instance_mock(request, _BaseCubeCounts, counts=counts) @@ -377,7 +377,7 @@ def it_computes_its_blocks(self, request, is_defined_prop_, dimensions_): ) assert blocks == [[[1], [2]], [[3], [4]]] - def but_blocks_raises_when_is_not_defined(self, is_defined_prop_): + def test_but_blocks_raises_when_is_not_defined(self, is_defined_prop_): is_defined_prop_.return_value = False with pytest.raises(ValueError) as e: @@ -396,7 +396,7 @@ def but_blocks_raises_when_is_not_defined(self, is_defined_prop_): ((DT.CAT, DT.NUM_ARRAY), False), ), ) - def it_knows_when_it_is_defined(self, dimensions_, dim_types, expected): + def test_it_knows_when_it_is_defined(self, dimensions_, dim_types, expected): dimensions_[0].dimension_type = dim_types[0] dimensions_[1].dimension_type = dim_types[1] col_comparable_counts = _ColumnComparableCounts(dimensions_, None, None) @@ -414,10 +414,10 @@ def is_defined_prop_(self, request): return property_mock(request, _ColumnComparableCounts, "is_defined") -class Describe_ColumnProportions: +class Test_ColumnProportions: """Unit test suite for `cr.cube.matrix.measure._ColumnProportions` object.""" - def it_computes_its_blocks(self, request): + def test_it_computes_its_blocks(self, request): property_mock( request, _ColumnProportions, "_subtotal_columns", return_value=2.0 ) @@ -443,10 +443,10 @@ def it_computes_its_blocks(self, request): assert column_proportions.blocks == [[1.0, 2.0], [3.0, 4.0]] -class Describe_ProportionVariances: +class Test_ProportionVariances: """Unit test suite for `cr.cube.matrix.measure._ProportionVariances` object.""" - def it_computes_its_blocks( + def test_it_computes_its_blocks( self, request, bases_, @@ -479,7 +479,7 @@ def it_computes_its_blocks( call(variances, "p4", "Nt4", "Np4", "Ni4", "Nn4"), ] - def it_can_compute_variance_to_help(self): + def test_it_can_compute_variance_to_help(self): p = np.array([[0.8, 0.3], [0.2, 0.7], [0.6, -0.4]]) Nt = np.array([[5, 10], [5, 10], [5, 10]]) Np = np.array([[4, 3], [1, 7], [4, 3]]) @@ -493,7 +493,7 @@ def it_can_compute_variance_to_help(self): pytest.approx([0.64, 0.84]), ] - def it_provides_the_count_ignored_to_help( + def test_it_provides_the_count_ignored_to_help( self, bases_, _count_positive_prop_, _count_negative_prop_ ): bases_.blocks = [[5, 10], [6, 11]] @@ -503,7 +503,7 @@ def it_provides_the_count_ignored_to_help( assert variances._count_ignored == [[4, 4], [3, 1]] - def it_provides_the_count_negative_to_help( + def test_it_provides_the_count_negative_to_help( self, request, dimensions_, _weighted_cube_counts_prop_, cube_counts_ ): negative_term_blocks = method_mock( @@ -515,7 +515,7 @@ def it_provides_the_count_negative_to_help( assert variances._count_negative == "b" negative_term_blocks.assert_called_once_with(cube_counts_.counts, dimensions_) - def it_provides_the_count_positive_to_help( + def test_it_provides_the_count_positive_to_help( self, request, dimensions_, _weighted_cube_counts_prop_, cube_counts_ ): positive_term_blocks = method_mock( @@ -566,10 +566,10 @@ def _weighted_cube_counts_prop_(self, request): return property_mock(request, _ProportionVariances, "_weighted_cube_counts") -class Describe_ColumnShareSum: +class Test_ColumnShareSum: """Unit test suite for `cr.cube.matrix.measure._ColumnShareSum` object.""" - def it_computes_its_blocks(self, request): + def test_it_computes_its_blocks(self, request): SumSubtotals_ = class_mock(request, "cr.cube.matrix.measure.SumSubtotals") SumSubtotals_.blocks.return_value = [ [[5.0, 12.0], [21.0, 32.0]], @@ -592,10 +592,10 @@ def it_computes_its_blocks(self, request): SumSubtotals_.blocks.assert_called_once_with(ANY, None, True, True) -class Describe_ColumnStandardError: +class Test_ColumnStandardError: """Unit test suite for `cr.cube.matrix.measure._ColumnStandardError` object.""" - def it_computes_its_blocks(self, request): + def test_it_computes_its_blocks(self, request): column_proportion_variances_ = instance_mock( request, _ProportionVariances, blocks=[[4.0, 18.0], [48.0, 100.0]] ) @@ -614,10 +614,10 @@ def it_computes_its_blocks(self, request): assert stderrs.blocks == [[2.0, 3.0], [4.0, 5.0]] -class Describe_ColumnUnweightedBases: +class Test_ColumnUnweightedBases: """Unit test suite for `cr.cube.matrix.measure._ColumnUnweightedBases` object.""" - def it_computes_its_base_values_to_help( + def test_it_computes_its_base_values_to_help( self, _unweighted_cube_counts_prop_, unweighted_cube_counts_ ): _unweighted_cube_counts_prop_.return_value = unweighted_cube_counts_ @@ -626,7 +626,7 @@ def it_computes_its_base_values_to_help( assert column_unweighted_bases._base_values.tolist() == [[0, 1, 2], [3, 4, 5]] - def it_computes_its_intersections_block_to_help( + def test_it_computes_its_intersections_block_to_help( self, request, _base_values_prop_, dimensions_, SumSubtotals_ ): property_mock( @@ -646,7 +646,7 @@ def it_computes_its_intersections_block_to_help( ) assert intersections.tolist() == [[9, 6], [9, 6]] - def it_computes_its_subtotal_columns_to_help( + def test_it_computes_its_subtotal_columns_to_help( self, _base_values_prop_, dimensions_, SumSubtotals_ ): _base_values_prop_.return_value = [[1, 2], [3, 4]] @@ -660,7 +660,7 @@ def it_computes_its_subtotal_columns_to_help( ) assert subtotal_columns.tolist() == [[5, 8], [3, 7]] - def it_computes_its_subtotal_rows_to_help( + def test_it_computes_its_subtotal_rows_to_help( self, _base_values_prop_, dimensions_, @@ -681,7 +681,7 @@ def it_computes_its_subtotal_rows_to_help( ) assert subtotal_rows.tolist() == [[4, 7], [4, 7]] - def but_it_returns_empty_array_of_right_shape_when_there_are_no_row_subtotals( + def test_but_it_returns_empty_array_of_right_shape_when_there_are_no_row_subtotals( self, _base_values_prop_, dimensions_, SumSubtotals_ ): """Empty shape must be (0, ncols) to compose properly in `np.block()` call.""" @@ -721,10 +721,10 @@ def _unweighted_cube_counts_prop_(self, request): return property_mock(request, _ColumnUnweightedBases, "_unweighted_cube_counts") -class Describe_ColumnWeightedBases: +class Test_ColumnWeightedBases: """Unit test suite for `cr.cube.matrix.measure._ColumnWeightedBases` object.""" - def it_computes_its_base_values_to_help( + def test_it_computes_its_base_values_to_help( self, _weighted_cube_counts_prop_, weighted_cube_counts_ ): _weighted_cube_counts_prop_.return_value = weighted_cube_counts_ @@ -733,7 +733,7 @@ def it_computes_its_base_values_to_help( assert column_weighted_bases._base_values.tolist() == [[0, 1], [2, 3], [4, 5]] - def it_computes_its_intersections_block_to_help( + def test_it_computes_its_intersections_block_to_help( self, request, _base_values_prop_, dimensions_, SumSubtotals_ ): property_mock( @@ -759,7 +759,7 @@ def it_computes_its_intersections_block_to_help( ) assert intersections.tolist() == [[9.9, 6.6], [9.9, 6.6]] - def it_computes_its_subtotal_columns_to_help( + def test_it_computes_its_subtotal_columns_to_help( self, _base_values_prop_, dimensions_, SumSubtotals_ ): _base_values_prop_.return_value = [[1.1, 2.2], [3.3, 4.4]] @@ -773,7 +773,7 @@ def it_computes_its_subtotal_columns_to_help( ) assert subtotal_columns.tolist() == [[5.5, 8.8], [3.3, 7.7]] - def it_computes_its_subtotal_rows_to_help( + def test_it_computes_its_subtotal_rows_to_help( self, _base_values_prop_, dimensions_, @@ -797,7 +797,7 @@ def it_computes_its_subtotal_rows_to_help( ] assert subtotal_rows.tolist() == [[4.4, 7.7], [4.4, 7.7]] - def but_it_returns_empty_array_of_right_shape_when_there_are_no_row_subtotals( + def test_but_it_returns_empty_array_of_right_shape_when_there_are_no_row_subtotals( self, _base_values_prop_, dimensions_, SumSubtotals_ ): """Empty shape must be (0, ncols) to compose properly in `np.block()` call.""" @@ -837,10 +837,10 @@ def _weighted_cube_counts_prop_(self, request): return property_mock(request, _ColumnWeightedBases, "_weighted_cube_counts") -class Describe_PairwiseMeansSigPvals: +class Test_PairwiseMeansSigPvals: """Unit test suite for `cr.cube.matrix.measure._PairwiseMeansSigPvals` object.""" - def it_provides_the_df(self, request): + def test_it_provides_the_df(self, request): # Adapted from: # https://mse.redwoods.edu/darnold/math15/spring2013/R/Activities/WelchTTest.html cube_std_dev_ = instance_mock( @@ -857,10 +857,10 @@ def it_provides_the_df(self, request): assert pairwise_pvals._df == pytest.approx(np.array([[44, 37.8554]])) -class Describe_PairwiseMeansSigTStats: +class Test_PairwiseMeansSigTStats: """Unit test suite for `cr.cube.matrix.measure._PairwiseMeansSigTStats` object.""" - def it_provides_the_tstats(self, request): + def test_it_provides_the_tstats(self, request): # Adapted from: # https://mse.redwoods.edu/darnold/math15/spring2013/R/Activities/WelchTTest.html cube_means_ = instance_mock( @@ -881,10 +881,10 @@ def it_provides_the_tstats(self, request): assert pairwise_tstat.t_stats == pytest.approx(np.array([[0, 2.310889]])) -class Describe_PairwiseSigTstats: +class Test_PairwiseSigTstats: """Unit test suite for `cr.cube.matrix.measure._PairwiseSigTstats` object.""" - def it_provides_a_blocks_interface(self, request): + def test_it_provides_a_blocks_interface(self, request): property_mock(request, _PairwiseSigTstats, "_base_values", return_value=1) property_mock(request, _PairwiseSigTstats, "_subtotal_columns", return_value=2) property_mock(request, _PairwiseSigTstats, "_subtotal_rows", return_value=3) @@ -893,7 +893,7 @@ def it_provides_a_blocks_interface(self, request): assert pairwise_tstat.blocks == [[1, 2], [3, 4]] - def it_calculates_the_base_values_to_help( + def test_it_calculates_the_base_values_to_help( self, _bases_prop_, _proportions_prop_, _reference_values_, _calculate_t_stats_ ): _bases_prop_.return_value = [[1, 2], [3, 4]] @@ -908,14 +908,14 @@ def it_calculates_the_base_values_to_help( _reference_values_.assert_called_once_with(pairwise_tstat, 0) _calculate_t_stats_.assert_called_once_with(pairwise_tstat, 0.5, 1, 9, 0) - def it_provides_the_bases_to_help(self, second_order_measures_): + def test_it_provides_the_bases_to_help(self, second_order_measures_): second_order_measures_.column_unweighted_bases.blocks = [1, 2] second_order_measures_.columns_squared_base.is_defined = False pairwise_tstat = _PairwiseSigTstats(None, second_order_measures_, None, None) assert pairwise_tstat._column_bases == [1, 2] - def it_can_calculate_the_t_stat_to_help(self): + def test_it_can_calculate_the_t_stat_to_help(self): pairwise_tstat = _PairwiseSigTstats(None, None, None, None) actual = pairwise_tstat._calculate_t_stats( @@ -938,7 +938,7 @@ def it_can_calculate_the_t_stat_to_help(self): ) ) - def but_tstat_calculation_is_ok_with_empty_inputs(self): + def test_but_tstat_calculation_is_ok_with_empty_inputs(self): pairwise_tstat = _PairwiseSigTstats(None, None, None, None) actual = pairwise_tstat._calculate_t_stats( @@ -950,7 +950,7 @@ def but_tstat_calculation_is_ok_with_empty_inputs(self): assert actual.tolist() == [[]] - def it_provides_the_intersections_to_help( + def test_it_provides_the_intersections_to_help( self, _bases_prop_, _proportions_prop_, _reference_values_, _calculate_t_stats_ ): _bases_prop_.return_value = [[1, 2], [3, 4]] @@ -965,7 +965,7 @@ def it_provides_the_intersections_to_help( _reference_values_.assert_called_once_with(pairwise_tstat, 1) _calculate_t_stats_.assert_called_once_with(pairwise_tstat, 0.8, 4, 9, 0) - def it_provides_the_proportions_to_help(self, second_order_measures_): + def test_it_provides_the_proportions_to_help(self, second_order_measures_): second_order_measures_.column_proportions.blocks = [1, 2] pairwise_tstat = _PairwiseSigTstats(None, second_order_measures_, None, None) @@ -981,7 +981,7 @@ def it_provides_the_proportions_to_help(self, second_order_measures_): (-2, 1, ("13", "15")), ), ) - def it_can_calculate_the_reference_values_to_help( + def test_it_can_calculate_the_reference_values_to_help( self, _bases_prop_, _proportions_prop_, col_index, block_index, expected ): _bases_prop_.return_value = [ @@ -1011,7 +1011,7 @@ def it_can_calculate_the_reference_values_to_help( assert actual[1].tolist() == [["b" + i] for i in expected] assert actual[0].tolist() == [["p" + i] for i in expected] - def it_provides_the_subtotal_columns_to_help( + def test_it_provides_the_subtotal_columns_to_help( self, _bases_prop_, _proportions_prop_, _reference_values_, _calculate_t_stats_ ): _bases_prop_.return_value = [[1, 2], [3, 4]] @@ -1026,7 +1026,7 @@ def it_provides_the_subtotal_columns_to_help( _reference_values_.assert_called_once_with(pairwise_tstat, 0) _calculate_t_stats_.assert_called_once_with(pairwise_tstat, 0.6, 2, 9, 0) - def it_provides_the_subtotal_rows_to_help( + def test_it_provides_the_subtotal_rows_to_help( self, _bases_prop_, _proportions_prop_, _reference_values_, _calculate_t_stats_ ): _bases_prop_.return_value = [[1, 2], [3, 4]] @@ -1064,7 +1064,7 @@ def second_order_measures_(self, request): return instance_mock(request, SecondOrderMeasures) -class Describe_PopulationProportions: +class Test_PopulationProportions: """Unit test suite for `cr.cube.matrix.measure._PopulationProportions` object.""" @pytest.mark.parametrize( @@ -1077,7 +1077,7 @@ class Describe_PopulationProportions: ((DT.CAT, DT.TEXT, DT.CA_CAT), "table"), ), ) - def it_computes_its_blocks(self, request, dimension_types, expected): + def test_it_computes_its_blocks(self, request, dimension_types, expected): dimensions_ = [ instance_mock(request, Dimension, dimension_type=dt) for dt in dimension_types @@ -1098,7 +1098,7 @@ def it_computes_its_blocks(self, request, dimension_types, expected): ) -class Describe_PopulationStandardError: +class Test_PopulationStandardError: """Unit test suite for `cr.cube.matrix.measure._PopulationStandardError` object.""" @pytest.mark.parametrize( @@ -1111,7 +1111,7 @@ class Describe_PopulationStandardError: ((DT.CAT, DT.TEXT, DT.CAT_DATE), "column"), ), ) - def it_computes_its_blocks(self, request, dimension_types, expected): + def test_it_computes_its_blocks(self, request, dimension_types, expected): dimensions_ = [ instance_mock(request, Dimension, dimension_type=dt) for dt in dimension_types @@ -1132,10 +1132,10 @@ def it_computes_its_blocks(self, request, dimension_types, expected): ) -class Describe_Pvalues: +class Test_Pvalues: """Unit test suite for `cr.cube.matrix.measure._Pvalues` object.""" - def it_provides_its_blocks(self, request): + def test_it_provides_its_blocks(self, request): _calculate_pval_ = method_mock( request, _Pvalues, "_calculate_pval", side_effect=(0, 1, 2, 3) ) @@ -1164,16 +1164,16 @@ def it_provides_its_blocks(self, request): ([], []), ), ) - def it_can_calculate_pval_to_help(self, zscores, expected): + def test_it_can_calculate_pval_to_help(self, zscores, expected): actual = _Pvalues(None, None, None)._calculate_pval(np.array(zscores)) assert actual == pytest.approx(np.array(expected)) -class Describe_RowComparableCounts: +class Test_RowComparableCounts: """Unit test suite for `cr.cube.matrix.measure._RowComparableCounts` object.""" - def it_computes_its_blocks(self, request, is_defined_prop_, dimensions_): + def test_it_computes_its_blocks(self, request, is_defined_prop_, dimensions_): is_defined_prop_.return_value = True counts = np.arange(12).reshape(3, 4).tolist() cube_counts_ = instance_mock(request, _BaseCubeCounts, counts=counts) @@ -1194,7 +1194,7 @@ def it_computes_its_blocks(self, request, is_defined_prop_, dimensions_): ) assert blocks == [[[1], [2]], [[3], [4]]] - def but_blocks_raises_when_is_not_defined(self, is_defined_prop_): + def test_but_blocks_raises_when_is_not_defined(self, is_defined_prop_): is_defined_prop_.return_value = False with pytest.raises(ValueError) as e: @@ -1211,7 +1211,7 @@ def but_blocks_raises_when_is_not_defined(self, is_defined_prop_): ((DT.CA_SUBVAR, DT.CA_CAT), False), ), ) - def it_knows_when_it_is_defined(self, dimensions_, dim_types, expected): + def test_it_knows_when_it_is_defined(self, dimensions_, dim_types, expected): dimensions_[0].dimension_type = dim_types[0] dimensions_[1].dimension_type = dim_types[1] row_comparable_counts = _RowComparableCounts(dimensions_, None, None) @@ -1229,10 +1229,10 @@ def is_defined_prop_(self, request): return property_mock(request, _RowComparableCounts, "is_defined") -class Describe_RowProportions: +class Test_RowProportions: """Unit test suite for `cr.cube.matrix.measure._RowProportions` object.""" - def it_computes_its_blocks(self, request): + def test_it_computes_its_blocks(self, request): property_mock(request, _RowProportions, "_inserted_columns", return_value=2.0) property_mock(request, _RowProportions, "_inserted_rows", return_value=3.0) weighted_counts_ = instance_mock( @@ -1254,10 +1254,10 @@ def it_computes_its_blocks(self, request): assert row_proportions.blocks == [[1.0, 2.0], [3.0, 4.0]] -class Describe_RowStandardError: +class Test_RowStandardError: """Unit test suite for `cr.cube.matrix.measure._RowStandardError` object.""" - def it_computes_its_blocks(self, request): + def test_it_computes_its_blocks(self, request): row_proportion_variances_ = instance_mock( request, _ProportionVariances, blocks=[[4.0, 18.0], [48.0, 100.0]] ) @@ -1276,10 +1276,10 @@ def it_computes_its_blocks(self, request): assert stderrs.blocks == [[2.0, 3.0], [4.0, 5.0]] -class Describe_RowUnweightedBases: +class Test_RowUnweightedBases: """Unit test suite for `cr.cube.matrix.measure._RowUnweightedBases` object.""" - def it_computes_its_base_values_to_help( + def test_it_computes_its_base_values_to_help( self, _unweighted_cube_counts_prop_, unweighted_cube_counts_ ): _unweighted_cube_counts_prop_.return_value = unweighted_cube_counts_ @@ -1305,7 +1305,7 @@ def it_computes_its_base_values_to_help( ), ), ) - def it_computes_its_intersections_block_to_help( + def test_it_computes_its_intersections_block_to_help( self, request, subtotal_rows, @@ -1332,7 +1332,7 @@ def it_computes_its_intersections_block_to_help( assert intersections.shape == expected_shape assert intersections.dtype == int - def it_computes_its_subtotal_columns_to_help( + def test_it_computes_its_subtotal_columns_to_help( self, _base_values_prop_, dimensions_, @@ -1353,7 +1353,7 @@ def it_computes_its_subtotal_columns_to_help( ) assert subtotal_columns.tolist() == [[7, 7], [4, 4]] - def but_it_returns_empty_array_of_right_shape_when_there_are_no_column_subtotals( + def test_it_returns_empty_array_of_right_shape_when_there_are_no_column_subtotals( self, _base_values_prop_, dimensions_, SumSubtotals_ ): """Empty shape must be (nrows, 0) to compose properly in `np.block()` call.""" @@ -1372,7 +1372,7 @@ def but_it_returns_empty_array_of_right_shape_when_there_are_no_column_subtotals assert subtotal_columns.shape == (3, 0) assert subtotal_columns.dtype == int - def it_computes_its_subtotal_rows_to_help( + def test_it_computes_its_subtotal_rows_to_help( self, _base_values_prop_, dimensions_, SumSubtotals_ ): _base_values_prop_.return_value = [[1, 2], [3, 4]] @@ -1409,10 +1409,10 @@ def _unweighted_cube_counts_prop_(self, request): return property_mock(request, _RowUnweightedBases, "_unweighted_cube_counts") -class Describe_RowWeightedBases: +class Test_RowWeightedBases: """Unit test suite for `cr.cube.matrix.measure._RowWeightedBases` object.""" - def it_computes_its_base_values_to_help( + def test_it_computes_its_base_values_to_help( self, _weighted_cube_counts_prop_, weighted_cube_counts_ ): _weighted_cube_counts_prop_.return_value = weighted_cube_counts_ @@ -1441,7 +1441,7 @@ def it_computes_its_base_values_to_help( ), ), ) - def it_computes_its_intersections_block_to_help( + def test_it_computes_its_intersections_block_to_help( self, request, subtotal_rows, @@ -1472,7 +1472,7 @@ def it_computes_its_intersections_block_to_help( assert intersections.shape == expected_shape assert intersections.dtype == float - def it_computes_its_subtotal_columns_to_help( + def test_it_computes_its_subtotal_columns_to_help( self, _base_values_prop_, dimensions_, @@ -1496,7 +1496,7 @@ def it_computes_its_subtotal_columns_to_help( ] assert subtotal_columns.tolist() == [[7.7, 7.7], [4.4, 4.4]] - def but_it_returns_empty_array_of_right_shape_when_there_are_no_column_subtotals( + def test_it_returns_empty_array_of_right_shape_when_there_are_no_column_subtotals( self, _base_values_prop_, dimensions_, SumSubtotals_ ): """Empty shape must be (nrows, 0) to compose properly in `np.block()` call.""" @@ -1515,7 +1515,7 @@ def but_it_returns_empty_array_of_right_shape_when_there_are_no_column_subtotals assert subtotal_columns.shape == (3, 0) assert subtotal_columns.dtype == int - def it_computes_its_subtotal_rows_to_help( + def test_it_computes_its_subtotal_rows_to_help( self, _base_values_prop_, dimensions_, SumSubtotals_ ): _base_values_prop_.return_value = [[1.1, 2.2], [3.3, 4.4]] @@ -1552,10 +1552,10 @@ def _weighted_cube_counts_prop_(self, request): return property_mock(request, _RowWeightedBases, "_weighted_cube_counts") -class Describe_RowShareSum: +class Test_RowShareSum: """Unit test suite for `cr.cube.matrix.measure._RowShareSum` object.""" - def it_computes_its_blocks(self, request): + def test_it_computes_its_blocks(self, request): SumSubtotals_ = class_mock(request, "cr.cube.matrix.measure.SumSubtotals") SumSubtotals_.blocks.return_value = [ np.array([[[5.0, 12.0]], [[21.0, 32.0]]]), @@ -1584,10 +1584,10 @@ def it_computes_its_blocks(self, request): SumSubtotals_.blocks.assert_called_once_with(ANY, None, True, True) -class Describe_TableProportions: +class Test_TableProportions: """Unit test suite for `cr.cube.matrix.measure._TableProportions` object.""" - def it_computes_its_blocks(self, request): + def test_it_computes_its_blocks(self, request): weighted_counts_ = instance_mock( request, _WeightedCounts, blocks=[[5.0, 12.0], [21.0, 32.0]] ) @@ -1606,10 +1606,10 @@ def it_computes_its_blocks(self, request): assert table_proportions.blocks == [[1.0, 2.0], [3.0, 4.0]] -class Describe_TableStandardError: +class Test_TableStandardError: """Unit test suite for `cr.cube.matrix.measure._TableStandardError` object.""" - def it_computes_its_blocks(self, request): + def test_it_computes_its_blocks(self, request): table_proportion_variances_ = instance_mock( request, _ProportionVariances, blocks=[[4.0, 18.0], [48.0, 100.0]] ) @@ -1628,10 +1628,10 @@ def it_computes_its_blocks(self, request): assert stderrs.blocks == [[2.0, 3.0], [4.0, 5.0]] -class Describe_TotalShareSum: +class Test_TotalShareSum: """Unit test suite for `cr.cube.matrix.measure._RowShareSum` object.""" - def it_computes_its_blocks(self, request): + def test_it_computes_its_blocks(self, request): SumSubtotals_ = class_mock(request, "cr.cube.matrix.measure.SumSubtotals") SumSubtotals_.blocks.return_value = [ np.array([[[5.0, 12.0]], [[21.0, 32.0]]]), @@ -1660,10 +1660,10 @@ def it_computes_its_blocks(self, request): SumSubtotals_.blocks.assert_called_once_with(ANY, None, True, True) -class Describe_TableUnweightedBases: +class Test_TableUnweightedBases: """Unit test suite for `cr.cube.matrix.measure._TableUnweightedBases` object.""" - def it_computes_its_base_values_to_help( + def test_it_computes_its_base_values_to_help( self, _unweighted_cube_counts_prop_, unweighted_cube_counts_ ): _unweighted_cube_counts_prop_.return_value = unweighted_cube_counts_ @@ -1686,7 +1686,7 @@ def it_computes_its_base_values_to_help( ((4, 1), [[6.6], [6.6], [6.6], [6.6]]), ), ) - def it_computes_its_intersections_block_to_help( + def test_it_computes_its_intersections_block_to_help( self, _base_values_prop_, _intersections_shape_prop_, @@ -1708,7 +1708,7 @@ def it_computes_its_intersections_block_to_help( assert intersections.shape == intersections_shape assert intersections.dtype == np.float64 - def it_computes_its_intersections_shape_to_help(self, dimensions_): + def test_it_computes_its_intersections_shape_to_help(self, dimensions_): dimensions_[0].subtotals = [0, 1] dimensions_[1].subtotals = [2, 3, 4] @@ -1725,7 +1725,7 @@ def it_computes_its_intersections_shape_to_help(self, dimensions_): ((4, 1), [[6.6], [9.9], [3.3]]), ), ) - def it_computes_its_subtotal_columns_to_help( + def test_it_computes_its_subtotal_columns_to_help( self, _base_values_prop_, _intersections_shape_prop_, @@ -1760,7 +1760,7 @@ def it_computes_its_subtotal_columns_to_help( ), ), ) - def it_computes_its_subtotal_rows_to_help( + def test_it_computes_its_subtotal_rows_to_help( self, _base_values_prop_, _intersections_shape_prop_, @@ -1806,10 +1806,10 @@ def _unweighted_cube_counts_prop_(self, request): return property_mock(request, _TableUnweightedBases, "_unweighted_cube_counts") -class Describe_TableWeightedBases: +class Test_TableWeightedBases: """Unit test suite for `cr.cube.matrix.measure._TableWeightedBases` object.""" - def it_computes_its_base_values_to_help( + def test_it_computes_its_base_values_to_help( self, _weighted_cube_counts_prop_, weighted_cube_counts_ ): _weighted_cube_counts_prop_.return_value = weighted_cube_counts_ @@ -1830,7 +1830,7 @@ def it_computes_its_base_values_to_help( ((4, 1), [[6.6], [6.6], [6.6], [6.6]]), ), ) - def it_computes_its_intersections_block_to_help( + def test_it_computes_its_intersections_block_to_help( self, _base_values_prop_, _intersections_shape_prop_, @@ -1852,7 +1852,7 @@ def it_computes_its_intersections_block_to_help( assert intersections.shape == intersections_shape assert intersections.dtype == np.float64 - def it_computes_its_intersections_shape_to_help(self, dimensions_): + def test_it_computes_its_intersections_shape_to_help(self, dimensions_): dimensions_[0].subtotals = [0, 1] dimensions_[1].subtotals = [2, 3, 4] @@ -1869,7 +1869,7 @@ def it_computes_its_intersections_shape_to_help(self, dimensions_): ((4, 1), [[6.6], [9.9], [3.3]]), ), ) - def it_computes_its_subtotal_columns_to_help( + def test_it_computes_its_subtotal_columns_to_help( self, _base_values_prop_, _intersections_shape_prop_, @@ -1904,7 +1904,7 @@ def it_computes_its_subtotal_columns_to_help( ), ), ) - def it_computes_its_subtotal_rows_to_help( + def test_it_computes_its_subtotal_rows_to_help( self, _base_values_prop_, _intersections_shape_prop_, @@ -1950,10 +1950,10 @@ def _weighted_cube_counts_prop_(self, request): return property_mock(request, _TableWeightedBases, "_weighted_cube_counts") -class Describe_UnweightedCounts: +class Test_UnweightedCounts: """Unit test suite for `cr.cube.matrix.measure._UnweightedCounts` object.""" - def it_computes_its_blocks_to_help(self, request, dimensions_, cube_measures_): + def test_it_computes_its_blocks_to_help(self, request, dimensions_, cube_measures_): # --- these need to be in list form because the assert-called-with mechanism # --- uses equality, which doesn't work on numpy arrays. Normally this would be # --- the array itself. @@ -1990,10 +1990,10 @@ def cube_measures_(self, request): return instance_mock(request, CubeMeasures) -class Describe_WeightedCounts: +class Test_WeightedCounts: """Unit test suite for `cr.cube.matrix.measure._WeightedCounts` object.""" - def it_computes_its_blocks_to_help(self, request, dimensions_, cube_measures_): + def test_it_computes_its_blocks_to_help(self, request, dimensions_, cube_measures_): # --- these need to be in list form because the assert-called-with mechanism # --- uses equality, which doesn't work on numpy arrays. Normally this would be # --- the array itself. @@ -2027,10 +2027,10 @@ def dimensions_(self, request): return instance_mock(request, Dimension), instance_mock(request, Dimension) -class Describe_Zscores: +class Test_Zscores: """Unit test suite for `cr.cube.matrix.measure._Zscores` object.""" - def it_computes_its_blocks_for_non_mr_dimensions( + def test_it_computes_its_blocks_for_non_mr_dimensions( self, request, _base_values_prop_, dimensions_ ): _base_values_prop_.return_value = "A" @@ -2042,7 +2042,7 @@ def it_computes_its_blocks_for_non_mr_dimensions( assert blocks == [["A", "B"], ["C", "D"]] - def it_can_calculate_a_zscore(self, _is_defective_prop_): + def test_it_can_calculate_a_zscore(self, _is_defective_prop_): _is_defective_prop_.return_value = False zscores = _Zscores(None, None, None) @@ -2058,7 +2058,7 @@ def it_can_calculate_a_zscore(self, _is_defective_prop_): pytest.approx([-0.4387482, 8.67757795e-16, 0.5097793]), ] - def but_it_does_not_calculate_zscore_if_defective(self, _is_defective_prop_): + def test_but_it_does_not_calculate_zscore_if_defective(self, _is_defective_prop_): _is_defective_prop_.return_value = True counts = np.array([[3.3, 2.2, 1.1], [6.6, 5.5, 4.4]]) zscores = _Zscores(None, None, None) @@ -2067,7 +2067,7 @@ def but_it_does_not_calculate_zscore_if_defective(self, _is_defective_prop_): assert actual == pytest.approx(np.full(counts.shape, np.nan), nan_ok=True) - def and_it_is_nan_if_rows_base_equal_table_base(self, _is_defective_prop_): + def test_and_it_is_nan_if_rows_base_equal_table_base(self, _is_defective_prop_): _is_defective_prop_.return_value = False counts = np.array([[3.3, 2.2, 1.1], [6.6, 5.5, 4.4]]) zscores = _Zscores(None, None, None) @@ -2081,7 +2081,7 @@ def and_it_is_nan_if_rows_base_equal_table_base(self, _is_defective_prop_): assert actual == pytest.approx(np.full(counts.shape, np.nan), nan_ok=True) - def and_it_is_nan_if_columns_base_equal_table_base(self, _is_defective_prop_): + def test_and_it_is_nan_if_columns_base_equal_table_base(self, _is_defective_prop_): _is_defective_prop_.return_value = False counts = np.array([[3.3, 2.2, 1.1], [6.6, 5.5, 4.4]]) zscores = _Zscores(None, None, None) @@ -2104,7 +2104,7 @@ def and_it_is_nan_if_columns_base_equal_table_base(self, _is_defective_prop_): ([[1, 0, 0], [4, 0, 0]], True), ), ) - def it_knows_if_it_is_defective( + def test_it_knows_if_it_is_defective( self, request, second_order_measures_, counts, expected ): weighted_counts_ = instance_mock( @@ -2124,7 +2124,7 @@ def it_knows_if_it_is_defective( ("_intersections", 4), ), ) - def it_provides_the_block_components_to_help( + def test_it_provides_the_block_components_to_help( self, request, _calculate_zscores_, second_order_measures_, prop_name, index ): _calculate_zscores_.return_value = [[1, 2], [3, 4]] @@ -2179,15 +2179,15 @@ def second_order_measures_(self, request): # === Marginals === -class Describe_BaseMarginal: +class Test_BaseMarginal: """Unit test suite for `cr.cube.matrix.measure._BaseMarginal` object.""" - def it_is_defined_by_default(self): + def test_it_is_defined_by_default(self): marginal = _BaseMarginal(None, None, None, None) assert marginal.is_defined is True @pytest.mark.parametrize("orientation", (MO.ROWS, MO.COLUMNS)) - def it_knows_the_orientation_of_the_marginal(self, orientation): + def test_it_knows_the_orientation_of_the_marginal(self, orientation): marginal = _BaseMarginal(None, None, None, orientation) assert marginal.orientation == orientation @@ -2201,33 +2201,35 @@ def it_knows_the_orientation_of_the_marginal(self, orientation): (MO.COLUMNS, np.array([]).reshape(6, 0), []), ), ) - def it_can_apply_along_orientation_to_help(self, orientation, array, expected): + def test_it_can_apply_along_orientation_to_help(self, orientation, array, expected): marginal = _BaseMarginal(None, None, None, orientation) result = marginal._apply_along_orientation(np.sum, array) assert result.tolist() == expected - def it_gets_the_right_counts_for_rows(self, measure_, second_order_measures_): + def test_it_gets_the_right_counts_for_rows(self, measure_, second_order_measures_): measure_.blocks = [["a", "b"], ["c", "d"]] second_order_measures_.column_comparable_counts = measure_ marginal = _BaseMarginal(None, second_order_measures_, None, MO.ROWS) assert marginal._counts == ["a", "c"] - def it_gets_the_right_counts_for_columns(self, measure_, second_order_measures_): + def test_it_gets_the_right_counts_for_columns( + self, measure_, second_order_measures_ + ): measure_.blocks = [["a", "b"], ["c", "d"]] second_order_measures_.row_comparable_counts = measure_ marginal = _BaseMarginal(None, second_order_measures_, None, MO.COLUMNS) assert marginal._counts == ["a", "b"] - def it_knows_when_counts_are_defined_columns(self, second_order_measures_): + def test_it_knows_when_counts_are_defined_columns(self, second_order_measures_): marginal = _BaseMarginal(None, second_order_measures_, None, MO.COLUMNS) actual = marginal._counts_are_defined assert actual == second_order_measures_.row_comparable_counts.is_defined - def it_knows_when_counts_are_defined_rows(self, second_order_measures_): + def test_it_knows_when_counts_are_defined_rows(self, second_order_measures_): marginal = _BaseMarginal(None, second_order_measures_, None, MO.ROWS) actual = marginal._counts_are_defined @@ -2249,13 +2251,13 @@ def second_order_measures_(self, request): return instance_mock(request, SecondOrderMeasures) -class Describe_BaseScaledCountMarginal: +class Test_BaseScaledCountMarginal: """Unit test suite for `cr.cube.matrix.measure._BaseScaledCountMarginal` object.""" @pytest.mark.parametrize( "orientation, expected", ((MO.ROWS, [1]), (MO.COLUMNS, [0])) ) - def it_provides_opposing_numeric_values_to_help( + def test_it_provides_opposing_numeric_values_to_help( self, request, orientation, expected ): row_dim_ = instance_mock(request, Dimension, numeric_values=[0]) @@ -2267,10 +2269,10 @@ def it_provides_opposing_numeric_values_to_help( assert marginal._opposing_numeric_values == expected -class Describe_MarginTableBase: +class Test_MarginTableBase: """Unit test suite for `cr.cube.matrix.measure._MarginTableBase` object.""" - def it_provides_blocks_if_table_weighted_base( + def test_it_provides_blocks_if_table_weighted_base( self, request, _base_values_prop_, @@ -2286,7 +2288,7 @@ def it_provides_blocks_if_table_weighted_base( assert results[0].tolist() == [1.0, 1.0] assert results[1].tolist() == [1.0, 1.0, 1.0] - def but_it_raises_if_undefined(self, is_defined_prop_): + def test_but_it_raises_if_undefined(self, is_defined_prop_): is_defined_prop_.return_value = False with pytest.raises(ValueError) as e: @@ -2303,19 +2305,21 @@ def but_it_raises_if_undefined(self, is_defined_prop_): (np.array([1, 2]), True), ), ) - def it_can_tell_if_it_is_defined(self, _base_values_prop_, base_values, expected): + def test_it_can_tell_if_it_is_defined( + self, _base_values_prop_, base_values, expected + ): _base_values_prop_.return_value = base_values table_weighted_base = _MarginTableBase(None, None, None, None, None) assert table_weighted_base.is_defined == expected - def it_provides_the_base_values_for_rows_to_help(self, cube_counts_): + def test_it_provides_the_base_values_for_rows_to_help(self, cube_counts_): cube_counts_.rows_table_base = [1, 2] table_weighted_base = _MarginTableBase(None, None, None, MO.ROWS, cube_counts_) assert table_weighted_base._base_values == [1, 2] - def it_provides_the_base_values_for_columns_to_help(self, cube_counts_): + def test_it_provides_the_base_values_for_columns_to_help(self, cube_counts_): cube_counts_.columns_table_base = [1, 2] table_weighted_base = _MarginTableBase( None, None, None, MO.COLUMNS, cube_counts_ @@ -2323,13 +2327,15 @@ def it_provides_the_base_values_for_columns_to_help(self, cube_counts_): assert table_weighted_base._base_values == [1, 2] - def it_provides_subtotal_shape_for_rows_orientation_to_help(self, dimensions_): + def test_it_provides_subtotal_shape_for_rows_orientation_to_help(self, dimensions_): dimensions_[0].subtotals = (1, 2, 3) table_weighted_base = _MarginTableBase(dimensions_, None, None, MO.ROWS, None) assert table_weighted_base._subtotal_shape == 3 - def it_provides_subtotal_shape_for_columns_orientation_to_help(self, dimensions_): + def test_it_provides_subtotal_shape_for_columns_orientation_to_help( + self, dimensions_ + ): dimensions_[1].subtotals = (1,) table_weighted_base = _MarginTableBase( dimensions_, None, None, MO.COLUMNS, None @@ -2356,10 +2362,10 @@ def cube_counts_(self, request): return instance_mock(request, _BaseCubeCounts) -class Describe_MarginTableProportion: +class Test_MarginTableProportion: """Unit test suite for `cr.cube.matrix.measure._MarginTableProportion` object.""" - def it_provides_blocks(self, request): + def test_it_provides_blocks(self, request): property_mock( request, _MarginTableProportion, @@ -2379,12 +2385,12 @@ def it_provides_blocks(self, request): assert margin_proportion[0] == pytest.approx([0.4, 0.6]) assert margin_proportion[1].shape == (0,) - def it_can_tell_if_it_is_defined(self, request): + def test_it_can_tell_if_it_is_defined(self, request): property_mock(request, _BaseMarginal, "_counts_are_defined") margin_proportion = _MarginTableProportion(None, None, None, None) assert margin_proportion.is_defined == margin_proportion._counts_are_defined - def it_provides_the_right_denominator_for_rows( + def test_it_provides_the_right_denominator_for_rows( self, second_order_measures_, margin_table_base_, @@ -2395,7 +2401,7 @@ def it_provides_the_right_denominator_for_rows( assert margin._proportion_denominators == [[1, 2], [3, 4]] - def it_provides_the_right_denominator_for_columns( + def test_it_provides_the_right_denominator_for_columns( self, second_order_measures_, margin_table_base_, @@ -2406,7 +2412,7 @@ def it_provides_the_right_denominator_for_columns( assert margin._proportion_denominators == [[1, 2], [3, 4]] - def it_provides_the_right_numerator_for_rows( + def test_it_provides_the_right_numerator_for_rows( self, second_order_measures_, weighted_counts_, _apply_along_orientation_ ): second_order_measures_.weighted_counts = weighted_counts_ @@ -2420,7 +2426,7 @@ def it_provides_the_right_numerator_for_rows( call(margin, np.sum, 3), ] - def but_it_raises_if_column_counts_are_not_comparable( + def test_but_it_raises_if_column_counts_are_not_comparable( self, request, second_order_measures_, weighted_counts_ ): second_order_measures_.weighted_counts = weighted_counts_ @@ -2436,7 +2442,7 @@ def but_it_raises_if_column_counts_are_not_comparable( with pytest.raises(ValueError): margin._proportion_numerators - def it_provides_the_right_numerator_for_columns( + def test_it_provides_the_right_numerator_for_columns( self, second_order_measures_, weighted_counts_, _apply_along_orientation_ ): second_order_measures_.weighted_counts = weighted_counts_ @@ -2450,7 +2456,7 @@ def it_provides_the_right_numerator_for_columns( call(margin, np.sum, 2), ] - def but_it_raises_if_row_counts_are_not_comparable( + def test_but_it_raises_if_row_counts_are_not_comparable( self, request, second_order_measures_, weighted_counts_ ): second_order_measures_.weighted_counts = weighted_counts_ @@ -2487,10 +2493,10 @@ def weighted_counts_(self, request): return instance_mock(request, _WeightedCounts) -class Describe_MarginUnweightedBase: +class Test_MarginUnweightedBase: """Unit test suite for `cr.cube.matrix.measure._MarginUnweightedBase` object.""" - def it_provides_blocks_for_rows( + def test_it_provides_blocks_for_rows( self, request, is_defined_prop_, @@ -2511,7 +2517,7 @@ def it_provides_blocks_for_rows( assert actual[0].tolist() == [0, 2] assert actual[1].tolist() == [6] - def it_provides_blocks_for_columns( + def test_it_provides_blocks_for_columns( self, request, is_defined_prop_, @@ -2532,7 +2538,7 @@ def it_provides_blocks_for_columns( assert actual[0].tolist() == [0, 1] assert actual[1].tolist() == [4] - def but_blocks_raises_if_undefined(self, is_defined_prop_): + def test_but_blocks_raises_if_undefined(self, is_defined_prop_): is_defined_prop_.return_value = False margin_ = _MarginUnweightedBase(None, None, None, None) @@ -2541,7 +2547,7 @@ def but_blocks_raises_if_undefined(self, is_defined_prop_): assert str(e.value) == "Cannot calculate base across subvariables dimension." - def it_can_tell_if_it_is_defined(self, request): + def test_it_can_tell_if_it_is_defined(self, request): property_mock(request, _BaseMarginal, "_counts_are_defined") margin_unweighted_base = _MarginUnweightedBase(None, None, None, None) assert ( @@ -2571,10 +2577,10 @@ def second_order_measures_(self, request): return instance_mock(request, SecondOrderMeasures) -class Describe_MarginWeightedBase: +class Test_MarginWeightedBase: """Unit test suite for `cr.cube.matrix.measure._MarginWeightedBase` object.""" - def it_provides_blocks_for_rows( + def test_it_provides_blocks_for_rows( self, request, is_defined_prop_, @@ -2593,7 +2599,7 @@ def it_provides_blocks_for_rows( assert actual[0].tolist() == [0, 2] assert actual[1].tolist() == [6] - def it_provides_blocks_for_columns( + def test_it_provides_blocks_for_columns( self, request, is_defined_prop_, @@ -2614,7 +2620,7 @@ def it_provides_blocks_for_columns( assert actual[0].tolist() == [0, 1] assert actual[1].tolist() == [4] - def but_blocks_raises_if_undefined(self, is_defined_prop_): + def test_but_blocks_raises_if_undefined(self, is_defined_prop_): is_defined_prop_.return_value = False margin_ = _MarginWeightedBase(None, None, None, None) @@ -2633,13 +2639,15 @@ def but_blocks_raises_if_undefined(self, is_defined_prop_): (np.array([1, 2]), True), ), ) - def it_can_tell_if_it_is_defined(self, _base_values_prop_, base_values, expected): + def test_it_can_tell_if_it_is_defined( + self, _base_values_prop_, base_values, expected + ): _base_values_prop_.return_value = base_values table_weighted_base = _MarginWeightedBase(None, None, None, None) assert table_weighted_base.is_defined == expected - def it_provides_the_base_values_for_rows_to_help( + def test_it_provides_the_base_values_for_rows_to_help( self, weighted_cube_counts_, cube_measures_ ): weighted_cube_counts_.rows_base = [1, 2] @@ -2648,7 +2656,7 @@ def it_provides_the_base_values_for_rows_to_help( assert table_weighted_base._base_values == [1, 2] - def it_provides_the_base_values_for_columns_to_help( + def test_it_provides_the_base_values_for_columns_to_help( self, weighted_cube_counts_, cube_measures_ ): weighted_cube_counts_.columns_base = [1, 2] @@ -2693,10 +2701,10 @@ def weighted_cube_counts_(self, request): return instance_mock(request, _BaseCubeCounts) -class Describe_ScaleMean: +class Test_ScaleMean: """Unit test suite for `cr.cube.matrix.measure._ScaleMean` object.""" - def it_provides_blocks(self, request): + def test_it_provides_blocks(self, request): property_mock(request, _ScaleMean, "is_defined", return_value=True) property_mock( request, _ScaleMean, "_proportions", return_value=["prop1", "prop2"] @@ -2728,7 +2736,7 @@ def it_provides_blocks(self, request): ), ] - def but_blocks_raises_if_it_is_undefined(self, request): + def test_but_blocks_raises_if_it_is_undefined(self, request): property_mock(request, _ScaleMean, "is_defined", return_value=False) with pytest.raises(ValueError) as e: @@ -2742,14 +2750,14 @@ def but_blocks_raises_if_it_is_undefined(self, request): @pytest.mark.parametrize( "values, expected", ((np.array([0, 1]), True), (np.array([np.nan]), False)) ) - def it_can_tell_if_it_is_defined(self, request, values, expected): + def test_it_can_tell_if_it_is_defined(self, request, values, expected): property_mock( request, _ScaleMean, "_opposing_numeric_values", return_value=values ) mean = _ScaleMean(None, None, None, MO.ROWS) assert mean.is_defined == expected - def it_gets_the_right_proportions_for_rows(self, request): + def test_it_gets_the_right_proportions_for_rows(self, request): row_proportions_ = instance_mock( request, _RowProportions, blocks=[["a", "b"], ["c", "d"]] ) @@ -2761,7 +2769,7 @@ def it_gets_the_right_proportions_for_rows(self, request): assert mean._proportions == ["a", "c"] - def it_gets_the_right_counts_for_columns(self, request): + def test_it_gets_the_right_counts_for_columns(self, request): column_proportions_ = instance_mock( request, _ColumnProportions, blocks=[["a", "b"], ["c", "d"]] ) @@ -2783,15 +2791,15 @@ def it_gets_the_right_counts_for_columns(self, request): ([np.nan, np.nan, np.nan], [1.0, 2.0, 3.0], np.nan), ), ) - def it_calculates_weighted_mean(self, proportions, values, expected): + def test_it_calculates_weighted_mean(self, proportions, values, expected): mean = _ScaleMean._weighted_mean(np.array(proportions), np.array(values)) assert mean == pytest.approx(expected, nan_ok=True) -class Describe_ScaleMeanStddev: +class Test_ScaleMeanStddev: """Unit test suite for `cr.cube.matrix.measure._ScaleMeanStddev` object.""" - def it_provides_blocks(self, request, is_defined_prop_): + def test_it_provides_blocks(self, request, is_defined_prop_): is_defined_prop_.return_value = True _rows_weighted_mean_stddev_ = method_mock( request, _ScaleMeanStddev, "_rows_weighted_mean_stddev" @@ -2817,7 +2825,7 @@ def it_provides_blocks(self, request, is_defined_prop_): call("b", [1, 2], "d"), ] - def but_blocks_raises_if_undefined(self, is_defined_prop_): + def test_but_blocks_raises_if_undefined(self, is_defined_prop_): is_defined_prop_.return_value = False with pytest.raises(ValueError) as e: @@ -2829,7 +2837,7 @@ def but_blocks_raises_if_undefined(self, is_defined_prop_): + "are defined on opposing dimension." ) - def it_gets_the_right_scale_mean_for_columns(self, request): + def test_it_gets_the_right_scale_mean_for_columns(self, request): columns_scale_mean_ = instance_mock(request, _ScaleMean, blocks=["a", "b"]) second_order_measures_ = instance_mock( request, SecondOrderMeasures, columns_scale_mean=columns_scale_mean_ @@ -2839,7 +2847,7 @@ def it_gets_the_right_scale_mean_for_columns(self, request): assert stddev._scale_means == ["a", "b"] - def it_gets_the_right_scale_mean_for_rows(self, request): + def test_it_gets_the_right_scale_mean_for_rows(self, request): rows_scale_mean_ = instance_mock(request, _ScaleMean, blocks=["a", "b"]) second_order_measures_ = instance_mock( request, SecondOrderMeasures, rows_scale_mean=rows_scale_mean_ @@ -2872,7 +2880,9 @@ def it_gets_the_right_scale_mean_for_rows(self, request): ), ), ) - def it_can_calculate_stddev_for_rows(self, counts, values, scale_mean, expected): + def test_it_can_calculate_stddev_for_rows( + self, counts, values, scale_mean, expected + ): result = _ScaleMeanStddev._rows_weighted_mean_stddev(counts, values, scale_mean) assert result.tolist() == pytest.approx(expected, nan_ok=True) @@ -2900,7 +2910,9 @@ def it_can_calculate_stddev_for_rows(self, counts, values, scale_mean, expected) ), ), ) - def it_can_calculate_stddev_for_columns(self, counts, values, scale_mean, expected): + def test_it_can_calculate_stddev_for_columns( + self, counts, values, scale_mean, expected + ): result = _ScaleMeanStddev._columns_weighted_mean_stddev( counts, values, scale_mean ) @@ -2914,10 +2926,10 @@ def is_defined_prop_(self, request): return property_mock(request, _ScaleMeanStddev, "is_defined") -class Describe_ScaleMeanStderr: +class Test_ScaleMeanStderr: """Unit test suite for `cr.cube.matrix.measure._ScaleMeanStderr` object.""" - def it_provides_blocks( + def test_it_provides_blocks( self, is_defined_prop_, _margin_prop_, @@ -2937,7 +2949,7 @@ def it_provides_blocks( assert stderr[0].tolist() == [1.0, 0.75] assert stderr[1].tolist() == [0.8] - def but_it_raises_it_if_blocks_are_not_defined(self, is_defined_prop_): + def test_but_it_raises_it_if_blocks_are_not_defined(self, is_defined_prop_): is_defined_prop_.return_value = False with pytest.raises(ValueError) as e: @@ -2958,7 +2970,7 @@ def but_it_raises_it_if_blocks_are_not_defined(self, is_defined_prop_): (False, False, False), ), ) - def it_can_tell_if_it_is_defined( + def test_it_can_tell_if_it_is_defined( self, _margin_prop_, margin_, @@ -2976,19 +2988,19 @@ def it_can_tell_if_it_is_defined( assert stderr.is_defined == expected - def it_provides_the_margin_for_rows_to_help(self, second_order_measures_): + def test_it_provides_the_margin_for_rows_to_help(self, second_order_measures_): second_order_measures_.rows_weighted_base = "a" stderr = _ScaleMeanStderr(None, second_order_measures_, None, MO.ROWS) assert stderr._margin == "a" - def it_provides_the_margin_for_columns_to_help(self, second_order_measures_): + def test_it_provides_the_margin_for_columns_to_help(self, second_order_measures_): second_order_measures_.columns_weighted_base = "b" stderr = _ScaleMeanStderr(None, second_order_measures_, None, MO.COLUMNS) assert stderr._margin == "b" - def it_provides_the_scale_mean_stddev_for_rows_to_help( + def test_it_provides_the_scale_mean_stddev_for_rows_to_help( self, second_order_measures_ ): second_order_measures_.rows_scale_mean_stddev = "a" @@ -2996,7 +3008,7 @@ def it_provides_the_scale_mean_stddev_for_rows_to_help( assert stderr._scale_mean_stddev == "a" - def it_provides_the_scale_mean_stddev_for_columns_to_help( + def test_it_provides_the_scale_mean_stddev_for_columns_to_help( self, second_order_measures_ ): second_order_measures_.columns_scale_mean_stddev = "b" @@ -3031,10 +3043,10 @@ def second_order_measures_(self, request): return instance_mock(request, SecondOrderMeasures) -class Describe_ScaleMedian: +class Test_ScaleMedian: """Unit test suite for `cr.cube.matrix.measure._ScaleMedian` object.""" - def it_provides_blocks(self, request): + def test_it_provides_blocks(self, request): property_mock(request, _ScaleMedian, "is_defined", return_value=True) property_mock(request, _ScaleMedian, "_sorted_values") property_mock( @@ -3066,7 +3078,7 @@ def it_provides_blocks(self, request): ), ] - def but_blocks_raises_if_it_is_undefined(self, request): + def test_but_blocks_raises_if_it_is_undefined(self, request): property_mock(request, _ScaleMedian, "is_defined", return_value=False) with pytest.raises(ValueError) as e: @@ -3087,7 +3099,7 @@ def but_blocks_raises_if_it_is_undefined(self, request): ([25, 10, np.nan, 5, np.nan], [3, 1, 0]), ), ) - def it_gets_the_right_sort_order(self, request, values, expected): + def test_it_gets_the_right_sort_order(self, request, values, expected): property_mock( request, _ScaleMedian, @@ -3106,7 +3118,7 @@ def it_gets_the_right_sort_order(self, request, values, expected): ([25, 10, np.nan, 5, np.nan], [5, 10, 25]), ), ) - def it_sorts_the_values_to_help(self, request, values, expected): + def test_it_sorts_the_values_to_help(self, request, values, expected): property_mock( request, _ScaleMedian, @@ -3149,7 +3161,7 @@ def it_sorts_the_values_to_help(self, request, values, expected): ), ), ) - def it_sorts_the_counts_to_help( + def test_it_sorts_the_counts_to_help( self, request, orientation, sort_order, base_values, subtotals, expected ): property_mock( @@ -3180,7 +3192,7 @@ def it_sorts_the_counts_to_help( ([0.0, 0.0, 0.0], [10.0, 20.0, 30.0], np.nan), ), ) - def it_calculates_weighted_median(self, counts, values, expected): + def test_it_calculates_weighted_median(self, counts, values, expected): assert _ScaleMedian._weighted_median( np.array(counts), np.array(values) ) == pytest.approx(expected, nan_ok=True) @@ -3189,7 +3201,7 @@ def it_calculates_weighted_median(self, counts, values, expected): # === Scalars === -class Describe_TableBase: +class Test_TableBase: """Unit test suite for `cr.cube.matrix.measure._TableBase` object.""" @pytest.mark.parametrize( @@ -3199,19 +3211,19 @@ class Describe_TableBase: (1, True), ), ) - def it_knows_if_it_is_defined(self, cube_counts_, table_base, expected): + def test_it_knows_if_it_is_defined(self, cube_counts_, table_base, expected): cube_counts_.table_base = table_base assert _TableBase(None, None, None, cube_counts_).is_defined == expected - def it_provides_its_value(self, cube_counts_, is_defined_prop_): + def test_it_provides_its_value(self, cube_counts_, is_defined_prop_): is_defined_prop_.return_value = True cube_counts_.table_base = 2.0 table_margin = _TableBase(None, None, None, cube_counts_) assert table_margin.value == 2.0 - def but_it_raises_if_it_is_not_defined(self, is_defined_prop_): + def test_but_it_raises_if_it_is_not_defined(self, is_defined_prop_): is_defined_prop_.return_value = False with pytest.raises(ValueError) as e: @@ -3233,10 +3245,10 @@ def cube_counts_(self, request): return instance_mock(request, _BaseCubeCounts) -class Describe_TableBasesRange: +class Test_TableBasesRange: """Unit test suite for `cr.cube.matrix.measure._TableBasesRange` object.""" - def it_is_always_defined(self): + def test_it_is_always_defined(self): assert _TableBasesRange(None, None, None, None).is_defined @pytest.mark.parametrize( @@ -3246,7 +3258,7 @@ def it_is_always_defined(self): ([[0, 1, 2], [3, 4, 5]], [0, 5]), ), ) - def it_knows_its_values(self, request, bases, expected): + def test_it_knows_its_values(self, request, bases, expected): cube_counts_ = instance_mock(request, _BaseCubeCounts, table_bases=bases) range = _TableBasesRange(None, None, None, cube_counts_) diff --git a/tests/unit/matrix/test_subtotals.py b/tests/unit/matrix/test_subtotals.py index 87a0553a8..fe8c18e5d 100644 --- a/tests/unit/matrix/test_subtotals.py +++ b/tests/unit/matrix/test_subtotals.py @@ -18,10 +18,10 @@ from ...unitutil import ANY, initializer_mock, instance_mock, method_mock, property_mock -class Describe_BaseSubtotals: +class Test_BaseSubtotals: """Unit test suite for `cr.cube.matrix._BaseSubtotals` object.""" - def it_provides_a_blocks_interface_method(self, request, cube_counts_): + def test_it_provides_a_blocks_interface_method(self, request, cube_counts_): _init_ = initializer_mock(request, _BaseSubtotals) _blocks_ = property_mock( request, _BaseSubtotals, "_blocks", return_value=[[1, 2], [3, 4]] @@ -33,7 +33,7 @@ def it_provides_a_blocks_interface_method(self, request, cube_counts_): _blocks_.assert_called_once() assert blocks == [[1, 2], [3, 4]] - def it_can_compute_its_blocks(self, request): + def test_it_can_compute_its_blocks(self, request): property_mock(request, _BaseSubtotals, "_subtotal_columns") property_mock(request, _BaseSubtotals, "_subtotal_rows") property_mock(request, _BaseSubtotals, "_intersections") @@ -46,11 +46,11 @@ def it_can_compute_its_blocks(self, request): [base_subtotals._subtotal_rows, base_subtotals._intersections], ] - def it_provides_access_to_the_column_subtotals_to_help(self, dimension_): + def test_it_provides_access_to_the_column_subtotals_to_help(self, dimension_): subtotals = _BaseSubtotals(None, (None, dimension_)) assert subtotals._column_subtotals is dimension_.subtotals - def it_assembles_its_intersections_to_help( + def test_it_assembles_its_intersections_to_help( self, _intersection_, _column_subtotals_prop_, _row_subtotals_prop_ ): _intersection_.return_value = 10 @@ -69,15 +69,15 @@ def it_assembles_its_intersections_to_help( ).tolist() ) - def it_knows_how_many_columns_are_in_the_base_matrix_to_help(self): + def test_it_knows_how_many_columns_are_in_the_base_matrix_to_help(self): base_values = np.arange(12).reshape(3, 4) assert _BaseSubtotals(base_values, None)._ncols == 4 - def it_knows_how_many_rows_are_in_the_base_matrix_to_help(self): + def test_it_knows_how_many_rows_are_in_the_base_matrix_to_help(self): base_values = np.arange(12).reshape(3, 4) assert _BaseSubtotals(base_values, None)._nrows == 3 - def it_provides_access_to_the_row_subtotals_to_help(self, dimension_): + def test_it_provides_access_to_the_row_subtotals_to_help(self, dimension_): subtotals = _BaseSubtotals(None, (dimension_, None)) assert subtotals._row_subtotals is dimension_.subtotals @@ -88,7 +88,7 @@ def it_provides_access_to_the_row_subtotals_to_help(self, dimension_): (3, 2, np.array([[1, 1], [2, 2], [3, 3]])), ), ) - def it_assembles_its_subtotal_columns_to_help( + def test_it_assembles_its_subtotal_columns_to_help( self, _column_subtotals_prop_, _nrows_prop_, @@ -113,7 +113,7 @@ def it_assembles_its_subtotal_columns_to_help( (3, [1, 2], (2, 3), [[1, 2, 3], [1, 2, 3]]), ), ) - def it_assembles_its_subtotal_rows_to_help( + def test_it_assembles_its_subtotal_rows_to_help( self, _row_subtotals_prop_, _ncols_prop_, @@ -175,13 +175,13 @@ def _subtotal_row_(self, request): return method_mock(request, _BaseSubtotals, "_subtotal_row") -class DescribeNanSubtotals: +class TestNanSubtotals: """Unit test suite for `cr.cube.matrix.NanSubtotals` object.""" - def it_can_compute_a_intersection_cell_value_to_help(self): + def test_it_can_compute_a_intersection_cell_value_to_help(self): assert np.isnan(NanSubtotals(None, None)._intersection(None, None)) - def it_can_compute_a_subtotal_column_to_help(self, request): + def test_it_can_compute_a_subtotal_column_to_help(self, request): property_mock(request, NanSubtotals, "_nrows", return_value=3) subtotals = NanSubtotals(None, None) @@ -190,7 +190,7 @@ def it_can_compute_a_subtotal_column_to_help(self, request): np.array([np.nan] * 3), ) - def it_can_compute_a_subtotal_row_to_help(self, request): + def test_it_can_compute_a_subtotal_row_to_help(self, request): property_mock(request, NanSubtotals, "_ncols", return_value=4) subtotals = NanSubtotals(None, None) @@ -200,10 +200,10 @@ def it_can_compute_a_subtotal_row_to_help(self, request): ) -class DescribeNegativeTermSubtotals: +class TestNegativeTermSubtotals: """Unit test suite for `cr.cube.matrix.NegativeTermSubtotals` object.""" - def it_provides_blocks_to_help(self, request): + def test_it_provides_blocks_to_help(self, request): base_values = np.arange(12).reshape(3, 4) subtotal_cols = np.array([[12], [13], [14]]) subtotal_rows = np.array([[15, 16, 17, 18]]) @@ -245,7 +245,7 @@ def it_provides_blocks_to_help(self, request): ([0, 1], [2], [1, 2], [0], np.nan), ), ) - def it_can_compute_intersection_to_help( + def test_it_can_compute_intersection_to_help( self, request, col_add_idxs, @@ -273,14 +273,14 @@ def it_can_compute_intersection_to_help( expected_value, nan_ok=True ) - def it_can_compute_subtotal_column_to_help(self, subtotal_): + def test_it_can_compute_subtotal_column_to_help(self, subtotal_): base_values = np.arange(12).reshape(3, 4) subtotal_.subtrahend_idxs = [1, 2] subtotals = NegativeTermSubtotals(base_values, None) assert subtotals._subtotal_column(subtotal_).tolist() == [3, 11, 19] - def it_can_compute_subtotal_row_to_help(self, subtotal_): + def test_it_can_compute_subtotal_row_to_help(self, subtotal_): base_values = np.arange(12).reshape(3, 4) subtotal_.subtrahend_idxs = [1, 2] subtotals = NegativeTermSubtotals(base_values, None) @@ -294,7 +294,7 @@ def subtotal_(self, request): return instance_mock(request, _Subtotal) -class DescribePositiveTermSubtotals: +class TestPositiveTermSubtotals: """Unit test suite for `cr.cube.matrix.PositiveTermSubtotals` object.""" @pytest.mark.parametrize( @@ -306,7 +306,7 @@ class DescribePositiveTermSubtotals: ([0, 1], [2], [1, 2], [0], np.nan), ), ) - def it_can_compute_intersection_to_help( + def test_it_can_compute_intersection_to_help( self, request, col_add_idxs, @@ -334,14 +334,14 @@ def it_can_compute_intersection_to_help( subtotals._intersection(row_subtotal_, col_subtotal_), expected_value ) - def it_can_compute_subtotal_column_to_help(self, subtotal_): + def test_it_can_compute_subtotal_column_to_help(self, subtotal_): base_values = np.arange(12).reshape(3, 4) subtotal_.addend_idxs = [1, 2] subtotals = PositiveTermSubtotals(base_values, None) assert subtotals._subtotal_column(subtotal_).tolist() == [3, 11, 19] - def it_can_compute_subtotal_row_to_help(self, subtotal_): + def test_it_can_compute_subtotal_row_to_help(self, subtotal_): base_values = np.arange(12).reshape(3, 4) subtotal_.addend_idxs = [1, 2] subtotals = PositiveTermSubtotals(base_values, None) @@ -355,10 +355,10 @@ def subtotal_(self, request): return instance_mock(request, _Subtotal) -class DescribeSumSubtotals: +class TestSumSubtotals: """Unit test suite for `cr.cube.matrix.SumSubtotals` object.""" - def it_provides_an_intersections_interface_method( + def test_it_provides_an_intersections_interface_method( self, request, dimensions_, _init_ ): base_values = [[1, 5], [8, 0]] @@ -374,7 +374,7 @@ def it_provides_an_intersections_interface_method( _init_.assert_called_once_with(ANY, [[1, 5], [8, 0]], dimensions_, False, False) assert intersections.tolist() == [[1, 2], [3, 4]] - def it_provides_a_subtotal_columns_interface_method( + def test_it_provides_a_subtotal_columns_interface_method( self, request, dimensions_, _init_ ): base_values = [[0, 4], [7, 9]] @@ -390,7 +390,7 @@ def it_provides_a_subtotal_columns_interface_method( _init_.assert_called_once_with(ANY, [[0, 4], [7, 9]], dimensions_, False, False) assert subtotal_columns.tolist() == [[1, 2], [3, 4]] - def it_provides_a_subtotal_rows_interface_method( + def test_it_provides_a_subtotal_rows_interface_method( self, request, dimensions_, _init_ ): base_values = [[4, 1], [3, 5]] @@ -428,7 +428,7 @@ def it_provides_a_subtotal_rows_interface_method( ([1, 2], [], [0, 1], [2, 3], True, False, np.nan), ), ) - def it_can_compute_a_subtotal_intersection_value( + def test_it_can_compute_a_subtotal_intersection_value( self, request, row_add_idxs, @@ -469,7 +469,7 @@ def it_can_compute_a_subtotal_intersection_value( ([1], [3], True, [np.nan, np.nan, np.nan]), ), ) - def it_can_compute_a_subtotal_column_to_help( + def test_it_can_compute_a_subtotal_column_to_help( self, subtotal_, addend_idxs, subtrahend_idxs, diff_cols_nan, expected_value ): subtotal_.addend_idxs = addend_idxs @@ -492,7 +492,7 @@ def it_can_compute_a_subtotal_column_to_help( ([0], [2], True, [np.nan, np.nan, np.nan, np.nan]), ), ) - def it_can_compute_a_subtotal_row_to_help( + def test_it_can_compute_a_subtotal_row_to_help( self, subtotal_, addend_idxs, subtrahend_idxs, diff_rows_nan, expected_value ): subtotal_.addend_idxs = addend_idxs diff --git a/tests/unit/stripe/test_assembler.py b/tests/unit/stripe/test_assembler.py index 4c256bd51..07d95608b 100644 --- a/tests/unit/stripe/test_assembler.py +++ b/tests/unit/stripe/test_assembler.py @@ -36,7 +36,7 @@ from ...unitutil import class_mock, instance_mock, method_mock, property_mock -class DescribeStripeAssembler: +class TestStripeAssembler: """Unit test suite for `cr.cube.stripe.assembler.StripeAssembler` object.""" @pytest.mark.parametrize( @@ -54,7 +54,7 @@ class DescribeStripeAssembler: ("weighted_counts", _WeightedCounts), ), ) - def it_assembles_various_measures( + def test_it_assembles_various_measures( self, request, _measures_prop_, @@ -78,19 +78,19 @@ def it_assembles_various_measures( _assemble_vector_.assert_called_once_with(strand, ("A", "B")) assert value.tolist() == [1, 2, 3, 4, 5] - def it_knows_the_inserted_row_idxs(self, _row_order_prop_): + def test_it_knows_the_inserted_row_idxs(self, _row_order_prop_): _row_order_prop_.return_value = np.array([-1, 0, 3, -2, 4, 1]) strand = _Strand(None, None, None, None, None, None) assert strand.inserted_row_idxs == (0, 3) - def it_knows_the_row_count(self, _row_order_prop_): + def test_it_knows_the_row_count(self, _row_order_prop_): _row_order_prop_.return_value = np.array([1, 2, 3, 4, 5]) strand = _Strand(None, None, None, None, None, None) assert strand.row_count == 5 - def it_knows_the_row_labels(self, rows_dimension_, _row_order_prop_): + def test_it_knows_the_row_labels(self, rows_dimension_, _row_order_prop_): rows_dimension_.element_labels = ("baz", "foo", "bar") rows_dimension_.subtotal_labels = ("bing", "bada") _row_order_prop_.return_value = np.array([1, 2, 0, -1, -2]) @@ -110,7 +110,7 @@ def it_knows_the_row_labels(self, rows_dimension_, _row_order_prop_): ((-1, -2, 2, 1, 0), ("STF2", "STF1", "#f00ba5", "#111111", "#000000")), ), ) - def it_knows_the_rows_dimension_fills( + def test_it_knows_the_rows_dimension_fills( self, request, rows_dimension_, _row_order_prop_, order, expected_fills ): element_fills = ("#000000", "#111111", "#f00ba5") @@ -129,7 +129,7 @@ def it_knows_the_rows_dimension_fills( assert strand.rows_dimension_fills == expected_fills - def it_knows_the_scale_mean(self, _measures_prop_, measures_, scaled_counts_): + def test_it_knows_the_scale_mean(self, _measures_prop_, measures_, scaled_counts_): scaled_counts_.scale_mean = 3 measures_.scaled_counts = scaled_counts_ _measures_prop_.return_value = measures_ @@ -137,7 +137,9 @@ def it_knows_the_scale_mean(self, _measures_prop_, measures_, scaled_counts_): assert strand.scale_mean == 3 - def it_knows_the_scale_median(self, _measures_prop_, measures_, scaled_counts_): + def test_it_knows_the_scale_median( + self, _measures_prop_, measures_, scaled_counts_ + ): scaled_counts_.scale_median = 4 measures_.scaled_counts = scaled_counts_ _measures_prop_.return_value = measures_ @@ -145,7 +147,9 @@ def it_knows_the_scale_median(self, _measures_prop_, measures_, scaled_counts_): assert strand.scale_median == 4 - def it_knows_the_scale_stddev(self, _measures_prop_, measures_, scaled_counts_): + def test_it_knows_the_scale_stddev( + self, _measures_prop_, measures_, scaled_counts_ + ): scaled_counts_.scale_stddev = 5 measures_.scaled_counts = scaled_counts_ _measures_prop_.return_value = measures_ @@ -153,7 +157,9 @@ def it_knows_the_scale_stddev(self, _measures_prop_, measures_, scaled_counts_): assert strand.scale_stddev == 5 - def it_knows_the_scale_stderr(self, _measures_prop_, measures_, scaled_counts_): + def test_it_knows_the_scale_stderr( + self, _measures_prop_, measures_, scaled_counts_ + ): scaled_counts_.scale_stderr = 6 measures_.scaled_counts = scaled_counts_ _measures_prop_.return_value = measures_ @@ -161,7 +167,7 @@ def it_knows_the_scale_stderr(self, _measures_prop_, measures_, scaled_counts_): assert strand.scale_stderr == 6 - def it_knows_the_table_base_range(self, request, _measures_prop_, measures_): + def test_it_knows_the_table_base_range(self, request, _measures_prop_, measures_): measures_.unweighted_bases = instance_mock( request, _UnweightedBases, table_base_range=np.array([50, 100]) ) @@ -170,7 +176,7 @@ def it_knows_the_table_base_range(self, request, _measures_prop_, measures_): assert strand.table_base_range.tolist() == [50, 100] - def it_knows_the_table_margin_range(self, request, _measures_prop_, measures_): + def test_it_knows_the_table_margin_range(self, request, _measures_prop_, measures_): measures_.weighted_bases = instance_mock( request, _WeightedBases, table_margin_range=np.array([50.5, 100.1]) ) @@ -179,7 +185,7 @@ def it_knows_the_table_margin_range(self, request, _measures_prop_, measures_): assert strand.table_margin_range.tolist() == [50.5, 100.1] - def it_can_assemble_a_vector_to_help(self, _row_order_prop_): + def test_it_can_assemble_a_vector_to_help(self, _row_order_prop_): base_values = np.array([1, 2, 3, 4]) subtotal_values = (3, 5, 7) blocks = (base_values, subtotal_values) @@ -188,7 +194,7 @@ def it_can_assemble_a_vector_to_help(self, _row_order_prop_): assert strand._assemble_vector(blocks).tolist() == [3, 2, 1, 5, 4, 3, 7] - def it_constructs_its_measures_collaborator_object_to_help( + def test_it_constructs_its_measures_collaborator_object_to_help( self, request, cube_, rows_dimension_, measures_ ): StripeMeasures_ = class_mock( @@ -215,7 +221,7 @@ def it_constructs_its_measures_collaborator_object_to_help( (ORDER_FORMAT.BOGUS_IDS, ("ins_1", 1, "ins_2", 2, "ins_3", 3)), ), ) - def it_knows_the_row_order_to_help( + def test_it_knows_the_row_order_to_help( self, request, rows_dimension_, _measures_prop_, measures_, format, row_order ): _measures_prop_.return_value = measures_ @@ -266,7 +272,7 @@ def scaled_counts_(self, request): return instance_mock(request, _ScaledCounts) -class Describe_BaseOrderHelper: +class Test_BaseOrderHelper: """Unit-test suite for `cr.cube.stripe.assembler._BaseOrderHelper` object.""" @pytest.mark.parametrize( @@ -278,7 +284,7 @@ class Describe_BaseOrderHelper: (CM.PAYLOAD_ORDER, _OrderHelper), ), ) - def it_dispatches_to_the_right_order_helper( + def test_it_dispatches_to_the_right_order_helper( self, request, measures_, collation_method, HelperCls ): rows_dimension_ = instance_mock( @@ -310,7 +316,7 @@ def it_dispatches_to_the_right_order_helper( "pruning_base, expected_value", (([1, 1, 1], ()), ([1, 0, 1], (1,)), ([0, 0, 0], (0, 1, 2))), ) - def it_knows_the_empty_row_idxs_to_help( + def test_it_knows_the_empty_row_idxs_to_help( self, measures_, pruning_base, expected_value ): measures_.pruning_base = np.array(pruning_base) @@ -325,7 +331,7 @@ def measures_(self, request): return instance_mock(request, StripeMeasures) -class Describe_OrderHelper: +class Test_OrderHelper: """Unit test suite for `cr.cube.stripe.assembler._OrderHelper` object.""" @pytest.mark.parametrize( @@ -335,7 +341,7 @@ class Describe_OrderHelper: (CM.EXPLICIT_ORDER, "ExplicitOrderCollator"), ), ) - def it_computes_the_order_of_a_rows_dimension_to_help( + def test_it_computes_the_order_of_a_rows_dimension_to_help( self, request, collation_method, collator_class_name ): rows_dimension_ = instance_mock( @@ -360,10 +366,10 @@ def it_computes_the_order_of_a_rows_dimension_to_help( assert display_order == (1, -2, 3, 5, -1) -class Describe_BaseSortByValueHelper: +class Test_BaseSortByValueHelper: """Unit test suite for `cr.cube.strip.assembler._BaseSortByValueHelper`.""" - def it_computes_the_display_order_to_help( + def test_it_computes_the_display_order_to_help( self, dimension_, _element_values_prop_, @@ -386,7 +392,7 @@ def it_computes_the_display_order_to_help( ) assert order == (-1, -2, 0, 2, 1) - def but_it_falls_back_to_payload_order_on_value_error( + def test_but_it_falls_back_to_payload_order_on_value_error( self, request, dimension_, @@ -435,16 +441,16 @@ def _subtotal_values_prop_(self, request): return property_mock(request, _BaseSortByValueHelper, "_subtotal_values") -class Describe_SortByLabelHelper: +class Test_SortByLabelHelper: """Unit test suite for `cr.cube.strip.assembler._SortByLabelHelper`.""" - def it_extracts_the_element_values_to_help(self, dimension_): + def test_it_extracts_the_element_values_to_help(self, dimension_): dimension_.element_labels = ["b", "a", "c"] order_helper = _SortByLabelHelper(dimension_, None) assert order_helper._element_values.tolist() == ["b", "a", "c"] - def it_extracts_the_subtotal_values_to_help(self, dimension_): + def test_it_extracts_the_subtotal_values_to_help(self, dimension_): dimension_.subtotal_labels = ["b", "a", "c"] order_helper = _SortByLabelHelper(dimension_, None) @@ -457,10 +463,10 @@ def dimension_(self, request): return instance_mock(request, Dimension) -class Describe_SortByMeasureHelper: +class Test_SortByMeasureHelper: """Unit test suite for `cr.cube.strip.assembler._SortByMeasureHelper`.""" - def it_extracts_the_element_values_to_help(self, _measure_prop_, measure_): + def test_it_extracts_the_element_values_to_help(self, _measure_prop_, measure_): _measure_prop_.return_value = measure_ measure_.blocks = [np.arange(5), None] order_helper = _SortByMeasureHelper(None, None) @@ -484,7 +490,7 @@ def it_extracts_the_element_values_to_help(self, _measure_prop_, measure_): ("sum", "sums"), ), ) - def it_retrieves_the_right_measure_object_to_help( + def test_it_retrieves_the_right_measure_object_to_help( self, request, _order_spec_prop_, @@ -501,7 +507,7 @@ def it_retrieves_the_right_measure_object_to_help( assert order_helper._measure is measure_ - def but_it_raises_when_the_sort_measure_is_not_supported( + def test_but_it_raises_when_the_sort_measure_is_not_supported( self, _order_spec_prop_, order_spec_ ): _order_spec_prop_.return_value = order_spec_ @@ -513,7 +519,7 @@ def but_it_raises_when_the_sort_measure_is_not_supported( assert str(e.value) == "sort-by-value for measure 'foobar' is not yet supported" - def it_extracts_the_subtotal_values_to_help(self, _measure_prop_, measure_): + def test_it_extracts_the_subtotal_values_to_help(self, _measure_prop_, measure_): _measure_prop_.return_value = measure_ measure_.blocks = [None, np.arange(3)] order_helper = _SortByMeasureHelper(None, None) diff --git a/tests/unit/stripe/test_cubemeasure.py b/tests/unit/stripe/test_cubemeasure.py index 4354d42f8..3c14d26ac 100644 --- a/tests/unit/stripe/test_cubemeasure.py +++ b/tests/unit/stripe/test_cubemeasure.py @@ -28,10 +28,10 @@ from ...unitutil import class_mock, instance_mock, property_mock -class DescribeCubeMeasures: +class TestCubeMeasures: """Unit-test suite for `cr.cube.stripe.cubemeasure.CubeMeasures` object.""" - def it_provides_access_to_the_cube_means_object( + def test_it_provides_access_to_the_cube_means_object( self, request, cube_, rows_dimension_ ): cube_means_ = instance_mock(request, _BaseCubeMeans) @@ -46,7 +46,7 @@ def it_provides_access_to_the_cube_means_object( _BaseCubeMeans_.factory.assert_called_once_with(cube_, rows_dimension_) assert cube_means is cube_means_ - def it_provides_access_to_the_cube_median_object( + def test_it_provides_access_to_the_cube_median_object( self, request, cube_, rows_dimension_ ): cube_medians_ = instance_mock(request, _BaseCubeMedians) @@ -61,7 +61,7 @@ def it_provides_access_to_the_cube_median_object( _BaseCubeMedian_.factory.assert_called_once_with(cube_, rows_dimension_) assert cube_medians is cube_medians_ - def it_provides_access_to_the_cube_sum_object( + def test_it_provides_access_to_the_cube_sum_object( self, request, cube_, rows_dimension_ ): cube_sum_ = instance_mock(request, _BaseCubeSums) @@ -81,7 +81,7 @@ def it_provides_access_to_the_cube_sum_object( ("counts", "valid", "valid"), ), ) - def it_provides_access_to_the_unweighted_cube_counts_object( + def test_it_provides_access_to_the_unweighted_cube_counts_object( self, cube_, cube_counts_, @@ -110,7 +110,7 @@ def it_provides_access_to_the_unweighted_cube_counts_object( ("counts", "valid", "valid"), ), ) - def it_provides_access_to_the_weighted_cube_counts_object( + def test_it_provides_access_to_the_weighted_cube_counts_object( self, cube_, cube_counts_, @@ -154,7 +154,7 @@ def rows_dimension_(self, request): # === COUNTS === -class Describe_BaseCubeCounts: +class Test_BaseCubeCounts: """Unit test suite for `cr.cube.matrix.cubemeasure._BaseUnweightedCubeCounts`.""" @pytest.mark.parametrize( @@ -184,7 +184,7 @@ class Describe_BaseCubeCounts: ), ), ) - def it_provides_a_factory_for_constructing_unweighted_cube_count_objects( + def test_it_provides_a_factory_for_constructing_unweighted_cube_count_objects( self, request, ca_as_0th, @@ -211,10 +211,10 @@ def it_provides_a_factory_for_constructing_unweighted_cube_count_objects( assert unweighted_cube_counts is cube_counts_ -class Describe_CatCubeCounts: +class Test_CatCubeCounts: """Unit-test suite for `cr.cube.stripe.cubemeasure._CatCubeCounts`.""" - def it_knows_its_bases(self, request, raw_counts): + def test_it_knows_its_bases(self, request, raw_counts): property_mock( request, _CatCubeCounts, @@ -224,15 +224,15 @@ def it_knows_its_bases(self, request, raw_counts): cube_counts = _CatCubeCounts(None, raw_counts) assert cube_counts.bases.tolist() == [42, 42, 42] - def it_knows_its_counts(self, raw_counts): + def test_it_knows_its_counts(self, raw_counts): cube_counts = _CatCubeCounts(None, raw_counts) assert cube_counts.counts.tolist() == [1, 2, 3] - def it_knows_its_pruning_base(self, raw_counts): + def test_it_knows_its_pruning_base(self, raw_counts): cube_counts = _CatCubeCounts(None, raw_counts) assert cube_counts.pruning_base.tolist() == [1, 2, 3] - def it_knows_its_table_base(self, raw_counts): + def test_it_knows_its_table_base(self, raw_counts): cube_counts = _CatCubeCounts(None, raw_counts) assert cube_counts.table_base == 6 @@ -244,22 +244,22 @@ def raw_counts(self): return np.array([1, 2, 3]) -class Describe_MrCubeCounts: +class Test_MrCubeCounts: """Unit-test suite for `cr.cube.stripe.cubemeasure._MrCubeCounts`.""" - def it_knows_its_bases(self, raw_counts): + def test_it_knows_its_bases(self, raw_counts): cube_counts = _MrCubeCounts(None, raw_counts) assert cube_counts.bases.tolist() == [3, 7, 11] - def it_knows_its_counts(self, raw_counts): + def test_it_knows_its_counts(self, raw_counts): cube_counts = _MrCubeCounts(None, raw_counts) assert cube_counts.counts.tolist() == [1, 3, 5] - def it_knows_its_pruning_base(self, raw_counts): + def test_it_knows_its_pruning_base(self, raw_counts): cube_counts = _MrCubeCounts(None, raw_counts) assert cube_counts.pruning_base.tolist() == [3, 7, 11] - def it_knows_its_table_base_is_None(self, raw_counts): + def test_it_knows_its_table_base_is_None(self, raw_counts): cube_counts = _MrCubeCounts(None, raw_counts) assert cube_counts.table_base is None @@ -271,22 +271,22 @@ def raw_counts(self): return np.array([[1, 2], [3, 4], [5, 6]]) -class Describe_NumArrCubeCounts: +class Test_NumArrCubeCounts: """Unit-test suite for `cr.cube.stripe.cubemeasure._NumArrCubeCounts`.""" - def it_knows_its_bases(self, raw_counts): + def test_it_knows_its_bases(self, raw_counts): cube_counts = _NumArrCubeCounts(None, raw_counts) assert cube_counts.bases.tolist() == [1, 2, 3] - def it_knows_its_counts(self, raw_counts): + def test_it_knows_its_counts(self, raw_counts): cube_counts = _NumArrCubeCounts(None, raw_counts) assert cube_counts.counts.tolist() == [1, 2, 3] - def it_knows_its_pruning_base(self, raw_counts): + def test_it_knows_its_pruning_base(self, raw_counts): cube_counts = _NumArrCubeCounts(None, raw_counts) assert cube_counts.pruning_base.tolist() == [1, 2, 3] - def it_knows_its_table_base_is_None(self, raw_counts): + def test_it_knows_its_table_base_is_None(self, raw_counts): cube_counts = _NumArrCubeCounts(None, raw_counts) assert cube_counts.table_base is None @@ -301,7 +301,7 @@ def raw_counts(self): # === MEANS === -class Describe_BaseCubeMeans: +class Test_BaseCubeMeans: """Unit test suite for `cr.cube.matrix.cubemeasure._BaseCubeMeans`.""" @pytest.mark.parametrize( @@ -311,7 +311,7 @@ class Describe_BaseCubeMeans: (DT.MR, _MrCubeMeans, [[1, 6], [2, 5], [3, 4]]), ), ) - def it_provides_a_factory_for_constructing_cube_means_objects( + def test_it_provides_a_factory_for_constructing_cube_means_objects( self, request, rows_dimension_type, CubeMeansCls, means ): cube_ = instance_mock(request, Cube, means=means) @@ -331,14 +331,14 @@ def it_provides_a_factory_for_constructing_cube_means_objects( assert cube_means is cube_means_ -class Describe_CatCubeMeans: +class Test_CatCubeMeans: """Unit-test suite for `cr.cube.stripe.cubemeasure._CatCubeMeans`.""" - def it_knows_its_means(self): + def test_it_knows_its_means(self): cube_means = _CatCubeMeans(None, np.array([1.1, 2.2, 3.3])) assert cube_means.means == pytest.approx([1.1, 2.2, 3.3]) - def but_it_raises_value_error_when_the_cube_result_does_not_contain_means( + def test_but_it_raises_value_error_when_the_cube_result_does_not_contain_means( self, request ): cube_ = instance_mock(request, Cube) @@ -349,14 +349,14 @@ def but_it_raises_value_error_when_the_cube_result_does_not_contain_means( assert str(e.value) == "cube-result does not contain cube-means measure" -class Describe_MrCubeMeans: +class Test_MrCubeMeans: """Unit-test suite for `cr.cube.stripe.cubemeasure._MrCubeMeans`.""" - def it_knows_its_means(self): + def test_it_knows_its_means(self): cube_means = _MrCubeMeans(None, np.array([[1.1, 2.2], [3.3, 4.4], [5.5, 6.6]])) assert cube_means.means == pytest.approx([1.1, 3.3, 5.5]) - def but_it_raises_value_error_when_the_cube_result_does_not_contain_means( + def test_but_it_raises_value_error_when_the_cube_result_does_not_contain_means( self, request ): cube_ = instance_mock(request, Cube) @@ -370,7 +370,7 @@ def but_it_raises_value_error_when_the_cube_result_does_not_contain_means( # === MEDIANS === -class Describe_BaseCubeMedian: +class Test_BaseCubeMedian: """Unit test suite for `cr.cube.matrix.cubemeasure._BaseCubeMedian`.""" @pytest.mark.parametrize( @@ -380,7 +380,7 @@ class Describe_BaseCubeMedian: (DT.MR, _MrCubeMedians, [[1, 6], [2, 5], [3, 4]]), ), ) - def it_provides_a_factory_for_constructing_cube_medians_objects( + def test_it_provides_a_factory_for_constructing_cube_medians_objects( self, request, rows_dimension_type, CubeMedianCls, medians ): cube_ = instance_mock(request, Cube, medians=medians) @@ -400,14 +400,14 @@ def it_provides_a_factory_for_constructing_cube_medians_objects( assert cube_medians is cube_medians_ -class Describe_CatCubeMedians: +class Test_CatCubeMedians: """Unit-test suite for `cr.cube.stripe.cubemeasure._CatCubeMedians`.""" - def it_knows_its_medians(self): + def test_it_knows_its_medians(self): cube_medians = _CatCubeMedians(None, np.array([1.1, 2.2, 3.3])) assert cube_medians.medians == pytest.approx([1.1, 2.2, 3.3]) - def but_it_raises_value_error_when_the_cube_result_does_not_contain_medians( + def test_but_it_raises_value_error_when_the_cube_result_does_not_contain_medians( self, request ): cube_ = instance_mock(request, Cube) @@ -418,16 +418,16 @@ def but_it_raises_value_error_when_the_cube_result_does_not_contain_medians( assert str(e.value) == "cube-result does not contain cube-median measure" -class Describe_MrCubeMedians: +class Test_MrCubeMedians: """Unit-test suite for `cr.cube.stripe.cubemeasure._MrCubeMedians`.""" - def it_knows_its_medians(self): + def test_it_knows_its_medians(self): cube_medians = _MrCubeMedians( None, np.array([[1.1, 2.2], [3.3, 4.4], [5.5, 6.6]]) ) assert cube_medians.medians == pytest.approx([1.1, 3.3, 5.5]) - def but_it_raises_value_error_when_the_cube_result_does_not_contain_medians( + def test_but_it_raises_value_error_when_the_cube_result_does_not_contain_medians( self, request ): cube_ = instance_mock(request, Cube) @@ -441,7 +441,7 @@ def but_it_raises_value_error_when_the_cube_result_does_not_contain_medians( # === SUM === -class Describe_BaseCubeSums: +class Test_BaseCubeSums: """Unit test suite for `cr.cube.matrix.cubemeasure._BaseCubeSums`.""" @pytest.mark.parametrize( @@ -451,7 +451,7 @@ class Describe_BaseCubeSums: (DT.MR, _MrCubeSums, [[1, 6], [2, 5], [3, 4]]), ), ) - def it_provides_a_factory_for_constructing_cube_sums_objects( + def test_it_provides_a_factory_for_constructing_cube_sums_objects( self, request, rows_dimension_type, CubeSumCls, sums ): cube_ = instance_mock(request, Cube, sums=sums) @@ -471,14 +471,14 @@ def it_provides_a_factory_for_constructing_cube_sums_objects( assert cube_sums is cube_sums_ -class Describe_CatCubeSums: +class Test_CatCubeSums: """Unit-test suite for `cr.cube.stripe.cubemeasure._CatCubeSum`.""" - def it_knows_its_sum(self): + def test_it_knows_its_sum(self): cube_sum = _CatCubeSums(None, np.array([1, 2, 3])) assert cube_sum.sums == pytest.approx([1, 2, 3]) - def but_it_raises_value_error_when_the_cube_result_does_not_contain_sums( + def test_but_it_raises_value_error_when_the_cube_result_does_not_contain_sums( self, request ): cube_ = instance_mock(request, Cube) @@ -489,14 +489,14 @@ def but_it_raises_value_error_when_the_cube_result_does_not_contain_sums( assert str(e.value) == "cube-result does not contain cube-sum measure" -class Describe_MrCubeSums: +class Test_MrCubeSums: """Unit-test suite for `cr.cube.stripe.cubemeasure._MrCubeSum`.""" - def it_knows_its_sum(self): + def test_it_knows_its_sum(self): cube_sum = _MrCubeSums(None, np.array([[1, 2], [3, 4], [5, 6]])) assert cube_sum.sums == pytest.approx([1, 3, 5]) - def but_it_raises_value_error_when_the_cube_result_does_not_contain_sum( + def test_but_it_raises_value_error_when_the_cube_result_does_not_contain_sum( self, request ): cube_ = instance_mock(request, Cube) diff --git a/tests/unit/stripe/test_insertion.py b/tests/unit/stripe/test_insertion.py index 0d66cc714..8fb19d71a 100644 --- a/tests/unit/stripe/test_insertion.py +++ b/tests/unit/stripe/test_insertion.py @@ -17,10 +17,12 @@ from ...unitutil import ANY, initializer_mock, instance_mock, property_mock -class Describe_BaseSubtotals: +class Test_BaseSubtotals: """Unit test suite for `cr.cube.stripe._BaseSubtotals` object.""" - def it_provides_a_subtotal_values_interface_method(self, request, rows_dimension_): + def test_it_provides_a_subtotal_values_interface_method( + self, request, rows_dimension_ + ): base_values = [1, 2, 3] _init_ = initializer_mock(request, _BaseSubtotals) property_mock( @@ -32,7 +34,9 @@ def it_provides_a_subtotal_values_interface_method(self, request, rows_dimension _init_.assert_called_once_with(ANY, base_values, rows_dimension_) assert subtotal_values.tolist() == [3, 5] - def it_provides_access_to_the_row_subtotal_objects(self, request, rows_dimension_): + def test_it_provides_access_to_the_row_subtotal_objects( + self, request, rows_dimension_ + ): row_subtotals_ = tuple(instance_mock(request, _Subtotal) for _ in range(3)) rows_dimension_.subtotals = row_subtotals_ subtotals = _BaseSubtotals(None, rows_dimension_) @@ -46,10 +50,10 @@ def rows_dimension_(self, request): return instance_mock(request, Dimension) -class DescribeNanSubtotals: +class TestNanSubtotals: """Unit test suite for `cr.cube.stripe.NanSubtotals` object.""" - def it_computes_the_subtotal_values(self, request): + def test_it_computes_the_subtotal_values(self, request): property_mock( request, NanSubtotals, @@ -63,7 +67,7 @@ def it_computes_the_subtotal_values(self, request): ) -class DescribeNegativeTermSubtotals: +class TestNegativeTermSubtotals: """Unit test suite for `cr.cube.matrix.NegativeTermSubtotals` object.""" @pytest.mark.parametrize( @@ -74,7 +78,7 @@ class DescribeNegativeTermSubtotals: ([], [1], 2), ), ) - def it_computes_the_subtotal_values( + def test_it_computes_the_subtotal_values( self, request, addend_idxs, subtrahend_idxs, expected ): property_mock( @@ -97,7 +101,7 @@ def it_computes_the_subtotal_values( np.testing.assert_equal(subtotal_value, expected) -class DescribePositiveTermSubtotals: +class TestPositiveTermSubtotals: """Unit test suite for `cr.cube.matrix.PositiveTermSubtotals` object.""" @pytest.mark.parametrize( @@ -108,7 +112,7 @@ class DescribePositiveTermSubtotals: ([], [1], 0), ), ) - def it_computes_the_subtotal_values( + def test_it_computes_the_subtotal_values( self, request, addend_idxs, subtrahend_idxs, expected ): property_mock( @@ -131,7 +135,7 @@ def it_computes_the_subtotal_values( np.testing.assert_equal(subtotal_value, expected) -class DescribeSumSubtotals: +class TestSumSubtotals: """Unit test suite for `cr.cube.matrix.SumSubtotals` object.""" @pytest.mark.parametrize( @@ -142,7 +146,7 @@ class DescribeSumSubtotals: ([], [1], -2), ), ) - def it_calculates_subtotal_value_correctly( + def test_it_calculates_subtotal_value_correctly( self, request, addend_idxs, subtrahend_idxs, expected ): property_mock( diff --git a/tests/unit/stripe/test_measure.py b/tests/unit/stripe/test_measure.py index 84e697096..bef1fb6ee 100644 --- a/tests/unit/stripe/test_measure.py +++ b/tests/unit/stripe/test_measure.py @@ -38,7 +38,7 @@ from ...unitutil import class_mock, instance_mock, method_mock, property_mock -class DescribeStripeMeasures: +class TestStripeMeasures: """Unit test suite for `cr.cube.stripe.measure.StripeMeasures` object.""" @pytest.mark.parametrize( @@ -60,7 +60,7 @@ class DescribeStripeMeasures: ("weighted_counts", _WeightedCounts), ), ) - def it_provides_access_to_various_measure_objects( + def test_it_provides_access_to_various_measure_objects( self, request, _cube_measures_prop_, @@ -83,7 +83,7 @@ def it_provides_access_to_various_measure_objects( MeasureCls_.assert_called_once_with(rows_dimension_, measures, cube_measures_) assert measure is measure_ - def it_provides_access_to_the_pruning_base( + def test_it_provides_access_to_the_pruning_base( self, request, _cube_measures_prop_, cube_measures_ ): unweighted_cube_counts_ = instance_mock( @@ -95,7 +95,7 @@ def it_provides_access_to_the_pruning_base( assert measures.pruning_base.tolist() == [0, 2, 7] - def it_provides_access_to_the_cube_measures_to_help( + def test_it_provides_access_to_the_cube_measures_to_help( self, request, cube_, rows_dimension_, cube_measures_ ): CubeMeasures_ = class_mock( @@ -129,10 +129,10 @@ def rows_dimension_(self, request): return instance_mock(request, Dimension) -class Describe_BaseSecondOrderMeasure: +class Test_BaseSecondOrderMeasure: """Unit test suite for `cr.cube.stripe.measure._BaseSecondOrderMeasure` object.""" - def it_gathers_the_blocks_for_the_measure(self, request): + def test_it_gathers_the_blocks_for_the_measure(self, request): property_mock(request, _BaseSecondOrderMeasure, "base_values", return_value="A") property_mock( request, _BaseSecondOrderMeasure, "subtotal_values", return_value="B" @@ -141,7 +141,7 @@ def it_gathers_the_blocks_for_the_measure(self, request): assert measure.blocks == ("A", "B") - def it_provides_access_to_the_unweighted_cube_counts_object_to_help( + def test_it_provides_access_to_the_unweighted_cube_counts_object_to_help( self, request, cube_measures_ ): unweighted_cube_counts_ = instance_mock(request, _BaseCubeCounts) @@ -150,7 +150,7 @@ def it_provides_access_to_the_unweighted_cube_counts_object_to_help( assert measure._unweighted_cube_counts is unweighted_cube_counts_ - def it_provides_access_to_the_weighted_cube_counts_object_to_help( + def test_it_provides_access_to_the_weighted_cube_counts_object_to_help( self, request, cube_measures_ ): weighted_cube_counts_ = instance_mock(request, _BaseCubeCounts) @@ -170,10 +170,10 @@ def rows_dimension_(self, request): return instance_mock(request, Dimension) -class Describe_Means: +class Test_Means: """Unit test suite for `cr.cube.stripe.measure._Means` object.""" - def it_computes_its_base_values_to_help(self, request): + def test_it_computes_its_base_values_to_help(self, request): cube_means_ = instance_mock( request, _BaseCubeMeans, means=np.array([1.1, 2.2, 3.3]) ) @@ -182,7 +182,7 @@ def it_computes_its_base_values_to_help(self, request): assert means.base_values == pytest.approx([1.1, 2.2, 3.3]) - def it_computes_its_subtotal_values_to_help(self, request): + def test_it_computes_its_subtotal_values_to_help(self, request): property_mock(request, _Means, "base_values", return_value=[1.1, 2.2, 3.3]) rows_dimension_ = instance_mock(request, Dimension) NanSubtotals_ = class_mock(request, "cr.cube.stripe.measure.NanSubtotals") @@ -197,10 +197,10 @@ def it_computes_its_subtotal_values_to_help(self, request): assert subtotal_values == pytest.approx([np.nan, np.nan], nan_ok=True) -class Describe_Median: +class Test_Median: """Unit test suite for `cr.cube.stripe.measure._Median` object.""" - def it_computes_its_base_values_to_help(self, request): + def test_it_computes_its_base_values_to_help(self, request): cube_medians_ = instance_mock( request, _BaseCubeMedians, medians=np.array([1.1, 2.2, 3.3]) ) @@ -211,7 +211,7 @@ def it_computes_its_base_values_to_help(self, request): assert medians.base_values == pytest.approx([1.1, 2.2, 3.3]) - def it_computes_its_subtotal_values_to_help(self, request): + def test_it_computes_its_subtotal_values_to_help(self, request): property_mock(request, _Medians, "base_values", return_value=[1.1, 2.2, 3.3]) rows_dimension_ = instance_mock(request, Dimension) NanSubtotals_ = class_mock(request, "cr.cube.stripe.measure.NanSubtotals") @@ -226,7 +226,7 @@ def it_computes_its_subtotal_values_to_help(self, request): assert subtotal_values == pytest.approx([np.nan, np.nan], nan_ok=True) -class Describe_PopulationProportions: +class Test_PopulationProportions: """Unit test suite for `cr.cube.stripe.measure._PopulationProportions` object.""" @pytest.mark.parametrize( @@ -237,7 +237,7 @@ class Describe_PopulationProportions: (DT.CAT_DATE, [0, 1], [1, 1]), ), ) - def it_computes_its_base_values_to_help( + def test_it_computes_its_base_values_to_help( self, dimension_type, base_values, @@ -265,7 +265,7 @@ def it_computes_its_base_values_to_help( (DT.CAT_DATE, [], []), ), ) - def it_computes_its_subtotal_values_to_help( + def test_it_computes_its_subtotal_values_to_help( self, dimension_type, subtotal_values, @@ -298,7 +298,7 @@ def table_proportions_(self, request): return instance_mock(request, _TableProportions) -class Describe_PopulationProportionStderrs: +class Test_PopulationProportionStderrs: """Unit test suite for `cr.cube.stripe.measure._PopulationProportionStderrs`.""" @pytest.mark.parametrize( @@ -309,7 +309,7 @@ class Describe_PopulationProportionStderrs: (DT.CAT_DATE, [0, 1], [0, 0]), ), ) - def it_computes_its_base_values_to_help( + def test_it_computes_its_base_values_to_help( self, dimension_type, base_values, @@ -337,7 +337,7 @@ def it_computes_its_base_values_to_help( (DT.CAT_DATE, [], []), ), ) - def it_computes_its_subtotal_values_to_help( + def test_it_computes_its_subtotal_values_to_help( self, dimension_type, subtotal_values, @@ -370,7 +370,7 @@ def table_proportion_stderrs_(self, request): return instance_mock(request, _TableProportionStderrs) -class Describe_ScaledCounts: +class Test_ScaledCounts: """Unit test suite for `cr.cube.stripe.measure._ScaledCounts` object.""" @pytest.mark.parametrize( @@ -381,7 +381,7 @@ class Describe_ScaledCounts: (np.array([1, 2, 3]), 100, 4), ), ) - def it_knows_the_scale_mean( + def test_it_knows_the_scale_mean( self, _numeric_values_prop_, numeric_values, @@ -404,7 +404,7 @@ def it_knows_the_scale_mean( (np.array([3, 1, 2]), np.array([300, 100, 200]), 2.5), ), ) - def it_knows_the_scale_median( + def test_it_knows_the_scale_median( self, _numeric_values_prop_, numeric_values, @@ -427,7 +427,7 @@ def it_knows_the_scale_median( (np.array([1, 2, 3]), 4.0, 2.0), ), ) - def it_knows_the_scale_stddev( + def test_it_knows_the_scale_stddev( self, _numeric_values_prop_, numeric_values, @@ -448,7 +448,7 @@ def it_knows_the_scale_stddev( (np.array([1, 2, 3]), 4.0, 100.0, 0.2), ), ) - def it_knows_the_scale_stderr( + def test_it_knows_the_scale_stderr( self, _numeric_values_prop_, numeric_values, @@ -465,13 +465,15 @@ def it_knows_the_scale_stderr( assert scaled_counts.scale_stderr == expected_value - def it_knows_which_elements_have_a_numeric_values_to_help(self, rows_dimension_): + def test_it_knows_which_elements_have_a_numeric_values_to_help( + self, rows_dimension_ + ): rows_dimension_.numeric_values = (1, np.nan, 3) scaled_counts = _ScaledCounts(rows_dimension_, None, None) assert scaled_counts._has_numeric_value.tolist() == [True, False, True] - def it_gathers_the_numeric_values_to_help( + def test_it_gathers_the_numeric_values_to_help( self, rows_dimension_, _has_numeric_value_prop_ ): rows_dimension_.numeric_values = (1, np.nan, 3) @@ -480,7 +482,7 @@ def it_gathers_the_numeric_values_to_help( assert scaled_counts._numeric_values.tolist() == [1, 3] - def it_computes_the_scale_variance_to_help( + def test_it_computes_the_scale_variance_to_help( self, request, _weighted_counts_prop_, @@ -495,7 +497,7 @@ def it_computes_the_scale_variance_to_help( assert scaled_counts._scale_variance == pytest.approx(0.5555556) - def it_computes_the_total_scaled_count_to_help( + def test_it_computes_the_total_scaled_count_to_help( self, _weighted_counts_prop_, _numeric_values_prop_ ): _weighted_counts_prop_.return_value = np.array([10, 20, 30, 40]) @@ -505,13 +507,13 @@ def it_computes_the_total_scaled_count_to_help( # --- 10 + 40 + 90 + 160 = 300 --- assert scaled_counts._total_scaled_count == 300 - def it_computes_the_total_weighted_count_to_help(self, _weighted_counts_prop_): + def test_it_computes_the_total_weighted_count_to_help(self, _weighted_counts_prop_): _weighted_counts_prop_.return_value = np.array([10, 20, 30, 40]) scaled_counts = _ScaledCounts(None, None, None) assert scaled_counts._total_weighted_count == 100 - def it_retrives_the_weighted_counts_to_help( + def test_it_retrives_the_weighted_counts_to_help( self, request, _has_numeric_value_prop_ ): weighted_cube_counts_ = instance_mock( @@ -559,10 +561,10 @@ def _weighted_counts_prop_(self, request): return property_mock(request, _ScaledCounts, "_weighted_counts") -class Describe_TableProportionStddevs: +class Test_TableProportionStddevs: """Unit test suite for `cr.cube.stripe.measure._TableProportionStddevs` object.""" - def it_computes_its_base_values_to_help( + def test_it_computes_its_base_values_to_help( self, measures_, table_proportion_variances_ ): table_proportion_variances_.base_values = np.array([0.04, 0.09, 0.16]) @@ -571,7 +573,7 @@ def it_computes_its_base_values_to_help( assert table_proportion_stddevs.base_values == pytest.approx([0.2, 0.3, 0.4]) - def it_computes_its_subtotal_values_to_help( + def test_it_computes_its_subtotal_values_to_help( self, measures_, table_proportion_variances_ ): table_proportion_variances_.subtotal_values = np.array([0.25, 0.36]) @@ -591,10 +593,10 @@ def table_proportion_variances_(self, request): return instance_mock(request, _TableProportionVariances) -class Describe_TableProportionStderrs: +class Test_TableProportionStderrs: """Unit test suite for `cr.cube.stripe.measure._TableProportionStderrs` object.""" - def it_computes_its_base_values_to_help( + def test_it_computes_its_base_values_to_help( self, measures_, table_proportion_variances_, weighted_bases_ ): table_proportion_variances_.base_values = np.array([0.4, 1.8, 4.8]) @@ -605,7 +607,7 @@ def it_computes_its_base_values_to_help( assert table_proportion_stderrs.base_values == pytest.approx([0.2, 0.3, 0.4]) - def it_computes_its_subtotal_values_to_help( + def test_it_computes_its_subtotal_values_to_help( self, measures_, table_proportion_variances_, weighted_bases_ ): table_proportion_variances_.subtotal_values = np.array([4.8, 12.5]) @@ -631,10 +633,10 @@ def weighted_bases_(self, request): return instance_mock(request, _WeightedBases) -class Describe_TableProportionVariances: +class Test_TableProportionVariances: """Unit test suite for `cr.cube.stripe.measure._TableProportionVariances` object.""" - def it_computes_its_base_values_to_help(self, measures_, table_proportions_): + def test_it_computes_its_base_values_to_help(self, measures_, table_proportions_): table_proportions_.base_values = np.array([0.2, 0.3, 0.5]) measures_.table_proportions = table_proportions_ table_proportion_variances = _TableProportionVariances(None, measures_, None) @@ -643,7 +645,7 @@ def it_computes_its_base_values_to_help(self, measures_, table_proportions_): [0.16, 0.21, 0.25] ) - def it_computes_its_subtotal_values_to_help( + def test_it_computes_its_subtotal_values_to_help( self, request, measures_, table_proportions_ ): rows_dimension_ = instance_mock(request, Dimension) @@ -694,7 +696,7 @@ def table_proportions_(self, request): return instance_mock(request, _TableProportions) -class Describe_TableProportions: +class Test_TableProportions: """Unit test suite for `cr.cube.stripe.measure._TableProportions` object.""" @pytest.mark.parametrize( @@ -705,7 +707,7 @@ class Describe_TableProportions: (0, [np.inf, np.inf]), ), ) - def it_computes_its_base_values_to_help( + def test_it_computes_its_base_values_to_help( self, measures_, weighted_counts_, @@ -729,7 +731,7 @@ def it_computes_its_base_values_to_help( (42.42, [0.2310231, 0.1791608]), ), ) - def it_computes_its_subtotal_values_to_help( + def test_it_computes_its_subtotal_values_to_help( self, _dimension, measures_, @@ -772,10 +774,10 @@ def _dimension(self, request): return instance_mock(request, Dimension) -class Describe_UnweightedBases: +class Test_UnweightedBases: """Unit test suite for `cr.cube.stripe.measure._UnweightedBases` object.""" - def it_knows_its_base_values( + def test_it_knows_its_base_values( self, _unweighted_cube_counts_prop_, unweighted_cube_counts_ ): _unweighted_cube_counts_prop_.return_value = unweighted_cube_counts_ @@ -788,7 +790,7 @@ def it_knows_its_base_values( "subtotal_values, expected_value", ((np.array([]), []), (np.array([5, 3]), [42, 42])), ) - def it_knows_its_subtotal_values( + def test_it_knows_its_subtotal_values( self, request, _unweighted_cube_counts_prop_, subtotal_values, expected_value ): rows_dimension_ = instance_mock(request, Dimension) @@ -807,7 +809,7 @@ def it_knows_its_subtotal_values( ) assert subtotal_values.tolist() == expected_value - def it_knows_its_table_base_range( + def test_it_knows_its_table_base_range( self, _unweighted_cube_counts_prop_, unweighted_cube_counts_ ): _unweighted_cube_counts_prop_.return_value = unweighted_cube_counts_ @@ -827,10 +829,10 @@ def _unweighted_cube_counts_prop_(self, request): return property_mock(request, _UnweightedBases, "_unweighted_cube_counts") -class Describe_UnweightedCounts: +class Test_UnweightedCounts: """Unit test suite for `cr.cube.stripe.measure._UnweightedCounts` object.""" - def it_knows_its_base_values( + def test_it_knows_its_base_values( self, _unweighted_cube_counts_prop_, unweighted_cube_counts_ ): _unweighted_cube_counts_prop_.return_value = unweighted_cube_counts_ @@ -839,7 +841,7 @@ def it_knows_its_base_values( assert unweighted_counts.base_values.tolist() == [1, 2, 3] - def it_knows_its_subtotal_values(self, request): + def test_it_knows_its_subtotal_values(self, request): rows_dimension_ = instance_mock(request, Dimension) property_mock(request, _UnweightedCounts, "base_values", return_value=[1, 2, 3]) SumSubtotals_ = class_mock(request, "cr.cube.stripe.measure.SumSubtotals") @@ -864,10 +866,10 @@ def _unweighted_cube_counts_prop_(self, request): return property_mock(request, _UnweightedCounts, "_unweighted_cube_counts") -class Describe_WeightedBases: +class Test_WeightedBases: """Unit test suite for `cr.cube.stripe.measure._WeightedBases` object.""" - def it_knows_its_base_values( + def test_it_knows_its_base_values( self, _weighted_cube_counts_prop_, weighted_cube_counts_ ): _weighted_cube_counts_prop_.return_value = weighted_cube_counts_ @@ -880,7 +882,7 @@ def it_knows_its_base_values( "subtotal_values, expected_value", ((np.array([]), []), (np.array([5.5, 3.3]), [42.24, 42.24])), ) - def it_knows_its_subtotal_values( + def test_it_knows_its_subtotal_values( self, request, _weighted_cube_counts_prop_, @@ -905,7 +907,7 @@ def it_knows_its_subtotal_values( ) assert subtotal_values.tolist() == expected_value - def it_knows_its_table_margin_range( + def test_it_knows_its_table_margin_range( self, _weighted_cube_counts_prop_, weighted_cube_counts_ ): _weighted_cube_counts_prop_.return_value = weighted_cube_counts_ @@ -925,10 +927,10 @@ def _weighted_cube_counts_prop_(self, request): return property_mock(request, _WeightedBases, "_weighted_cube_counts") -class Describe_WeightedCounts: +class Test_WeightedCounts: """Unit test suite for `cr.cube.stripe.measure._WeightedCounts` object.""" - def it_computes_its_base_values_to_help( + def test_it_computes_its_base_values_to_help( self, _weighted_cube_counts_prop_, weighted_cube_counts_ ): _weighted_cube_counts_prop_.return_value = weighted_cube_counts_ @@ -937,7 +939,7 @@ def it_computes_its_base_values_to_help( assert weighted_counts.base_values.tolist() == [1, 2, 3] - def it_computes_its_subtotal_values_to_help(self, request): + def test_it_computes_its_subtotal_values_to_help(self, request): rows_dimension_ = instance_mock(request, Dimension) property_mock( request, _WeightedCounts, "base_values", return_value=[1.1, 2.2, 3.3] diff --git a/tests/unit/test_collator.py b/tests/unit/test_collator.py index f599a5454..523565143 100644 --- a/tests/unit/test_collator.py +++ b/tests/unit/test_collator.py @@ -34,10 +34,10 @@ ) -class Describe_BaseCollator: +class Test_BaseCollator: """Unit-test suite for `cr.cube.collator._BaseCollator` object.""" - def it_provides_access_to_the_dimension_element_ids_to_help(self, dimension_): + def test_it_provides_access_to_the_dimension_element_ids_to_help(self, dimension_): dimension_.element_ids = (42, 24, 1, 6) assert _BaseCollator(dimension_, None)._element_ids == (42, 24, 1, 6) @@ -52,7 +52,7 @@ def it_provides_access_to_the_dimension_element_ids_to_help(self, dimension_): ((1, 2, 3), True, (4, 5, 6), (1, 2, 3, 4, 5, 6)), ), ) - def it_knows_the_hidden_idxs_to_help( + def test_it_knows_the_hidden_idxs_to_help( self, dimension_, empty_idxs, prune, hidden_idxs, expected_value ): dimension_.hidden_idxs = hidden_idxs @@ -61,15 +61,15 @@ def it_knows_the_hidden_idxs_to_help( assert collator._hidden_idxs == frozenset(expected_value) - def it_provides_access_to_the_order_spec_to_help(self, request, dimension_): + def test_it_provides_access_to_the_order_spec_to_help(self, request, dimension_): order_spec_ = instance_mock(request, _OrderSpec) dimension_.order_spec = order_spec_ assert _BaseCollator(dimension_, None)._order_spec is order_spec_ - def it_provides_access_to_the_dimension_subtotals_to_help(self, dimension_): + def test_it_provides_access_to_the_dimension_subtotals_to_help(self, dimension_): assert _BaseCollator(dimension_, None)._subtotals is dimension_.subtotals - def it_provides_access_to_subtotal_bogus_ids(self, request, dimension_): + def test_it_provides_access_to_subtotal_bogus_ids(self, request, dimension_): _Subtotals_ = instance_mock(request, _Subtotals) _Subtotals_.bogus_ids = ("i1", "i2") dimension_.subtotals = _Subtotals_ @@ -82,10 +82,10 @@ def dimension_(self, request): return instance_mock(request, Dimension) -class Describe_BaseAnchoredCollator: +class Test_BaseAnchoredCollator: """Unit-test suite for `cr.cube.collator._BaseAnchoredCollator` object.""" - def it_provides_an_interface_classmethod(self, request, dimension_): + def test_it_provides_an_interface_classmethod(self, request, dimension_): _init_ = initializer_mock(request, _BaseAnchoredCollator) _display_order_ = property_mock( request, _BaseAnchoredCollator, "_display_order" @@ -132,7 +132,7 @@ def it_provides_an_interface_classmethod(self, request, dimension_): ), ), ) - def it_computes_the_display_order_to_help( + def test_it_computes_the_display_order_to_help( self, request, base_order, @@ -179,7 +179,7 @@ def it_computes_the_display_order_to_help( (((0, 2, 18), (1, 0, 12), (2, 1, 5)), ((0, 0, 2), (1, 0, 0), (2, 0, 1))), ), ) - def it_computes_the_base_element_orderings_to_help( + def test_it_computes_the_base_element_orderings_to_help( self, request, element_order_descriptors, expected_value ): property_mock( @@ -192,11 +192,11 @@ def it_computes_the_base_element_orderings_to_help( assert collator._base_element_orderings == expected_value - def it_has_empty_derived_element_orderings(self): + def test_it_has_empty_derived_element_orderings(self): collator = _BaseAnchoredCollator(None, None) assert collator._derived_element_orderings == tuple() - def it_raises_on_element_order_descriptors_access(self): + def test_it_raises_on_element_order_descriptors_access(self): """Error message identifies the non-implementing subclass.""" with pytest.raises(NotImplementedError) as e: _BaseAnchoredCollator(None, None)._element_order_descriptors @@ -215,7 +215,7 @@ def it_raises_on_element_order_descriptors_access(self): (((0, 2, 18), (1, 0, 12), (2, 1, 5)), {18: 0, 12: 1, 5: 2}), ), ) - def it_maps_the_element_ids_to_their_position_to_help( + def test_it_maps_the_element_ids_to_their_position_to_help( self, request, element_order_descriptors, expected_value ): property_mock( @@ -242,7 +242,7 @@ def it_maps_the_element_ids_to_their_position_to_help( ), ), ) - def it_computes_the_insertion_orderings_to_help( + def test_it_computes_the_insertion_orderings_to_help( self, request, insertion_positions, expected_value ): subtotals_ = tuple( @@ -277,7 +277,7 @@ def it_computes_the_insertion_orderings_to_help( (3, (2, 1)), ), ) - def it_can_compute_the_insertion_position_for_a_subtotal_to_help( + def test_it_can_compute_the_insertion_position_for_a_subtotal_to_help( self, request, anchor, expected_value ): property_mock( @@ -298,7 +298,7 @@ def dimension_(self, request): return instance_mock(request, Dimension) -class DescribeExplicitOrderCollator: +class TestExplicitOrderCollator: """Unit-test suite for `cr.cube.collator.ExplicitOrderCollator` object.""" @pytest.mark.parametrize( @@ -320,7 +320,7 @@ class DescribeExplicitOrderCollator: ), ), ) - def it_computes_the_derived_element_orderings_to_help( + def test_it_computes_the_derived_element_orderings_to_help( self, request, ids, are_derived, element_positions, expected_value ): derived_elements_ = tuple( @@ -355,7 +355,7 @@ def it_computes_the_derived_element_orderings_to_help( (2, None, (sys.maxsize, 0)), ), ) - def it_computes_the_derived_element_position_to_help( + def test_it_computes_the_derived_element_position_to_help( self, request, element_id, anchor, expected_value ): element_ = instance_mock(request, Element, anchor=anchor) @@ -409,7 +409,7 @@ def it_computes_the_derived_element_position_to_help( ), ), ) - def it_computes_the_element_order_descriptors_to_help( + def test_it_computes_the_element_order_descriptors_to_help( self, request, element_ids, element_id_order, expected_value ): valid_elements_ = [ @@ -429,7 +429,7 @@ def it_computes_the_element_order_descriptors_to_help( assert collator._element_order_descriptors == expected_value -class DescribePayloadOrderCollator: +class TestPayloadOrderCollator: """Unit-test suite for `cr.cube.collator.PayloadOrderCollator` object.""" @pytest.mark.parametrize( @@ -443,7 +443,7 @@ class DescribePayloadOrderCollator: ((47, 103, 18), ((0, 0, 47), (1, 1, 103), (2, 2, 18))), ), ) - def it_computes_the_element_order_descriptors_to_help( + def test_it_computes_the_element_order_descriptors_to_help( self, request, element_ids, expected_value ): property_mock( @@ -454,7 +454,7 @@ def it_computes_the_element_order_descriptors_to_help( assert collator._element_order_descriptors == expected_value -class DescribeSortByValueCollator: +class TestSortByValueCollator: """Unit-test suite for `cr.cube.collator.SortByValueCollator` object. SortByValueCollator computes element ordering for sort-by-value order transforms. It @@ -463,7 +463,7 @@ class DescribeSortByValueCollator: or a marginal. """ - def it_provides_an_interface_classmethod(self, request): + def test_it_provides_an_interface_classmethod(self, request): dimension_ = instance_mock(request, Dimension) _init_ = initializer_mock(request, SortByValueCollator) property_mock( @@ -494,7 +494,7 @@ def it_provides_an_interface_classmethod(self, request): ) assert display_order == (-3, -1, -2, 1, 0, 2, 3) - def it_computes_the_display_order_to_help( + def test_it_computes_the_display_order_to_help( self, request, _top_fixed_idxs_prop_, _bottom_fixed_idxs_prop_ ): property_mock( @@ -532,7 +532,7 @@ def it_computes_the_display_order_to_help( ((), (), True, (8.0, np.nan, 2.0, np.nan), (0, 2, 1, 3)), ), ) - def it_computes_the_sorted_body_idxs_to_help( + def test_it_computes_the_sorted_body_idxs_to_help( self, _top_fixed_idxs_prop_, _bottom_fixed_idxs_prop_, @@ -553,7 +553,7 @@ def it_computes_the_sorted_body_idxs_to_help( assert collator._body_idxs == expected_value - def it_computes_the_bottom_exclusion_idxs_to_help( + def test_it_computes_the_bottom_exclusion_idxs_to_help( self, _iter_fixed_idxs_, _order_spec_prop_, order_spec_ ): _iter_fixed_idxs_.return_value = (n for n in (4, 0, 5, 2)) @@ -575,7 +575,7 @@ def it_computes_the_bottom_exclusion_idxs_to_help( (True, (-3, -1, -2), ()), ), ) - def it_computes_the_bottom_subtotal_idxs_to_help( + def test_it_computes_the_bottom_subtotal_idxs_to_help( self, _descending_prop_, _subtotal_idxs_prop_, @@ -593,7 +593,7 @@ def it_computes_the_bottom_subtotal_idxs_to_help( "fixed_element_ids, expected_value", (((), ()), ((1, 3), (0, 2)), ((1, 3, 7), (0, 2)), ((4, 2), (3, 1))), ) - def it_can_iterate_the_fixed_idxs_to_help( + def test_it_can_iterate_the_fixed_idxs_to_help( self, request, fixed_element_ids, expected_value ): property_mock( @@ -610,7 +610,7 @@ def it_can_iterate_the_fixed_idxs_to_help( (False, False), ), ) - def it_knows_whether_the_sort_direction_is_descending_to_help( + def test_it_knows_whether_the_sort_direction_is_descending_to_help( self, _order_spec_prop_, order_spec_, descending, expected_value ): _order_spec_prop_.return_value = order_spec_ @@ -623,7 +623,7 @@ def it_knows_whether_the_sort_direction_is_descending_to_help( "value, expected", ((0, False), (1.1, False), ("a", False), (np.nan, True)), ) - def it_can_compute_is_nan_to_help(self, value, expected): + def test_it_can_compute_is_nan_to_help(self, value, expected): assert SortByValueCollator._is_nan(value) == expected @pytest.mark.parametrize( @@ -637,7 +637,7 @@ def it_can_compute_is_nan_to_help(self, value, expected): ((1, np.nan, 2, np.nan, 3), False, (-5, -3, -1, -4, -2)), ), ) - def it_computes_the_subtotal_idxs_to_help( + def test_it_computes_the_subtotal_idxs_to_help( self, _descending_prop_, descending, subtotal_values, expected_value ): _descending_prop_.return_value = descending @@ -645,7 +645,7 @@ def it_computes_the_subtotal_idxs_to_help( assert collator._subtotal_idxs == expected_value - def it_computes_the_top_fixed_idxs_to_help( + def test_it_computes_the_top_fixed_idxs_to_help( self, _order_spec_prop_, order_spec_, _iter_fixed_idxs_ ): _order_spec_prop_.return_value = order_spec_ @@ -662,7 +662,7 @@ def it_computes_the_top_fixed_idxs_to_help( "subtotal_idxs, descending, expected_value", (((-3, -1, -2), True, (-3, -1, -2)), ((-1, -2, -3), False, ())), ) - def it_computes_the_top_subtotal_idxs_to_help( + def test_it_computes_the_top_subtotal_idxs_to_help( self, _subtotal_idxs_prop_, subtotal_idxs, diff --git a/tests/unit/test_cube.py b/tests/unit/test_cube.py index 891dc6608..01832cbed 100644 --- a/tests/unit/test_cube.py +++ b/tests/unit/test_cube.py @@ -19,10 +19,10 @@ from ..unitutil import call, class_mock, instance_mock, property_mock -class DescribeCubeSet: +class TestCubeSet: """Unit-test suite for `cr.cube.cube.CubeSet` object.""" - def it_knows_its_availabe_measures(self, cube_, _cubes_prop_): + def test_it_knows_its_availabe_measures(self, cube_, _cubes_prop_): cube_.available_measures = {"mean", "sum"} _cubes_prop_.return_value = (cube_,) cube_set = CubeSet(None, None, None, None) @@ -33,7 +33,7 @@ def it_knows_its_availabe_measures(self, cube_, _cubes_prop_): "available_measures, expected_value", (({M.MEAN, M.COUNT}, True), ({M.OVERLAP, M.COUNT}, False)), ) - def it_knows_if_it_has_numeric_measures( + def test_it_knows_if_it_has_numeric_measures( self, request, available_measures, expected_value ): property_mock( @@ -42,7 +42,7 @@ def it_knows_if_it_has_numeric_measures( cube_set = CubeSet(None, None, None, None) assert cube_set.has_numeric_measures is expected_value - def but_it_includes_availabe_measures_from_all_cubes_in_cube_set( + def test_but_it_includes_availabe_measures_from_all_cubes_in_cube_set( self, request, _cubes_prop_ ): _cubes_prop_.return_value = tuple( @@ -69,7 +69,7 @@ def but_it_includes_availabe_measures_from_all_cubes_in_cube_set( (((DT.DATETIME, DT.DATETIME), (DT.DATETIME, DT.MR_CAT)), False), ), ) - def it_knows_whether_it_can_show_pairwise( + def test_it_knows_whether_it_can_show_pairwise( self, request, cubes_dimtypes, expected_value, _cubes_prop_ ): _cubes_prop_.return_value = tuple( @@ -84,7 +84,7 @@ def it_knows_whether_it_can_show_pairwise( assert can_show_pairwise is expected_value - def it_knows_its_description(self, _cubes_prop_, cube_): + def test_it_knows_its_description(self, _cubes_prop_, cube_): cube_.description = "Are you male or female?" _cubes_prop_.return_value = (cube_,) cube_set = CubeSet(None, None, None, None) @@ -96,7 +96,7 @@ def it_knows_its_description(self, _cubes_prop_, cube_): @pytest.mark.parametrize( ("first_cube_has_w_counts", "expected_value"), ((True, True), (False, False)) ) - def it_knows_whether_it_has_weighted_counts( + def test_it_knows_whether_it_has_weighted_counts( self, first_cube_has_w_counts, expected_value, _cubes_prop_, cube_ ): cube_.has_weighted_counts = first_cube_has_w_counts @@ -108,7 +108,7 @@ def it_knows_whether_it_has_weighted_counts( assert has_weighted_counts == expected_value @pytest.mark.parametrize(("ncubes", "expected_value"), ((2, True), (1, False))) - def it_knows_when_it_is_ca_as_0th( + def test_it_knows_when_it_is_ca_as_0th( self, ncubes, expected_value, _cubes_prop_, cube_ ): cubes_ = (cube_,) * ncubes @@ -123,7 +123,7 @@ def it_knows_when_it_is_ca_as_0th( @pytest.mark.parametrize( ("first_cube_missing_count", "expected_value"), ((34, 34), (0, 0)) ) - def it_knows_its_missing_count( + def test_it_knows_its_missing_count( self, first_cube_missing_count, expected_value, _cubes_prop_, cube_ ): cube_.missing = first_cube_missing_count @@ -134,7 +134,7 @@ def it_knows_its_missing_count( assert missing_count == expected_value - def it_knows_its_name(self, _cubes_prop_, cube_): + def test_it_knows_its_name(self, _cubes_prop_, cube_): cube_.name = "Beverage" _cubes_prop_.return_value = (cube_,) cube_set = CubeSet(None, None, None, None) @@ -153,7 +153,7 @@ def it_knows_its_name(self, _cubes_prop_, cube_): ((_Nub,), ((_Nub,),)), ), ) - def it_provides_access_to_the_partition_sets( + def test_it_provides_access_to_the_partition_sets( self, cube_partitions, expected_value, _cubes_prop_, cube_ ): cube_.partitions = cube_partitions @@ -168,7 +168,7 @@ def it_provides_access_to_the_partition_sets( ("population_fraction", "expected_value"), ((1.0, 1.0), (0.54, 0.54), (np.nan, np.nan)), ) - def it_has_proper_population_fraction( + def test_it_has_proper_population_fraction( self, population_fraction, expected_value, cube_, _cubes_prop_ ): cube_.population_fraction = population_fraction @@ -179,7 +179,7 @@ def it_has_proper_population_fraction( np.testing.assert_almost_equal(cubeset_population_fraction, expected_value) - def it_constructs_its_sequence_of_cube_objects_to_help( + def test_it_constructs_its_sequence_of_cube_objects_to_help( self, request, Cube_, _is_numeric_measure_prop_ ): cubes_ = tuple(instance_mock(request, Cube) for _ in range(4)) @@ -221,7 +221,7 @@ def it_constructs_its_sequence_of_cube_objects_to_help( ] assert cubes == cubes_[:3] - def but_it_inflates_the_cubes_in_special_case_of_numeric_mean_payload( + def test_but_it_inflates_the_cubes_in_special_case_of_numeric_mean_payload( self, request, Cube_, cube_, _is_numeric_measure_prop_ ): cubes_ = tuple(instance_mock(request, Cube) for _ in range(4)) @@ -264,7 +264,9 @@ def but_it_inflates_the_cubes_in_special_case_of_numeric_mean_payload( assert cube_.inflate.call_args_list == [call(), call(), call()] assert cubes == cubes_[:3] - def it_constructs_its_sequence_of_augmented_cube_objects_to_help(self, request): + def test_it_constructs_its_sequence_of_augmented_cube_objects_to_help( + self, request + ): cube_set = CubeSet( cube_responses=[ { @@ -380,7 +382,7 @@ def it_constructs_its_sequence_of_augmented_cube_objects_to_help(self, request): ("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_measure_to_help( + def test_it_knows_whether_it_is_numeric_measure_to_help( self, _is_multi_cube_prop_, is_multi_cube, @@ -399,7 +401,7 @@ def it_knows_whether_it_is_numeric_measure_to_help( assert Cube_.call_args_list == ([call({"cube": 0})] if is_multi_cube else []) assert is_numeric_mean == expected_value - def it_knows_its_valid_counts_summary_range_to_help(self, _cubes_prop_, cube_): + def test_it_knows_its_valid_counts_summary_range_to_help(self, _cubes_prop_, cube_): cube_.valid_counts_summary_range = (1, 3) _cubes_prop_.return_value = (cube_,) cube_set = CubeSet(None, None, None, None) @@ -408,7 +410,7 @@ def it_knows_its_valid_counts_summary_range_to_help(self, _cubes_prop_, cube_): np.testing.assert_array_equal(valid_counts_summary_range, (1, 3)) - def it_knows_its_n_reposnes_to_help(self, _cubes_prop_, cube_): + def test_it_knows_its_n_reposnes_to_help(self, _cubes_prop_, cube_): cube_.n_responses = 6 _cubes_prop_.return_value = (cube_,) cube_set = CubeSet(None, None, None, None) @@ -440,10 +442,10 @@ def _is_numeric_measure_prop_(self, request): return property_mock(request, CubeSet, "_is_numeric_measure") -class DescribeCube: +class TestCube: """Unit-test suite for `cr.cube.cube.Cube` object.""" - def it_provides_the_default_repr_when_enhanced_repr_fails( + def test_it_provides_the_default_repr_when_enhanced_repr_fails( self, dimension_types_prop_ ): dimension_types_prop_.return_value = [1, 2, 3] @@ -453,7 +455,7 @@ def it_provides_the_default_repr_when_enhanced_repr_fails( assert cube_repr.startswith("= 3) for idx in range(5) @@ -680,7 +684,7 @@ def it_provides_access_to_valid_elements(self, request): ), ), ) - def it_knows_its_mr_insertions_elements_transforms_from_transforms_dict( + def test_it_knows_its_mr_insertions_elements_transforms_from_transforms_dict( self, dim_xforms, element_dicts, dim_type, expected_value ): elements = Elements.from_typedef( @@ -722,7 +726,7 @@ def it_knows_its_mr_insertions_elements_transforms_from_transforms_dict( ("Y", "%Y", "abc", "abc"), # ----------------- invalid x, no change ), ) - def it_can_format_datetime_label_to_help( + def test_it_can_format_datetime_label_to_help( self, request, resolution, out_format, x, expected ): all_elements = Elements.from_typedef( @@ -741,7 +745,9 @@ def it_can_format_datetime_label_to_help( "dim_type, value, expected", ((DT.CATEGORICAL, "cat a", "cat a"), (DT.BINNED_NUMERIC, 123, "123")), ) - def and_it_can_format_non_datetime_element_label(self, dim_type, value, expected): + def test_and_it_can_format_non_datetime_element_label( + self, dim_type, value, expected + ): typedef = { "class": "enum", "subtype": {"class": "numeric"}, @@ -750,7 +756,7 @@ def and_it_can_format_non_datetime_element_label(self, dim_type, value, expected all_elements = Elements.from_typedef(typedef, {}, dim_type, None) assert all_elements[0]._label_formatter(value) == expected - def it_obeys_category_order_from_typedef(self): + def test_it_obeys_category_order_from_typedef(self): # Unordered all_elements = Elements.from_typedef( { @@ -777,10 +783,10 @@ def it_obeys_category_order_from_typedef(self): assert all_elements.element_ids == (2, 3, 1) -class Describe_ValidElements: +class Test_ValidElements: """Unit-test suite for `cr.cube.dimension.Elements.valid_elements`.""" - def it_gets_its_Element_objects_from_anElements_object(self, request): + def test_it_gets_its_Element_objects_from_anElements_object(self, request): all_elements = Elements( instance_mock(request, Element, name="element-%s" % idx, missing=missing) for idx, missing in enumerate([False, True, False]) @@ -788,10 +794,12 @@ def it_gets_its_Element_objects_from_anElements_object(self, request): assert all_elements.valid_elements == (all_elements[0], all_elements[2]) -class Describe_ElementIdShim: +class Test_ElementIdShim: """Unit-test suite for `cr.cube.dimension._ElementIdShim` object.""" - def it_provides_the_shimmed_dimension_dict_for_subvars(self, _subvar_aliases_prop_): + def test_it_provides_the_shimmed_dimension_dict_for_subvars( + self, _subvar_aliases_prop_ + ): _subvar_aliases_prop_.return_value = tuple(("alias1", "alias2")) dimension_dict = { "type": { @@ -813,7 +821,7 @@ def it_provides_the_shimmed_dimension_dict_for_subvars(self, _subvar_aliases_pro "another": "outside type", } - def and_it_provides_the_shimmed_dimension_dict_for_datetime(self): + def test_and_it_provides_the_shimmed_dimension_dict_for_datetime(self): dimension_dict = { "type": { "elements": [ @@ -844,13 +852,13 @@ def and_it_provides_the_shimmed_dimension_dict_for_datetime(self): "another": "outside type", } - def but_other_types_of_dimensions_are_left_alone(self): + def test_but_other_types_of_dimensions_are_left_alone(self): dimension_dict = {"dimension": "dictionary"} shim_ = _ElementIdShim(DT.CAT, dimension_dict, None) assert shim_.shimmed_dimension_dict == dimension_dict - def it_provides_the_shimmed_dimension_transform_dict_for_subvars( + def test_it_provides_the_shimmed_dimension_transform_dict_for_subvars( self, _replaced_element_transforms_, _replaced_order_element_ids_ ): dimension_transforms_dict = { @@ -870,7 +878,7 @@ def it_provides_the_shimmed_dimension_transform_dict_for_subvars( _replaced_element_transforms_.assert_called_once_with(shim_, "all_elements") _replaced_order_element_ids_.assert_called_once_with(shim_, "a") - def but_it_skips_replacing_if_not_present( + def test_but_it_skips_replacing_if_not_present( self, _replaced_element_transforms_, _replaced_order_element_ids_ ): dimension_transforms_dict = { @@ -883,7 +891,7 @@ def but_it_skips_replacing_if_not_present( _replaced_element_transforms_.assert_not_called() _replaced_order_element_ids_.assert_not_called() - def and_it_skips_replacing_if_not_subvars( + def test_and_it_skips_replacing_if_not_subvars( self, _replaced_element_transforms_, _replaced_order_element_ids_ ): dimension_transforms_dict = { @@ -911,7 +919,7 @@ def and_it_skips_replacing_if_not_subvars( ("1", ("all", "al1", "al2"), ("001", "1", "003"), (1, 3, "all"), "al1"), ), ) - def it_translates_element_ids_for_subvariables( + def test_it_translates_element_ids_for_subvariables( self, _raw_element_id_prop_, _subvar_aliases_prop_, @@ -930,7 +938,7 @@ def it_translates_element_ids_for_subvariables( assert shim_.translate_element_id(id) == expected - def but_it_leaves_non_array_ids_alone(self): + def test_but_it_leaves_non_array_ids_alone(self): _ElementIdShim(DT.CAT, None, None).translate_element_id(25) == 25 @pytest.mark.parametrize( @@ -942,7 +950,7 @@ def but_it_leaves_non_array_ids_alone(self): ("2021", "2021"), ), ) - def and_it_translates_for_datetime(self, request, id_, expected): + def test_and_it_translates_for_datetime(self, request, id_, expected): property_mock( request, _ElementIdShim, @@ -952,13 +960,13 @@ def and_it_translates_for_datetime(self, request, id_, expected): shim = _ElementIdShim(DT.DATETIME, None, None) assert shim.translate_element_id(id_) == expected - def it_provides_the_raw_element_ids_to_help(self): + def test_it_provides_the_raw_element_ids_to_help(self): dimension_dict = {"type": {"elements": [{"id": 1}, {"id": "b"}]}} shim_ = _ElementIdShim(None, dimension_dict, None) assert shim_._raw_element_ids == tuple((1, "b")) - def it_replaces_the_element_transforms_to_help( + def test_it_replaces_the_element_transforms_to_help( self, _raw_element_id_prop_, _subvar_aliases_prop_, _subvar_ids_prop_ ): element_transforms = { @@ -975,7 +983,7 @@ def it_replaces_the_element_transforms_to_help( "alias2": {"another": "transform"} } - def it_replaces_the_element_transforms_to_help_with_alias_keys(self): + def test_it_replaces_the_element_transforms_to_help_with_alias_keys(self): element_transforms = { "alias1": {"transform": "object"}, "alias2": {"another": "transform"}, @@ -987,7 +995,7 @@ def it_replaces_the_element_transforms_to_help_with_alias_keys(self): shim_._replaced_element_transforms(element_transforms) == element_transforms ) - def it_replaces_the_element_transforms_to_help_with_subvar_id_keys( + def test_it_replaces_the_element_transforms_to_help_with_subvar_id_keys( self, _subvar_aliases_prop_, _subvar_ids_prop_ ): _subvar_aliases_prop_.return_value = tuple(("alias1", "alias2", "alias3")) @@ -1026,11 +1034,11 @@ def it_replaces_the_element_transforms_to_help_with_subvar_id_keys( ), ), ) - def it_provides_the_subvar_ids_to_help(self, dim_dict, expected): + def test_it_provides_the_subvar_ids_to_help(self, dim_dict, expected): shim_ = _ElementIdShim(None, dim_dict, None) assert shim_._subvar_ids == expected - def it_provides_the_subvar_aliases_to_help(self): + def test_it_provides_the_subvar_aliases_to_help(self): dimension_dict = { "type": { "elements": [ @@ -1067,7 +1075,7 @@ def it_provides_the_subvar_aliases_to_help(self): ), ), ) - def it_knows_if_it_has_mr_insertions( + def test_it_knows_if_it_has_mr_insertions( self, dimension_dict, dimension_type, expected_has_mr_insertion ): shim = _ElementIdShim(dimension_type, dimension_dict, None) @@ -1099,10 +1107,10 @@ def _subvar_ids_prop_(self, request): return property_mock(request, _ElementIdShim, "_subvar_ids") -class Describe_Element: +class Test_Element: """Unit-test suite for `cr.cube.dimension.Element` object.""" - def it_knows_its_anchor(self): + def test_it_knows_its_anchor(self): element_dict = {"value": {"references": {"anchor": "top"}, "derived": True}} element = Element(element_dict, None, None, None, None) @@ -1110,7 +1118,7 @@ def it_knows_its_anchor(self): assert anchor == "top" - def but_anchor_is_none_if_not_derived(self): + def test_but_anchor_is_none_if_not_derived(self): element_dict = {"value": {"derived": False}} element = Element(element_dict, None, None, None, None) @@ -1118,7 +1126,7 @@ def but_anchor_is_none_if_not_derived(self): assert anchor is None - def it_knows_its_element_id(self): + def test_it_knows_its_element_id(self): element_dict = {"id": 42} element = Element(element_dict, None, None, None, None) @@ -1126,7 +1134,7 @@ def it_knows_its_element_id(self): assert element_id == 42 - def it_knows_its_fill_RGB_color_str(self, element_transforms_): + def test_it_knows_its_fill_RGB_color_str(self, element_transforms_): element_transforms_.fill = [255, 255, 248] element = Element(None, None, element_transforms_, None, None) @@ -1134,7 +1142,7 @@ def it_knows_its_fill_RGB_color_str(self, element_transforms_): assert rgb_color_fill == [255, 255, 248] - def it_knows_its_position_among_all_the_dimension_elements(self): + def test_it_knows_its_position_among_all_the_dimension_elements(self): element = Element(None, 17, None, None, None) index = element.index assert index == 17 @@ -1160,7 +1168,7 @@ def it_knows_its_position_among_all_the_dimension_elements(self): ({"value": {"references": {"name": "Tom"}}}, "", "", ()), ), ) - def it_knows_its_label( + def test_it_knows_its_label( self, request, element_dict, @@ -1176,7 +1184,9 @@ def it_knows_its_label( @pytest.mark.parametrize( ("hide", "expected_value"), ((True, True), (False, False), (None, False)) ) - def it_knows_whether_it_is_explicitly_hidden(self, request, hide, expected_value): + def test_it_knows_whether_it_is_explicitly_hidden( + self, request, hide, expected_value + ): element_transforms_ = instance_mock(request, _ElementTransforms, hide=hide) element = Element(None, None, element_transforms_, None, None) @@ -1196,7 +1206,7 @@ def it_knows_whether_it_is_explicitly_hidden(self, request, hide, expected_value ({"missing": 1}, True), ), ) - def it_knows_whether_its_missing_or_valid(self, element_dict, expected_value): + def test_it_knows_whether_its_missing_or_valid(self, element_dict, expected_value): element = Element(element_dict, None, None, None, None) missing = element.missing @@ -1219,7 +1229,7 @@ def it_knows_whether_its_missing_or_valid(self, element_dict, expected_value): ({"numeric_value": {"?": 8}}, {"?": 8}), ), ) - def it_knows_its_numeric_value(self, element_dict, expected_value): + def test_it_knows_its_numeric_value(self, element_dict, expected_value): element = Element(element_dict, None, None, None, None) numeric_value = element.numeric_value @@ -1234,7 +1244,7 @@ def element_transforms_(self, request): return instance_mock(request, _ElementTransforms) -class DescribeElementTransforms: +class TestElementTransforms: """Unit-test suite for `cr.cube.dimension._ElementTransforms` object.""" @pytest.mark.parametrize( @@ -1245,7 +1255,9 @@ class DescribeElementTransforms: ({"name": "Zillow", "fill": [255, 255, 0]}, [255, 255, 0]), ), ) - def it_knows_its_fill_color_value(self, element_transforms_dict, expected_value): + def test_it_knows_its_fill_color_value( + self, element_transforms_dict, expected_value + ): element_transforms = _ElementTransforms(element_transforms_dict) fill_color_value = element_transforms.fill @@ -1261,7 +1273,7 @@ def it_knows_its_fill_color_value(self, element_transforms_dict, expected_value) ({"hide": 0}, None), ), ) - def it_knows_when_it_is_explicitly_hidden( + def test_it_knows_when_it_is_explicitly_hidden( self, element_transforms_dict, expected_value ): element_transforms = _ElementTransforms(element_transforms_dict) @@ -1279,7 +1291,7 @@ def it_knows_when_it_is_explicitly_hidden( ({"foo": "foo"}, None), ), ) - def it_knows_its_name(self, element_transforms_dict, expected_value): + def test_it_knows_its_name(self, element_transforms_dict, expected_value): element_transforms = _ElementTransforms(element_transforms_dict) name = element_transforms.name @@ -1287,7 +1299,7 @@ def it_knows_its_name(self, element_transforms_dict, expected_value): assert name == expected_value -class Describe_OrderSpec: +class Test_OrderSpec: """Unit-test suite for `cr.cube.dimension._OrderSpec` object.""" @pytest.mark.parametrize( @@ -1301,7 +1313,7 @@ class Describe_OrderSpec: ({"fixed": {"top": [1, 2], "bottom": [3, 4]}}, (3, 4)), ), ) - def it_knows_its_bottom_fixed_ids( + def test_it_knows_its_bottom_fixed_ids( self, _order_dict_prop_, order_dict, expected_value ): _order_dict_prop_.return_value = order_dict @@ -1315,7 +1327,7 @@ def it_knows_its_bottom_fixed_ids( ({"type": "payload_order"}, CM.PAYLOAD_ORDER), ), ) - def it_knows_its_collation_method( + def test_it_knows_its_collation_method( self, _order_dict_prop_, order_dict, expected_value ): _order_dict_prop_.return_value = order_dict @@ -1330,17 +1342,17 @@ def it_knows_its_collation_method( ({"direction": "ascending"}, False), ), ) - def it_knows_whether_the_sort_direction_is_descending( + def test_it_knows_whether_the_sort_direction_is_descending( self, _order_dict_prop_, order_dict, expected_value ): _order_dict_prop_.return_value = order_dict assert _OrderSpec(None, None).descending == expected_value - def it_knows_the_sort_vector_element_id(self, _order_dict_prop_): + def test_it_knows_the_sort_vector_element_id(self, _order_dict_prop_): _order_dict_prop_.return_value = {"element_id": 42} assert _OrderSpec(None, None).element_id == 42 - def but_it_raises_when_element_id_not_present(self, _order_dict_prop_): + def test_but_it_raises_when_element_id_not_present(self, _order_dict_prop_): _order_dict_prop_.return_value = {} with pytest.raises(KeyError) as e: _OrderSpec(None, None).element_id @@ -1355,37 +1367,37 @@ def but_it_raises_when_element_id_not_present(self, _order_dict_prop_): ({"element_ids": [4, 2]}, (4, 2)), ), ) - def it_knows_the_ordered_element_ids_for_an_explicit_sort( + def test_it_knows_the_ordered_element_ids_for_an_explicit_sort( self, _order_dict_prop_, order_dict, expected_value ): _order_dict_prop_.return_value = order_dict assert _OrderSpec(None, None).element_ids == expected_value - def it_knows_the_sort_vector_insertion_id(self, _order_dict_prop_): + def test_it_knows_the_sort_vector_insertion_id(self, _order_dict_prop_): _order_dict_prop_.return_value = {"insertion_id": 42} assert _OrderSpec(None, None).insertion_id == 42 - def but_it_raises_when_insertion_id_not_present(self, _order_dict_prop_): + def test_but_it_raises_when_insertion_id_not_present(self, _order_dict_prop_): _order_dict_prop_.return_value = {} with pytest.raises(KeyError) as e: _OrderSpec(None, None).insertion_id assert str(e.value) == "'insertion_id'" - def it_knows_the_marginal_specified_as_the_sort_basis(self, _order_dict_prop_): + def test_it_knows_the_marginal_specified_as_the_sort_basis(self, _order_dict_prop_): _order_dict_prop_.return_value = {"marginal": "scale_mean"} assert _OrderSpec(None, None).marginal == MARGINAL.SCALE_MEAN - def it_knows_the_measure_specified_as_the_sort_basis(self, _order_dict_prop_): + def test_it_knows_the_measure_specified_as_the_sort_basis(self, _order_dict_prop_): _order_dict_prop_.return_value = {"measure": "col_percent"} assert _OrderSpec(None, None).measure == MEASURE.COLUMN_PERCENT - def but_it_raises_when_measure_field_is_not_present(self, _order_dict_prop_): + def test_but_it_raises_when_measure_field_is_not_present(self, _order_dict_prop_): _order_dict_prop_.return_value = {} with pytest.raises(KeyError) as e: _OrderSpec(None, None).measure assert str(e.value) == "'measure'" - def and_it_raises_when_the_measure_keyword_is_not_recognized( + def test_and_it_raises_when_the_measure_keyword_is_not_recognized( self, _order_dict_prop_ ): _order_dict_prop_.return_value = {"measure": "foobar"} @@ -1406,7 +1418,9 @@ def and_it_raises_when_the_measure_keyword_is_not_recognized( ({"fixed": {"bottom": [1, 2], "top": [3, 4]}}, (3, 4)), ), ) - def it_knows_its_top_fixed_ids(self, _order_dict_prop_, order_dict, expected_value): + def test_it_knows_its_top_fixed_ids( + self, _order_dict_prop_, order_dict, expected_value + ): _order_dict_prop_.return_value = order_dict assert _OrderSpec(None, None).top_fixed_ids == expected_value @@ -1419,7 +1433,7 @@ def it_knows_its_top_fixed_ids(self, _order_dict_prop_, order_dict, expected_val ({"order": {"type": "explicit"}}, {"type": "explicit"}), ), ) - def it_provides_access_to_the_order_dict_to_help( + def test_it_provides_access_to_the_order_dict_to_help( self, dim_transforms, expected_value ): assert _OrderSpec(None, dim_transforms)._order_dict == expected_value @@ -1431,10 +1445,10 @@ def _order_dict_prop_(self, request): return property_mock(request, _OrderSpec, "_order_dict") -class Describe_Subtotals: +class Test_Subtotals: """Unit-test suite for `cr.cube.dimension._Subtotals` object.""" - def it_has_sequence_behaviors(self, request, _subtotals_prop_): + def test_it_has_sequence_behaviors(self, request, _subtotals_prop_): _subtotals_prop_.return_value = (1, 2, 3) subtotals = _Subtotals(None, None) @@ -1443,7 +1457,9 @@ def it_has_sequence_behaviors(self, request, _subtotals_prop_): assert len(subtotals) == 3 assert list(n for n in subtotals) == [1, 2, 3] - def it_provides_the_element_ids_as_a_set_to_help(self, request, valid_elements_): + def test_it_provides_the_element_ids_as_a_set_to_help( + self, request, valid_elements_ + ): valid_elements_.element_ids = tuple(range(3)) subtotals = _Subtotals(None, valid_elements_) @@ -1480,7 +1496,7 @@ def it_provides_the_element_ids_as_a_set_to_help(self, request, valid_elements_) ), ), ) - def it_removes_invalid_when_iterating_the_valid_subtotal_insertion_dicts_to_help( + def test_it_removes_invalid_when_iterating_the_valid_subtotal_insertion_dicts( self, _element_ids_prop_, insertion_dicts, element_ids, expected_value ): _element_ids_prop_.return_value = element_ids @@ -1490,7 +1506,7 @@ def it_removes_invalid_when_iterating_the_valid_subtotal_insertion_dicts_to_help assert subtotal_dicts == expected_value - def but_it_accepts_valid_insertion_dicts(self, _element_ids_prop_): + def test_but_it_accepts_valid_insertion_dicts(self, _element_ids_prop_): _element_ids_prop_.return_value = {1, 2, 5, 8, -1} insertion_dicts = [ { @@ -1531,7 +1547,7 @@ def but_it_accepts_valid_insertion_dicts(self, _element_ids_prop_): assert subtotal_dicts == tuple(insertion_dicts) - def it_constructs_its_subtotal_objects_to_help( + def test_it_constructs_its_subtotal_objects_to_help( self, request, _iter_valid_subtotal_dicts_, valid_elements_, _Subtotal_ ): subtotal_dicts_ = tuple( @@ -1577,7 +1593,7 @@ def valid_elements_(self, request): return instance_mock(request, Elements) -class Describe_Subtotal: +class Test_Subtotal: """Unit-test suite for `cr.cube.dimension._Subtotal` object.""" @pytest.mark.parametrize( @@ -1590,7 +1606,7 @@ class Describe_Subtotal: ({"args": [4, 99]}, (4, 99), [3, 4]), ), ) - def it_knows_the_addend_idxs( + def test_it_knows_the_addend_idxs( self, addend_ids_, all_elements_, @@ -1625,7 +1641,7 @@ def it_knows_the_addend_idxs( ({"anchor": None}, {1, 2, 3}, "bottom"), ), ) - def it_knows_the_insertion_anchor( + def test_it_knows_the_insertion_anchor( self, subtotal_dict, element_ids, expected_value, valid_elements_ ): valid_elements_.element_ids = element_ids @@ -1647,7 +1663,7 @@ def it_knows_the_insertion_anchor( ({"args": [1], "kwargs": {"positive": [2]}}, {1, 2, 3}, (2,)), ), ) - def it_provides_access_to_the_addend_element_ids( + def test_it_provides_access_to_the_addend_element_ids( self, subtotal_dict, element_ids, expected_value, valid_elements_ ): valid_elements_.element_ids = element_ids @@ -1655,14 +1671,14 @@ def it_provides_access_to_the_addend_element_ids( assert subtotal.addend_ids == expected_value - def it_knows_its_insertion_id_when_it_has_been_assigned_one(self): + def test_it_knows_its_insertion_id_when_it_has_been_assigned_one(self): assert _Subtotal({"id": 42}, None).insertion_id == 42 @pytest.mark.parametrize( "subtotal_dict, expected_value", (({}, ""), ({"name": None}, ""), ({"name": ""}, ""), ({"name": "Joe"}, "Joe")), ) - def it_knows_the_subtotal_label(self, subtotal_dict, expected_value): + def test_it_knows_the_subtotal_label(self, subtotal_dict, expected_value): assert _Subtotal(subtotal_dict, None).label == expected_value @pytest.mark.parametrize( @@ -1677,7 +1693,7 @@ def it_knows_the_subtotal_label(self, subtotal_dict, expected_value): ({"kwargs": {"negative": [1, 2, 3]}}, {}, ()), ), ) - def it_provides_access_to_the_subtrahend_element_ids( + def test_it_provides_access_to_the_subtrahend_element_ids( self, subtotal_dict, element_ids, expected_value, valid_elements_ ): valid_elements_.element_ids = element_ids @@ -1695,7 +1711,7 @@ def it_provides_access_to_the_subtrahend_element_ids( ({"kwargs": {"negative": [4, 99]}}, (4, 99), [3, 4]), ), ) - def it_knows_the_subtrahend_idxs( + def test_it_knows_the_subtrahend_idxs( self, subtrahend_ids_, all_elements_, @@ -1724,7 +1740,7 @@ def it_knows_the_subtrahend_idxs( "subtotal_dict, expected_fill", (({"fill": "fake_fill"}, "fake_fill"), ({}, None)), ) - def it_knows_its_fill(self, subtotal_dict, expected_fill): + def test_it_knows_its_fill(self, subtotal_dict, expected_fill): subtotal = _Subtotal(subtotal_dict, None) fill = subtotal.fill diff --git a/tests/unit/test_enum.py b/tests/unit/test_enum.py index 445e8ad9b..2a0511d51 100644 --- a/tests/unit/test_enum.py +++ b/tests/unit/test_enum.py @@ -5,18 +5,18 @@ from cr.cube.enums import _DimensionType -class Describe_DimensionType: - def it_provides_a_console_friendly_representation(self): +class Test_DimensionType: + def test_it_provides_a_console_friendly_representation(self): dimension_type = _DimensionType("ALTERNATE_UNIVERSE") repr_ = repr(dimension_type) assert repr_ == "" - def it_provides_a_user_friendly_str_representation(self): + def test_it_provides_a_user_friendly_str_representation(self): dimension_type = _DimensionType("QUANTUM_MANIFOLD") str_ = str(dimension_type) assert str_ == "DIMENSION_TYPE.QUANTUM_MANIFOLD" - def it_knows_its_name(self): + def test_it_knows_its_name(self): dimension_type = _DimensionType("WORM_HOLE") name = dimension_type.name assert name == "WORM_HOLE" diff --git a/tests/unit/test_scalar.py b/tests/unit/test_scalar.py index 7b433ea1b..27fd07423 100644 --- a/tests/unit/test_scalar.py +++ b/tests/unit/test_scalar.py @@ -5,6 +5,6 @@ from cr.cube.scalar import MeansScalar -class Describe_MeansScalar: - def it_knows_its_ndim(self): +class Test_MeansScalar: + def test_it_knows_its_ndim(self): assert MeansScalar(None, None).ndim == 0 diff --git a/tests/unit/test_smoothing.py b/tests/unit/test_smoothing.py index c3bbcfd9d..178cebc28 100644 --- a/tests/unit/test_smoothing.py +++ b/tests/unit/test_smoothing.py @@ -12,8 +12,8 @@ from ..unitutil import class_mock, initializer_mock, instance_mock -class DescribeSmoother: - def it_provides_a_factory_for_constructing_smoother_objects(self, request): +class TestSmoother: + def test_it_provides_a_factory_for_constructing_smoother_objects(self, request): _SingleSidedMovingAvgSmoother_ = class_mock( request, "cr.cube.smoothing._SingleSidedMovingAvgSmoother", @@ -29,7 +29,7 @@ def it_provides_a_factory_for_constructing_smoother_objects(self, request): {"function": "one_sided_moving_avg", "window": 3}, DT.CAT_DATE ) - def but_it_raises_an_exception_when_function_is_not_implemented(self, request): + def test_but_it_raises_an_exception_when_function_is_not_implemented(self, request): dimension_ = instance_mock(request, Dimension) dimension_.smoothing_dict = {"function": "foo", "window": 3} @@ -39,8 +39,8 @@ def but_it_raises_an_exception_when_function_is_not_implemented(self, request): assert str(e.value) == "Function foo is not available." -class Describe_SingleSideMovingAvgSmoother: - def it_constructs_single_sided_moving_avg_to_help(self, request): +class Test_SingleSideMovingAvgSmoother: + def test_it_constructs_single_sided_moving_avg_to_help(self, request): _init_ = initializer_mock(request, _SingleSidedMovingAvgSmoother) single_sided_miving_avg = _SingleSidedMovingAvgSmoother( smoothing_dict=3, dimension_type=DT.CAT_DATE @@ -57,7 +57,7 @@ def it_constructs_single_sided_moving_avg_to_help(self, request): ({"window": 3}, np.array([]), DT.CAT_DATE, False), ), ) - def it_knows_when_it_can_apply_smoothing( + def test_it_knows_when_it_can_apply_smoothing( self, smoothing_dict, base_values, dimension_type, expected_value ): smoother = _SingleSidedMovingAvgSmoother(smoothing_dict, dimension_type) @@ -71,7 +71,9 @@ def it_knows_when_it_can_apply_smoothing( (1, np.random.rand(3, 5), DT.CAT_DATE), ), ) - def but_it_warns_when_window_is_invalid(self, window, base_values, dimension_type): + def test_but_it_warns_when_window_is_invalid( + self, window, base_values, dimension_type + ): smoother = _SingleSidedMovingAvgSmoother( smoothing_dict={"window": window}, dimension_type=dimension_type ) @@ -92,7 +94,7 @@ def but_it_warns_when_window_is_invalid(self, window, base_values, dimension_typ (3, np.random.rand(3, 5), DT.CAT), ), ) - def and_it_warns_when_dim_is_not_a_categorical_date( + def test_and_it_warns_when_dim_is_not_a_categorical_date( self, window, base_values, dimension_type ): smoother = _SingleSidedMovingAvgSmoother( @@ -119,7 +121,9 @@ def and_it_warns_when_dim_is_not_a_categorical_date( (np.array([]), 3, []), ), ) - def it_provides_complete_smoothed_values(self, base_values, window, expected_value): + def test_it_provides_complete_smoothed_values( + self, base_values, window, expected_value + ): smoother = _SingleSidedMovingAvgSmoother( smoothing_dict={"window": window}, dimension_type=DT.CAT_DATE ) diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py index d46bed634..727a945a8 100644 --- a/tests/unit/test_util.py +++ b/tests/unit/test_util.py @@ -7,27 +7,27 @@ from cr.cube.util import lazyproperty -class DescribeLazyPropertyDecorator: +class TestLazyPropertyDecorator: """Tests @lazyproperty decorator class.""" - def it_is_a_lazyproperty_object_on_class_access(self, Obj): + def test_it_is_a_lazyproperty_object_on_class_access(self, Obj): assert isinstance(Obj.fget, lazyproperty) - def but_it_adopts_the_name_of_the_decorated_method(self, Obj): + def test_but_it_adopts_the_name_of_the_decorated_method(self, Obj): assert Obj.fget.__name__ == "fget" - def and_it_adopts_the_module_of_the_decorated_method(self, Obj): + def test_and_it_adopts_the_module_of_the_decorated_method(self, Obj): # ---the module name actually, not a module object assert Obj.fget.__module__ == __name__ - def and_it_adopts_the_docstring_of_the_decorated_method(self, Obj): + def test_and_it_adopts_the_docstring_of_the_decorated_method(self, Obj): assert Obj.fget.__doc__ == "Docstring of Obj.fget method definition." - def it_only_calculates_value_on_first_call(self, obj): + def test_it_only_calculates_value_on_first_call(self, obj): assert obj.fget == 1 assert obj.fget == 1 - def it_raises_on_attempt_to_assign(self, obj): + def test_it_raises_on_attempt_to_assign(self, obj): assert obj.fget == 1 with pytest.raises(AttributeError): obj.fget = 42