def __configure_core_element__(self, kwargs, user_function): # type: (dict, ...) -> None """ Include the registering info related to @implement. IMPORTANT! Updates self.kwargs[CORE_ELEMENT_KEY]. :param kwargs: Keyword arguments received from call. :param user_function: Decorated function. :return: None """ if __debug__: logger.debug("Configuring @implement core element.") # Resolve @implement specific parameters if 'sourceClass' in self.kwargs: another_class = self.kwargs['sourceClass'] self.kwargs['source_class'] = self.kwargs.pop('sourceClass') else: another_class = self.kwargs['source_class'] another_method = self.kwargs['method'] ce_signature = '.'.join((another_class, another_method)) impl_type = "METHOD" # impl_args = [another_class, another_method] - set by @task if CORE_ELEMENT_KEY in kwargs: # Core element has already been created in a higher level decorator # (e.g. @constraint) kwargs[CORE_ELEMENT_KEY].set_ce_signature(ce_signature) kwargs[CORE_ELEMENT_KEY].set_impl_type(impl_type) # @task sets the implementation type arguments # kwargs[CORE_ELEMENT_KEY].set_impl_type_args(impl_args) else: # @implement is in the top of the decorators stack. # Instantiate a new core element object, update it and include # it into kwarg core_element = CE() core_element.set_ce_signature(ce_signature) core_element.set_impl_type(impl_type) # @task sets the implementation type arguments # core_element.set_impl_type_args(impl_args) kwargs[CORE_ELEMENT_KEY] = core_element # Set as configured self.core_element_configured = True
def test_core_element(): signature = "my_signature" impl_signature = "my_impl_signature" impl_constraints = "impl_constraints" impl_type = "impl_type" impl_io = "impl_io" impl_type_args = "impl_type_args" core_element = CE(signature, impl_signature, impl_constraints, impl_type, impl_io, impl_type_args) # Check signature result = core_element.get_ce_signature() assert result == signature, ERROR_SIGNATURE new_signature = "my_new_signature" core_element.set_ce_signature(new_signature) result = core_element.get_ce_signature() assert result == new_signature, ERROR_SIGNATURE # Check impl_signature result = core_element.get_impl_signature() assert result == impl_signature, ERROR_IMPL_SIGNATURE new_impl_signature = "my_new_impl_signature" core_element.set_impl_signature(new_impl_signature) result = core_element.get_impl_signature() assert result == new_impl_signature, ERROR_IMPL_SIGNATURE # Check impl_constraints result = core_element.get_impl_constraints() assert result == impl_constraints, ERROR_IMPL_CONSTRAINTS new_impl_constraints = {"my_new_impl_constraints": "value"} core_element.set_impl_constraints(new_impl_constraints) result = core_element.get_impl_constraints() assert result == new_impl_constraints, ERROR_IMPL_CONSTRAINTS # Check impl_type result = core_element.get_impl_type() assert result == impl_type, ERROR_IMPL_TYPE new_impl_type = "my_new_impl_type" core_element.set_impl_type(new_impl_type) result = core_element.get_impl_type() assert result == new_impl_type, ERROR_IMPL_TYPE # Check impl_io result = core_element.get_impl_io() assert result == impl_io, ERROR_IMPL_IO new_impl_io = "my_new_impl_io" core_element.set_impl_io(new_impl_io) result = core_element.get_impl_io() assert result == new_impl_io, ERROR_IMPL_IO # Check impl_type_args result = core_element.get_impl_type_args() assert result == impl_type_args, ERROR_IMPL_TYPE_ARGS new_impl_type_args = "my_new_impl_type_args" core_element.set_impl_type_args(new_impl_type_args) result = core_element.get_impl_type_args() assert result == new_impl_type_args, ERROR_IMPL_TYPE_ARGS # Check representation representation = core_element.__repr__() assert isinstance(representation, str), "ERROR: Received wrong representation type." # noqa: E501 expected = "CORE ELEMENT: \n" \ "\t - CE signature : my_new_signature\n" \ "\t - Impl. signature : my_new_impl_signature\n" \ "\t - Impl. constraints: my_new_impl_constraints:value;\n" \ "\t - Impl. type : my_new_impl_type\n" \ "\t - Impl. io : my_new_impl_io\n" \ "\t - Impl. type args : my_new_impl_type_args" assert representation == expected, "ERROR: Wrong representation." # Reset core_element.reset() # Check again representation representation = core_element.__repr__() assert isinstance(representation, str), "ERROR: Received wrong representation type." # noqa: E501 expected = "CORE ELEMENT: \n" \ "\t - CE signature : None\n" \ "\t - Impl. signature : None\n" \ "\t - Impl. constraints: None\n" \ "\t - Impl. type : None\n" \ "\t - Impl. io : None\n" \ "\t - Impl. type args : None" assert representation == expected, "ERROR: Wrong empty representation."