diff options
author | Seth Troisi <sethtroisi@google.com> | 2020-06-01 00:11:05 -0700 |
---|---|---|
committer | Seth Troisi <sethtroisi@google.com> | 2020-06-01 00:11:05 -0700 |
commit | ff5680a0298251d8df7958f47032ac02cdea80e3 (patch) | |
tree | c7f02b19342456293b94ad4691b711d5ea36143b /numpy/testing/_private/utils.py | |
parent | 5a4140d722117afc89869d5772ddd7a67448cfbc (diff) | |
download | numpy-ff5680a0298251d8df7958f47032ac02cdea80e3.tar.gz |
DOC: Improve assert_warns docstring with example
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r-- | numpy/testing/_private/utils.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index f8789af90..ef623255b 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -1768,15 +1768,28 @@ def assert_warns(warning_class, *args, **kwargs): ---------- warning_class : class The class defining the warning that `func` is expected to throw. - \\*args : List of function and arguments - `func` and arguments for `func`. - \\*\\*kwargs : Kwargs + func : callable, optional + Callable to test + *args : Arguments + Arguments for `func`. + **kwargs : Kwargs Keyword arguments for `func`. Returns ------- The value returned by `func`. + Examples + -------- + >>> import warnings + >>> def deprecated_func(num): + ... warnings.warn("Please upgrade", DeprecationWarning) + ... return num*num + >>> with np.testing.assert_warns(DeprecationWarning): + ... assert deprecated_func(4) == 16 + >>> # or passing a func + >>> ret = np.testing.assert_warns(DeprecationWarning, deprecated_func, 4) + >>> assert ret == 16 """ if not args: return _assert_warns_context(warning_class) |