Esempio n. 1
0
    def test_load_parameters(self, mock_open, mock_load_model,
                             mock_base_processor):

        # test not model class
        with self.assertRaisesRegex(TypeError,
                                    "`model_class` must be a BaseModel"):
            load_options = dict(model_class="fake")
            UnstructuredDataLabeler._load_parameters("test/path", load_options)

        # test not correct model class
        with self.assertRaisesRegex(
                ValueError,
                "The load_options model class does not "
                "match the required DataLabeler model.\n "
                ".* != .*",
        ):
            mocked_model = mock.Mock(spec=CharacterLevelCnnModel)
            mocked_model.__name__ = "FakeClassName"
            load_options = dict(model_class=mocked_model)
            UnstructuredDataLabeler._load_parameters("test/path", load_options)

        # test not preprocessor class
        with self.assertRaisesRegex(
                TypeError, "`preprocessor_class` must be a "
                "BaseDataPreprocessor"):
            load_options = dict(preprocessor_class="fake")
            UnstructuredDataLabeler._load_parameters("test/path", load_options)

        # test not correct preprocessor class
        with self.assertRaisesRegex(
                ValueError,
                "The load_options preprocessor class does "
                "not match the required DataLabeler "
                "preprocessor.\n .* != .*",
        ):
            mocked_preprocessor = mock.Mock(
                spec=data_processing.BaseDataPreprocessor)
            mocked_preprocessor.__name__ = "FakeProcessorName"
            load_options = dict(preprocessor_class=mocked_preprocessor)
            UnstructuredDataLabeler._load_parameters("test/path", load_options)

        # test not postprocessor class
        with self.assertRaisesRegex(
                TypeError, "`postprocessor_class` must be a "
                "BaseDataPostprocessor"):
            load_options = dict(postprocessor_class="fake")
            UnstructuredDataLabeler._load_parameters("test/path", load_options)

        # test not correct postprocessor class
        with self.assertRaisesRegex(
                ValueError,
                "The load_options postprocessor class does "
                "not match the required DataLabeler "
                "postprocessor.\n .* != .*",
        ):
            mocked_postprocessor = mock.Mock(
                spec=data_processing.BaseDataPostprocessor)
            mocked_postprocessor.__name__ = "FakeProcessorName"
            load_options = dict(postprocessor_class=mocked_postprocessor)
            UnstructuredDataLabeler._load_parameters("test/path", load_options)
Esempio n. 2
0
    def test_load_parameters(self, mock_open, mock_load_model,
                             mock_base_processor):

        # test not model class
        with self.assertRaisesRegex(TypeError,
                                    '`model_class` must be a BaseModel'):
            load_options = dict(model_class='fake')
            UnstructuredDataLabeler._load_parameters('test/path', load_options)

        # test not correct model class
        with self.assertRaisesRegex(
                ValueError, 'The load_options model class does not '
                'match the required DataLabeler model.\n '
                '.* != .*'):
            mocked_model = mock.Mock(spec=CharacterLevelCnnModel)
            mocked_model.__name__ = 'FakeClassName'
            load_options = dict(model_class=mocked_model)
            UnstructuredDataLabeler._load_parameters('test/path', load_options)

        # test not preprocessor class
        with self.assertRaisesRegex(
                TypeError, '`preprocessor_class` must be a '
                'BaseDataPreprocessor'):
            load_options = dict(preprocessor_class='fake')
            UnstructuredDataLabeler._load_parameters('test/path', load_options)

        # test not correct preprocessor class
        with self.assertRaisesRegex(
                ValueError, 'The load_options preprocessor class does '
                'not match the required DataLabeler '
                'preprocessor.\n .* != .*'):
            mocked_preprocessor = mock.Mock(
                spec=data_processing.BaseDataPreprocessor)
            mocked_preprocessor.__name__ = 'FakeProcessorName'
            load_options = dict(preprocessor_class=mocked_preprocessor)
            UnstructuredDataLabeler._load_parameters('test/path', load_options)

        # test not postprocessor class
        with self.assertRaisesRegex(
                TypeError, '`postprocessor_class` must be a '
                'BaseDataPostprocessor'):
            load_options = dict(postprocessor_class='fake')
            UnstructuredDataLabeler._load_parameters('test/path', load_options)

        # test not correct postprocessor class
        with self.assertRaisesRegex(
                ValueError, 'The load_options postprocessor class does '
                'not match the required DataLabeler '
                'postprocessor.\n .* != .*'):
            mocked_postprocessor = mock.Mock(
                spec=data_processing.BaseDataPostprocessor)
            mocked_postprocessor.__name__ = 'FakeProcessorName'
            load_options = dict(postprocessor_class=mocked_postprocessor)
            UnstructuredDataLabeler._load_parameters('test/path', load_options)