Example #1
0
    def test_remove_model_method(self):
        """Testing the remove_model() method."""
        # arrange
        # instantiating the model manager class
        model_manager = ModelManager()

        # adding the model
        model_manager.load_model("tests.mocks.MLModelMock")

        # act
        exception_raised1 = False
        # accessing the MLModelMock model object
        try:
            model_manager.remove_model(qualified_name="qualified_name")
        except Exception as e:
            exception_raised1 = True

        exception_raised2 = False
        exception_message2 = ""
        # trying to access the model that was removed
        try:
            model = model_manager.get_model(qualified_name="qualified_name")
        except Exception as e:
            exception_raised2 = True
            exception_message2 = str(e)

        # assert
        self.assertFalse(exception_raised1)
        self.assertTrue(exception_raised2)
        self.assertTrue(
            exception_message2 ==
            "Instance of model 'qualified_name' not found in ModelManager.")
Example #2
0
    def test_load_model_method(self):
        # arrange
        # instantiating the model manager class
        model_manager = ModelManager()

        # adding the model
        model_manager.load_model("tests.mocks.MLModelMock")

        # act
        exception_raised = False
        model_object = None
        # accessing the MLModelMock model object
        try:
            model_object = model_manager.get_model(
                qualified_name="qualified_name")
        except Exception as e:
            exception_raised = True
            print_tb(e)

        # assert
        self.assertFalse(exception_raised)
        self.assertTrue(model_object is not None)

        # cleanup
        model_manager.clear_instance()
Example #3
0
    def test_model_manager_will_return_same_instance_when_instantiated_many_times(
            self):
        """Testing that the ModelManager will return the same instance of an MLModel class from several different
        references of ModelManager."""
        # arrange, act
        # instantiating the model manager class twice
        first_model_manager = ModelManager()
        second_model_manager = ModelManager()

        # loading the MLModel objects from configuration
        first_model_manager.load_model("tests.mocks.MLModelMock")

        first_model_object = first_model_manager.get_model(
            qualified_name="qualified_name")
        second_model_object = second_model_manager.get_model(
            qualified_name="qualified_name")

        # assert
        self.assertTrue(str(first_model_manager) == str(second_model_manager))
        self.assertTrue(str(first_model_object) == str(second_model_object))
Example #4
0
    def test_model_manager_will_return_same_instance_when_instantiated_many_times(
            self):
        # arrange, act
        # instantiating the model manager class twice
        first_model_manager = ModelManager()
        second_model_manager = ModelManager()

        # loading the MLModel objects from configuration
        first_model_manager.load_model("tests.mocks.MLModelMock")

        first_model_object = first_model_manager.get_model(
            qualified_name="qualified_name")
        second_model_object = second_model_manager.get_model(
            qualified_name="qualified_name")

        # assert
        self.assertTrue(str(first_model_manager) == str(second_model_manager))
        self.assertTrue(str(first_model_object) == str(second_model_object))

        # cleanup
        first_model_manager.clear_instance()
Example #5
0
    def test_get_model_method(self):
        """Testing the get_model method."""
        # arrange
        model_manager = ModelManager()

        model_manager.load_model("tests.mocks.MLModelMock")

        # act
        exception_raised = False
        model = None
        try:
            model = model_manager.get_model(qualified_name="qualified_name")
        except Exception as e:
            exception_raised = True

        # assert
        self.assertFalse(exception_raised)
        self.assertTrue(type(model) is MLModelMock)
Example #6
0
    def test_get_model_method_with_missing_model(self):
        """Testing that the ModelManager raises ValueError exception when a model is not found."""
        # arrange
        model_manager = ModelManager()

        model_manager.load_model("tests.mocks.MLModelMock")

        # act
        exception_raised = False
        exception_message = ""
        model = None
        try:
            model = model_manager.get_model(qualified_name="asdf")
        except Exception as e:
            exception_raised = True
            exception_message = str(e)

        # assert
        self.assertTrue(exception_raised)
        self.assertTrue(exception_message ==
                        "Instance of model 'asdf' not found in ModelManager.")