예제 #1
0
class TestCollocateFactory(unittest.TestCase):
    def setUp(self):
        self.factory = CollocatorFactory()

    def test_GIVEN_Factory_WHEN_request_ungridded_ungridded_box_mean_with_con_options_THEN_correct_objects_returned(
            self):
        collocator, constraint, kernel = self.factory.get_collocator_instances_for_method(
            "box", "mean", {'missing_data_for_missing_sample': "false", "h_sep": "10"}, {}, False, False)
        assert_that(collocator, instance_of(GeneralUngriddedCollocator), "Collocator's class")
        assert_that(constraint, instance_of(SepConstraintKdtree), "Constraint")
        assert_that(kernel, instance_of(mean), "Kernel")
        assert_that(constraint.h_sep, is_(10), "h_sep")

    def test_GIVEN_no_collocator_WHEN_get_col_instances_for_gridded_to_gridded_THEN_defaults_to_lin(self):
        collocator, constraint, kernel = self.factory.get_collocator_instances_for_method(
            None, None, {'missing_data_for_missing_sample': "false"}, {}, True, True)
        assert_that(collocator, instance_of(GriddedCollocator))
        assert_that(constraint, is_(None))
        assert_that(kernel, instance_of(gridded_gridded_li))

    def test_GIVEN_no_collocator_WHEN_get_col_instances_for_ungridded_to_ungridded_THEN_defaults_to_box(self):
        collocator, constraint, kernel = self.factory.get_collocator_instances_for_method(
            None, None, {'missing_data_for_missing_sample': "false"}, {}, False, False)
        assert_that(collocator, instance_of(GeneralUngriddedCollocator))
        assert_that(constraint, is_(SepConstraintKdtree))
        assert_that(kernel, is_(moments))

    def test_GIVEN_no_collocator_WHEN_get_col_instances_for_ungridded_to_gridded_THEN_correct_default_returned(self):
        collocator, constraint, kernel = self.factory.get_collocator_instances_for_method(
            None, None, {'missing_data_for_missing_sample': "false"}, {}, True, False)
        assert_that(collocator, instance_of(GeneralGriddedCollocator))
        assert_that(constraint, is_(BinnedCubeCellOnlyConstraint))
        assert_that(kernel, instance_of(moments))

    def test_GIVEN_no_collocator_WHEN_get_col_instances_for_gridded_to_ungridded_THEN_correct_default_returned(self):
        collocator, constraint, kernel = self.factory.get_collocator_instances_for_method(
            None, None, {'missing_data_for_missing_sample': "false"}, {}, False, True)
        assert_that(collocator, instance_of(GeneralUngriddedCollocator))
        assert_that(constraint, is_(None))
        assert_that(kernel, instance_of(nn_gridded))
예제 #2
0
    def test_GIVEN_GriddedData_WHEN_collocate_THEN_collocator_called_correctly(self):
        sample = gridded_data.make_from_cube(mock.make_square_5x3_2d_cube())
        out_name = "output-name"
        col_name = "dummy"
        col_options = {}
        mock_collocator = MagicMock()
        mock_collocator.collocate = MagicMock(return_value=GriddedDataList([sample]))
        mock_constraint = MagicMock()
        mock_kernel = MagicMock()
        mock_collocator_factory = CollocatorFactory()
        mock_collocator_factory.get_collocator_instances_for_method = MagicMock(
            return_value=(mock_collocator, mock_constraint, mock_kernel)
        )
        col = Collocate(sample, out_name, collocator_factory=mock_collocator_factory)
        data = gridded_data.make_from_cube(mock.make_square_5x3_2d_cube())
        output = col.collocate(data, col_name, col_options)

        assert_that(mock_collocator_factory.get_collocator_instances_for_method.call_count, is_(1))
        factory_call_args = mock_collocator_factory.get_collocator_instances_for_method.call_args_list[0][0]
        assert_that(factory_call_args[0], is_(col_name))
        assert_that(factory_call_args[1], is_(None))
        col_options["missing_data_for_missing_sample"] = False
        assert_that(factory_call_args[2], is_(col_options))
        assert_that(factory_call_args[3], is_(None))
        assert_that(factory_call_args[4], is_(True))
        assert_that(factory_call_args[5], is_(True))

        assert_that(mock_collocator.collocate.call_count, is_(1))
        collocator_args = mock_collocator.collocate.call_args_list[0][0]
        assert_that(collocator_args[0], is_(sample))
        assert_that(collocator_args[1], is_(data))
        assert_that(collocator_args[2], is_(mock_constraint))
        assert_that(collocator_args[3], is_(mock_kernel))

        assert_that(isinstance(output, GriddedDataList))
        assert_that(len(output), is_(1))
        assert_that(output[0].data.flatten().tolist(), is_(sample.data.flatten().tolist()))
예제 #3
0
 def setUp(self):
     self.factory = CollocatorFactory()