How to use the ward.models.WardMeta function in ward

To help you get started, we’ve selected a few ward examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github darrenburns / ward / ward / testing.py View on Github external
def decorator_test(func):
        mod_name = func.__module__

        force_path = kwargs.get("_force_path")
        if force_path:
            path = force_path
        else:
            path = Path(inspect.getfile(func)).absolute()

        if hasattr(func, "ward_meta"):
            func.ward_meta.description = description
            func.ward_meta.path = path
        else:
            func.ward_meta = WardMeta(
                description=description,
                path=path,
            )

        collect_into = kwargs.get("_collect_into")
        if collect_into is not None:
            collect_into[mod_name].append(func)
        else:
            anonymous_tests[mod_name].append(func)

        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            return func(*args, **kwargs)

        return wrapper
github darrenburns / ward / ward / testing.py View on Github external
def skip(func_or_reason=None, *, reason: str = None):
    if func_or_reason is None:
        return functools.partial(skip, reason=reason)

    if isinstance(func_or_reason, str):
        return functools.partial(skip, reason=func_or_reason)

    func = func_or_reason
    marker = SkipMarker(reason=reason)
    if hasattr(func, "ward_meta"):
        func.ward_meta.marker = marker
    else:
        func.ward_meta = WardMeta(marker=marker)

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        return func(*args, **kwargs)

    return wrapper
github darrenburns / ward / ward / testing.py View on Github external
def xfail(func_or_reason=None, *, reason: str = None):
    if func_or_reason is None:
        return functools.partial(xfail, reason=reason)

    if isinstance(func_or_reason, str):
        return functools.partial(xfail, reason=func_or_reason)

    func = func_or_reason
    marker = XfailMarker(reason=reason)
    if hasattr(func, "ward_meta"):
        func.ward_meta.marker = marker
    else:
        func.ward_meta = WardMeta(marker=marker)

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        return func(*args, **kwargs)

    return wrapper
github darrenburns / ward / ward / fixtures.py View on Github external
def fixture(func=None, *, scope: Optional[Union[Scope, str]] = Scope.Test):
    if not isinstance(scope, Scope):
        scope = Scope.from_str(scope)

    if func is None:
        return partial(fixture, scope=scope)

    # By setting is_fixture = True, the framework will know
    # that if this fixture is provided as a default arg, it
    # is responsible for resolving the value.
    path = Path(inspect.getfile(func)).absolute()
    if hasattr(func, "ward_meta"):
        func.ward_meta.is_fixture = True
        func.ward_meta.path = path
    else:
        func.ward_meta = WardMeta(
            is_fixture=True,
            scope=scope,
            path=path,
        )

    @wraps(func)
    def wrapper(*args, **kwargs):
        return func(*args, **kwargs)

    return wrapper
github darrenburns / ward / ward / collect.py View on Github external
if anon_tests:
            for test_fn in anon_tests:
                meta: WardMeta = getattr(test_fn, "ward_meta")
                yield Test(
                    fn=test_fn,
                    module_name=mod_name,
                    marker=meta.marker,
                    description=meta.description or "",
                )

        # Collect named tests from the module
        for item in dir(mod):
            if item.startswith("test_") and not item == "_":
                test_name = item
                test_fn = getattr(mod, test_name)
                marker: Marker = getattr(test_fn, "ward_meta", WardMeta()).marker
                if test_fn:
                    yield Test(fn=test_fn, module_name=mod_name, marker=marker)
github darrenburns / ward / ward / fixtures.py View on Github external
def decorator_using(func):
        signature = inspect.signature(func)
        bound_args = signature.bind_partial(*using_args, **using_kwargs)
        if hasattr(func, "ward_meta"):
            func.ward_meta.bound_args = bound_args
        else:
            func.ward_meta = WardMeta(bound_args=bound_args)

        @wraps(func)
        def wrapper(*args, **kwargs):
            return func(*args, **kwargs)

        return wrapper