Example #1
0
    def __configure_core_element__(self, kwargs):  # noqa
        # type: (dict) -> None
        """ Include the registering info related to @IO.

        IMPORTANT! Updates self.kwargs[CORE_ELEMENT_KEY].

        :param kwargs: Keyword arguments received from call.
        :return: None
        """
        if __debug__:
            logger.debug("Configuring @IO core element.")

        # Resolve @io specific parameters

        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_impl_io(True)
        else:
            # @binary 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_impl_io(True)
            kwargs[CORE_ELEMENT_KEY] = core_element
Example #2
0
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."