Example #1
0
def mock_op(name="", exception=None) -> Op:
    if exception is not None:
        operation = op(
            MagicMock(__name__=name,
                      return_value=f"{name}_return_value",
                      side_effect=exception))
    else:
        operation = op(
            MagicMock(__name__=name, return_value=f"{name}_return_value"))
    operation.arg_requirements = MagicMock(
        return_value=MockReq("Arg requirement"))

    return operation
Example #2
0
    def test_string_representation():
        mocked_function = MagicMock(__name__="function")
        mocked_op = op(mocked_function)
        variable = Variable(name="input")

        result = mocked_op.op(arg=variable)

        assert str(result) == "function(arg=input)"
Example #3
0
    def test_invokes_function_if_args_invariable():
        mocked_function = MagicMock(return_value="Return value")
        mocked_operation = op(mocked_function)

        return_value = mocked_operation(a=1, b="b")

        mocked_function.assert_called_once_with(a=1, b="b")
        assert return_value == "Return value"
Example #4
0
    def test_returns_variable_if_some_arg_variable():
        mocked_function = MagicMock(return_value="Return value")
        mocked_op = op(mocked_function)

        input_var = Variable("input")
        return_var = mocked_op(a=1, b=input_var)

        assert not mocked_function.called
        assert isinstance(return_var, Variable)
        assert return_var.dependencies == {"b": input_var}
Example #5
0
    def exec_module(cls, module):
        if module.__name__ == "paragraph.wrap":
            # module.__path__ is required, but may be just an empty list
            module.__path__ = []
            return module

        inner_module_path = module.__name__.split(".", maxsplit=2)[2]
        inner_module = import_module(inner_module_path)

        for func_name in dir(inner_module):
            func = getattr(inner_module, func_name)
            if isinstance(func, Callable):
                module.__dict__[func_name] = op(func)

        module.__path__ = []

        return module