Example #1
0
def test_append_var_to_docs():
    def foo():
        """some

        docstring"""
        pass

    append_var_to_docs(foo, 'My Var', [1, 2, 3, 4])
    assert foo.__doc__ == """some
Example #2
0
    def decorator(fn):
        append_var_to_docs(fn, "Return datatype (iterator of)", dfn)

        @wraps(fn)
        def wrapped_function(*args, **kwargs):
            for value in fn(*args, **kwargs):
                fails = failures(dfn, value)
                if fails:
                    if strict or _get_bad_values(fails):
                        raise BadReturnValueError(fails)
                    else:
                        logger.warning(fails)

                yield value
        return wrapped_function
Example #3
0
    def decorator(fn):

        # Add return-datatype info to function doc-block
        append_var_to_docs(fn, "Return datatype", dfn)

        @wraps(fn)
        def wrapped_function(*args, **kwargs):
            ret = fn(*args, **kwargs)

            # Check for failure and raise
            fails = failures(dfn, ret)
            if fails:
                if strict or _get_bad_values(fails):
                    raise BadReturnValueError(fails)
                else:
                    logger.warning(fails)

            # All is well, return as usual
            return ret
        return wrapped_function