Пример #1
0
    def test_model_manager_does_not_allow_duplicate_qualified_names(self):
        """Testing that the ModelManager does not allow duplicate qualified names in the singleton."""
        # arrange
        model_manager = ModelManager()
        model1 = MLModelMock()
        model2 = MLModelMock()

        # act
        # loading the first instance of the model object
        model_manager.add_model(model1)

        exception_raised = False
        exception_message = ""
        try:
            # loading it again
            model_manager.add_model(model2)
        except Exception as e:
            exception_raised = True
            exception_message = str(e)

        # assert
        self.assertTrue(exception_raised)
        self.assertTrue(
            exception_message ==
            "A model with the same qualified name is already in the ModelManager singleton."
        )

        # cleanup
        model_manager.clear_instance()
Пример #2
0
    def test_only_ml_model_instances_allowed_to_be_stored(self):
        """Testing that the ModelManager only allows MLModel objects to be stored."""
        # arrange
        model_manager = ModelManager()
        some_object = SomeClass()

        # act
        exception_raised = False
        exception_message = ""
        try:
            model_manager.add_model(some_object)
        except Exception as e:
            exception_raised = True
            exception_message = str(e)

        # assert
        self.assertTrue(exception_raised)
        self.assertTrue(
            exception_message ==
            "ModelManager instance can only hold references to objects of type MLModel."
        )

        # cleanup
        model_manager.clear_instance()