Esempio n. 1
0
    def test2(self):
        """testing that the ModelManager will return the same instance of an MLModel class from several different
        instances of ModelManager"""
        # arrange
        # instantiating the model manager class
        first_model_manager = ModelManager()

        # loading the MLModel objects from configuration
        first_model_manager.load_models(
            configuration=[{
                "module_name": "tests.model_manager_test",
                "class_name": "MLModelMock"
            }])

        # act
        first_model_object = first_model_manager.get_model(
            qualified_name="iris_model")

        # instantiating the ModelManager class again
        second_model_manager = ModelManager()

        second_model_object = second_model_manager.get_model(
            qualified_name="iris_model")

        # assert
        self.assertTrue(str(first_model_object) == str(second_model_object))
Esempio n. 2
0
    def test1(self):
        """ testing the load_models() method """
        # arrange
        # instantiating the model manager class
        model_manager = ModelManager()
        # loading the MLModel objects from configuration
        model_manager.load_models(configuration=[{
            "module_name": "tests.model_manager_test",
            "class_name": "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)
    def __init__(self, model_qualified_name):
        """Create a ZeroRPC endpoint for a model.

        :param model_qualified_name: The qualified name of the model that will be hosted in this endpoint.
        :type model_qualified_name: str
        :returns: An instance of MLModelZeroRPCCEndpoint.
        :rtype: MLModelZeroRPCCEndpoint

        """
        model_manager = ModelManager()

        model_instance = model_manager.get_model(model_qualified_name)

        if model_instance is None:
            raise ValueError("'{}' not found in ModelManager instance.".format(
                model_qualified_name))

        self._model = model_manager.get_model(model_qualified_name)

        # overriding the docstring of the object
        self.__doc__ = "Predict with the {}.".format(self._model.display_name)

        logger.info("Initializing endpoint for model: {}".format(
            self._model.qualified_name))
Esempio n. 4
0
    def test4(self):
        """ testing that the ModelManager returns None when a model is not found """
        # arrange
        model_manager = ModelManager()
        model_manager.load_models(configuration=[{
            "module_name": "tests.model_manager_test",
            "class_name": "MLModelMock"
        }])

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

        # assert
        self.assertFalse(exception_raised)
        self.assertTrue(model is None)