import functools


def raise_if_no_attrs(f):
    """
    A helper for PatchTestCase test methods that will check if there are any
    modules to use else raise a NotImplementedError.

    :param f: method to wrap with a check
    """
    required_attrs = [
        '__module_name__',
        '__integration_name__',
        '__patch_func__',
    ]

    @functools.wraps(f)
    def checked_method(self, *args, **kwargs):
        if getattr(self, '__unpatch_func__') is None:
            return

        for attr in required_attrs:
            if not getattr(self, attr):
                raise NotImplementedError(f.__doc__)
        return f(self, *args, **kwargs)
    return checked_method