summaryrefslogtreecommitdiff
path: root/numpy/testing/tests/test_utils.py
diff options
context:
space:
mode:
authorNathaniel J. Smith <njs@pobox.com>2012-09-20 22:02:18 +0100
committerNathaniel J. Smith <njs@pobox.com>2012-09-20 22:02:18 +0100
commit47086158cb00a151b67c442ae759ce230ec0de34 (patch)
tree275dc7e5b2a2d9fa3b17a119417c34f3f48f19a4 /numpy/testing/tests/test_utils.py
parent9597b1fdef7c46b0d1b1485fb680099ec7115f76 (diff)
downloadnumpy-47086158cb00a151b67c442ae759ce230ec0de34.tar.gz
ENH: More capable test functions for warnings
1) New function assert_no_warnings 2) Make assert_warns and assert_no_warnings pass through the function's return value on success, so that it can be checked as well.
Diffstat (limited to 'numpy/testing/tests/test_utils.py')
-rw-r--r--numpy/testing/tests/test_utils.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py
index bff8b50ab..23b2f8e7b 100644
--- a/numpy/testing/tests/test_utils.py
+++ b/numpy/testing/tests/test_utils.py
@@ -317,11 +317,15 @@ class TestWarns(unittest.TestCase):
def test_warn(self):
def f():
warnings.warn("yo")
+ return 3
before_filters = sys.modules['warnings'].filters[:]
- assert_warns(UserWarning, f)
+ assert_equal(assert_warns(UserWarning, f), 3)
after_filters = sys.modules['warnings'].filters
+ assert_raises(AssertionError, assert_no_warnings, f)
+ assert_equal(assert_no_warnings(lambda x: x, 1), 1)
+
# Check that the warnings state is unchanged
assert_equal(before_filters, after_filters,
"assert_warns does not preserver warnings state")