def assert_warns(warning_class, func, *args, **kw):
<EOL>clean_warning_registry()<EOL>with warnings.catch_warnings(record=True) as w:<EOL><INDENT>warnings.simplefilter("<STR_LIT>")<EOL>result = func(*args, **kw)<EOL>if hasattr(np, '<STR_LIT>'):<EOL><INDENT>w = [e for e in w<EOL>if e.category is not np.VisibleDeprecationWarning]<EOL><DEDENT>if not len(w) > <NUM_LIT:0>:<EOL><INDENT>raise AssertionError("<STR_LIT>"<EOL>% func.__name__)<EOL><DEDENT>found = any(warning.category is warning_class for warning in w)<EOL>if not found:<EOL><INDENT>raise AssertionError("<STR_LIT>"<EOL>% (func.__name__, warning_class, w))<EOL><DEDENT><DEDENT>return result<EOL>
Test that a certain warning occurs.
    Parameters
    ----------
    warning_class : the warning class
        The class to test for, e.g. UserWarning.
    func : callable
        Calable object to trigger warnings.
    *args : the positional arguments to `func`.
    **kw : the keyword arguments to `func`
    Returns
    -------
    result : the return value of `func`