コード例 #1
0
ファイル: test_implem.py プロジェクト: IKATS/ikats-pybase
    def setUpTestData(cls):
        """
        setUpClass: this setup is made once for several tests_ methods

        operational database is not impacted by the Django unittests
        """
        # init logger with CommonsUnittest service
        cls.init_logger()

        cls.arg_one = Argument("angle", "angle (rad)", ProfileItem.DIR.INPUT,
                               0)
        cls.res_one = Argument("result", "cos(angle)", ProfileItem.DIR.OUTPUT,
                               0)
        cls.res_two = Argument("result", "sin(angle)", ProfileItem.DIR.OUTPUT,
                               0)
        cls.res_three = Argument("result", "tan(angle)",
                                 ProfileItem.DIR.OUTPUT, 0)

        cls.my_cosinus = Implementation(
            "TU ORM Python Standard cosinus", "Python cosinus from math::cos",
            "apps.algo.execute.models.business.python_local_exec_engine::PythonLocalExecEngine",
            "math::cos", [cls.arg_one], [cls.res_one])

        cls.my_sinus = Implementation(
            "TU ORM Python Standard sinus", "Python sinus from math::sin",
            "apps.algo.execute.models.business.python_local_exec_engine::PythonLocalExecEngine",
            "math::sin", [cls.arg_one], [cls.res_two])

        cls.my_tan = Implementation(
            "TU ORM Python Standard tan", "Python tan from math::tan",
            "apps.algo.execute.models.business.python_local_exec_engine::PythonLocalExecEngine",
            "math::tan", [cls.arg_one], [cls.res_three])
コード例 #2
0
    def setUpTestData(cls):
        """
        setUpClass: this setup is made once for several tests_ methods

        operational database is not impacted by the Django unittests
        """
        cls.init_tu()
        arg_one = Argument("angle", "angle (rad)", ProfileItem.DIR.INPUT, 0)
        res_one = Argument("result", "cos(angle)", ProfileItem.DIR.OUTPUT, 0)

        cls.my_cosinus = Implementation(
            "TU WS Python Standard cosinus", "Python cosinus from math::cos",
            "apps.algo.execute.models.business.python_local_exec_engine::PythonLocalExecEngine",
            "math::cos", [arg_one], [res_one])
コード例 #3
0
    def test_output_profile(self):
        """
        Tests the output_profile method
        """

        profile1 = Parameter(name="param",
                             description="description of the new param",
                             direction=Parameter.DIR.OUTPUT,
                             order_index=0,
                             data_format='String',
                             domain_of_values='*',
                             db_id=1)

        profile2 = Argument(name="arg",
                            description="description of the new arg",
                            direction=Argument.DIR.OUTPUT,
                            order_index=1,
                            data_format='Int',
                            domain_of_values='*',
                            db_id=1)

        try:
            imp = Implementation('Name_of_my_implementation',
                                 'description of my implementation',
                                 'Execution_plugin_name',
                                 'library/address/',
                                 output_profile=[profile1, profile2])
        except TypeError:
            self.fail("output_profile raised TypeError unexpectedly!")

        # Testing output_profile as a non-list
        with self.assertRaises(TypeError):
            imp.output_profile = "A list is expected here"

        # Trying to add Output in output_profile list
        profile1.direction = ProfileItem.DIR.INPUT
        with self.assertRaises(ValueError):
            imp.output_profile = [profile1, profile2]

        # Trying another case for adding Output in output_profile list
        profile1.direction = ProfileItem.DIR.OUTPUT
        profile2.direction = ProfileItem.DIR.INPUT
        with self.assertRaises(ValueError):
            imp.output_profile = [profile1, profile2]

        # Sorting
        profile2.direction = ProfileItem.DIR.OUTPUT
        imp.output_profile = [profile2, profile1]
        self.assertEquals(imp.output_profile, [profile1, profile2])
コード例 #4
0
    def setUpTestData(cls):
        """
        setUpClass: this setup is made once for several tests_ methods

        operational database is not impacted by the Django unittests
        """
        cls.init_logger()
        cls.info("Start: setUpTestData on TestCustomizedParameter")
        try:
            arg_one = Argument("angle", "angle (rad)", ProfileItem.DIR.INPUT, 0)
            param_factor = Parameter("factor", "factor on angle", ProfileItem.DIR.INPUT, 1)
            param_phase = Parameter(name="phase", description="added phase constant",
                                    direction=ProfileItem.DIR.INPUT, order_index=2,
                                    db_id=None,
                                    data_format="number",
                                    domain_of_values=None,
                                    label="phase",
                                    default_value="0")

            cls.res_one = Argument("result", "cos(angle)", ProfileItem.DIR.OUTPUT, 0)
            cls.res_two = Argument("result", "sin(angle)", ProfileItem.DIR.OUTPUT, 0)
            cls.res_three = Argument("result", "tan(angle)", ProfileItem.DIR.OUTPUT, 0)

            res_four = Argument("result", "tan(factor*angle+phase)", ProfileItem.DIR.OUTPUT, 0)

            cls.my_pseudo_impl = Implementation(
                "TU ORM impl for CustomizedAlgo", "Python tan from math::my_tan",
                "apps.algo.execute.models.business.python_local_exec_engine::PythonLocalExecEngine",
                "math::my_tan_tri", [arg_one, param_factor, param_phase], [res_four])

            # Implementation created in DB => this one will be tested
            #
            cls.my_pseudo_impl_from_db = ImplementationDao.create(cls.my_pseudo_impl)
            cls.my_arg_one = cls.my_pseudo_impl_from_db.find_by_name_input_item("angle")
            cls.my_param_factor = cls.my_pseudo_impl_from_db.find_by_name_input_item("factor")
            cls.my_param_phase = cls.my_pseudo_impl_from_db.find_by_name_input_item("phase")

            cls.info("setUpTestData initialized implem= {}".format(cls.my_pseudo_impl_from_db))
            cls.info("setUpTestData initialized arg_one= {}".format(cls.my_arg_one))
            cls.info("setUpTestData initialized param_factor= {}".format(cls.my_param_factor))
            cls.info("setUpTestData initialized param_phase= {}".format(cls.my_param_phase))

        except Exception as err:
            cls.logger().exception("got exception type=" + type(err).__name__)
            cls.logger().exception("exception as str=" + str(err))
            cls.error("... ended setUpTestData TestCustomizedParameter: Failed: %s")

        cls.info("End: setUpTestData on TestCustomizedParameter")
コード例 #5
0
ファイル: profile.py プロジェクト: IKATS/ikats-pybase
    def build_business(self):
        """
        From the ORM object, this method will create the corresponding biz object.
        :return: The business object
        """
        if self.is_parameter():
            if (self.default_value is None) or (len(self.default_value) == 0):
                decoded_default_value = None
            else:
                # From DB: str encoded JSON => loaded into python object
                decoded_default_value = json.loads(self.default_value)

            return Parameter(name=self.name,
                             description=self.desc,
                             direction=self.direction,
                             order_index=self.order_index,
                             db_id=self.id,
                             data_format=self.data_format,
                             domain_of_values=self.domain_of_values,
                             label=self.label,
                             default_value=decoded_default_value)
        else:
            # Presently: default_value is not handled for arguments
            return Argument(name=self.name,
                            description=self.desc,
                            direction=self.direction,
                            order_index=self.order_index,
                            db_id=self.id,
                            data_format=self.data_format,
                            domain_of_values=self.domain_of_values,
                            label=self.label)
コード例 #6
0
    def build_temp_data_manager_arg():
        """
        Build the private argument typed TEMPORAL_DATA_MANAGER_ARGTYPE

        HYP: always the first argument
        """

        return Argument(
            name=FactoryCatalogue.TEMPORAL_DATA_MANAGER_ARGTYPE,
            description=
            "temporal_data_manager is a singleton initialized on server side",
            direction=ProfileItem.DIR.INPUT,
            order_index=0,
            db_id=None,
            data_format=FactoryCatalogue.TEMPORAL_DATA_MANAGER_ARGTYPE,
            domain_of_values=None)
コード例 #7
0
ファイル: tu_commons.py プロジェクト: IKATS/ikats-pybase
    def prepare_catalogue_data(cls):
        """
        this setup is made once for several tests_ methods

        operational database is not impacted by the Django unittests
        """
        cls.init_logger()
        if cls.cat_initialized is False:
            cls.cat_initialized = True
            cls.info("Start: prepareCatalogueData on {}".format(cls.__name__))
            t_name = cls.__name__
            try:

                my_fam = FunctionalFamily(name=t_name + " tested family",
                                          description="",
                                          db_id=None,
                                          label="lab family")
                my_algo = Algorithm(name=t_name + "my algo",
                                    description=" desc",
                                    db_id=None,
                                    label="lab",
                                    family=my_fam)

                cls.arg_one = Argument("angle", "angle (rad)",
                                       ProfileItem.DIR.INPUT, 0)
                cls.param_factor = Parameter("factor", "factor on angle",
                                             ProfileItem.DIR.INPUT, 1)
                cls.param_factor.data_format = "number"

                cls.param_phase = Parameter(name="phase",
                                            description="added phase constant",
                                            direction=ProfileItem.DIR.INPUT,
                                            order_index=2,
                                            db_id=None,
                                            data_format="number",
                                            domain_of_values=None,
                                            label="phase",
                                            default_value=0)

                cls.param_phase_with_domain = Parameter(
                    name="phase",
                    description="added phase constant",
                    direction=ProfileItem.DIR.INPUT,
                    order_index=2,
                    db_id=None,
                    data_format="number",
                    domain_of_values="[0, 1.1, 2 ]",
                    label="phase with constraint",
                    default_value=0)

                cls.res_one = Argument("result", "cos(angle)",
                                       ProfileItem.DIR.OUTPUT, 0)
                cls.res_two = Argument("result", "sin(angle)",
                                       ProfileItem.DIR.OUTPUT, 0)
                cls.res_three = Argument("result", "tan(angle)",
                                         ProfileItem.DIR.OUTPUT, 0)

                cls.res_four = Argument("result", "tan(factor*angle+phase)",
                                        ProfileItem.DIR.OUTPUT, 0)

                cls.my_cosinus = Implementation(
                    t_name + " ORM Python Standard cosinus",
                    "Python cosinus from math::cos",
                    "apps.algo.execute.models.business.python_local_exec_engine::PythonLocalExecEngine",
                    "math::cos", [cls.arg_one], [cls.res_one])

                cls.my_sinus = Implementation(
                    t_name + " ORM Python Standard sinus",
                    "Python sinus from math::sin",
                    "apps.algo.execute.models.business.python_local_exec_engine::PythonLocalExecEngine",
                    "math::sin", [cls.arg_one], [cls.res_two])

                cls.my_tan = Implementation(
                    t_name + " ORM Python Standard tan",
                    "Python tan from math::tan",
                    "apps.algo.execute.models.business.python_local_exec_engine::PythonLocalExecEngine",
                    "math::tan", [cls.arg_one], [cls.res_three])

                cls.my_pseudo_impl = Implementation(
                    t_name + " ORM impl for CustomizedAlgo",
                    "Python tan from math::my_tan",
                    "apps.algo.execute.models.business.python_local_exec_engine::PythonLocalExecEngine",
                    "ikats.processing.ikats_processing.tests.test_contrib::my_tan",
                    [cls.arg_one, cls.param_factor, cls.param_phase],
                    [cls.res_four],
                    algo=my_algo)

                cls.my_pseudo_impl_with_domain = Implementation(
                    t_name + " ORM impl2 for CustomizedAlgo",
                    "Python tan from math::my_tan_bis",
                    "apps.algo.execute.models.business.python_local_exec_engine::PythonLocalExecEngine",
                    "ikats.processing.ikats_processing.tests.test_contrib::my_tan_bis",
                    [
                        cls.arg_one, cls.param_factor,
                        cls.param_phase_with_domain
                    ], [cls.res_four],
                    algo=my_algo)

                # Implementation created in DB => this one will be tested
                #
                cls.my_pseudo_impl_from_db = ImplementationDao.create(
                    cls.my_pseudo_impl)
                cls.my_arg_one = cls.my_pseudo_impl_from_db.find_by_name_input_item(
                    "angle")
                cls.my_param_factor = cls.my_pseudo_impl_from_db.find_by_name_input_item(
                    "factor")
                cls.my_param_phase = cls.my_pseudo_impl_from_db.find_by_name_input_item(
                    "phase")

                cls.info(
                    "prepare_catalogue_data initialized implem= {}".format(
                        cls.my_pseudo_impl_from_db))
                cls.info(
                    "prepare_catalogue_data initialized arg_one= {}".format(
                        cls.my_arg_one))
                cls.info("prepare_catalogue_data initialized param_factor= {}".
                         format(cls.my_param_factor))
                cls.info("prepare_catalogue_data initialized param_phase= {}".
                         format(cls.my_param_phase))

                cls.my_pseudo_impl_with_domain_from_db = ImplementationDao.create(
                    cls.my_pseudo_impl_with_domain)
                cls.my_arg_one_bis = cls.my_pseudo_impl_with_domain_from_db.find_by_name_input_item(
                    "angle")
                cls.my_param_factor_bis = cls.my_pseudo_impl_with_domain_from_db.find_by_name_input_item(
                    "factor")
                cls.my_param_phase_bis = cls.my_pseudo_impl_with_domain_from_db.find_by_name_input_item(
                    "phase")

                cls.info(
                    "prepare_catalogue_data my_pseudo_impl_with_domain_from_db= {}"
                    .format(cls.my_pseudo_impl_with_domain_from_db))
                cls.info("prepare_catalogue_data my_arg_one_bis= {}".format(
                    cls.my_arg_one_bis))
                cls.info(
                    "prepare_catalogue_data my_param_factor_bis= {}".format(
                        cls.my_param_factor_bis))
                cls.info(
                    "prepare_catalogue_data my_param_phase_bis= {}".format(
                        cls.my_param_phase_bis))

                cls.info("End: prepare_catalogue_data on {}".format(
                    cls.__name__))

            except Exception as err:
                cls.logger().exception("got exception type=" +
                                       type(err).__name__)
                cls.logger().exception("exception as str=" + str(err))
                cls.error("... ended prepare_catalogue_data {}: Failed".format(
                    cls.__name__))
コード例 #8
0
    def test_input_profile(self):
        """
        Tests the input_profile method cases
        """

        profile1 = Parameter(name="param",
                             description="description of the new param",
                             direction=Parameter.DIR.INPUT,
                             order_index=0,
                             data_format='String',
                             domain_of_values='*',
                             db_id=1)

        profile2 = Argument(name="arg",
                            description="description of the new arg",
                            direction=Argument.DIR.INPUT,
                            order_index=1,
                            data_format='Int',
                            domain_of_values='*',
                            db_id=1)

        try:
            imp = Implementation('Name_of_my_implementation',
                                 'description of my implementation',
                                 'Execution_plugin_name',
                                 'library/address/',
                                 input_profile=[profile1, profile2])
        except TypeError:
            self.fail("input_profile raised TypeError unexpectedly!")

        # Testing input_profile as a non-list
        with self.assertRaises(TypeError):
            imp.input_profile = "A list is expected here"

        # Trying to add Output in Input_profile list
        profile1.direction = Parameter.DIR.OUTPUT
        with self.assertRaises(ValueError):
            imp.input_profile = [profile1, profile2]

        # Trying another case for adding Output in Input_profile list
        profile1.direction = Parameter.DIR.INPUT
        profile2.direction = Parameter.DIR.OUTPUT
        with self.assertRaises(ValueError):
            imp.input_profile = [profile1, profile2]

        # Sorting
        profile2.direction = Parameter.DIR.INPUT
        imp.input_profile = [profile2, profile1]
        self.assertEquals(imp.input_profile, [profile1, profile2])

        # Finding inputs ...
        # ... among Arguments or Parameters
        item1 = imp.find_by_name_input_item("param")
        self.assertEquals(profile1, item1)
        item2 = imp.find_by_name_input_item("arg")
        self.assertEquals(profile2, item2)
        # ... only among Arguments
        item3 = imp.find_by_name_input_item("param", accepted_type=Argument)
        self.assertEquals(None, item3)
        item4 = imp.find_by_name_input_item("arg", accepted_type=Argument)
        self.assertEquals(profile2, item4)
        # ... only among Parameters
        item5 = imp.find_by_name_input_item("param", accepted_type=Parameter)
        self.assertEquals(profile1, item5)
        item6 = imp.find_by_name_input_item("arg", accepted_type=Parameter)
        self.assertEquals(None, item6)

        # ... mismatched name
        item7 = imp.find_by_name_input_item("mismatched_name")
        self.assertEquals(None, item7)