MCPcopy Create free account
hub / github.com/numpy/numpy / assert_raises

Function assert_raises

numpy/testing/_private/utils.py:1269–1295  ·  view source on GitHub ↗

assert_raises(exception_class, callable, *args, **kwargs) assert_raises(exception_class) Fail unless an exception of class exception_class is thrown by callable when invoked with arguments args and keyword arguments kwargs. If a different type of exception is thrown, it wil

(*args, **kwargs)

Source from the content-addressed store, hash-verified

1267
1268
1269def assert_raises(*args, **kwargs):
1270 """
1271 assert_raises(exception_class, callable, *args, **kwargs)
1272 assert_raises(exception_class)
1273
1274 Fail unless an exception of class exception_class is thrown
1275 by callable when invoked with arguments args and keyword
1276 arguments kwargs. If a different type of exception is
1277 thrown, it will not be caught, and the test case will be
1278 deemed to have suffered an error, exactly as for an
1279 unexpected exception.
1280
1281 Alternatively, `assert_raises` can be used as a context manager:
1282
1283 >>> from numpy.testing import assert_raises
1284 >>> with assert_raises(ZeroDivisionError):
1285 ... 1 / 0
1286
1287 is equivalent to
1288
1289 >>> def div(x, y):
1290 ... return x / y
1291 >>> assert_raises(ZeroDivisionError, div, 1, 0)
1292
1293 """
1294 __tracebackhide__ = True # Hide traceback for py.test
1295 return _d.assertRaises(*args, **kwargs)
1296
1297
1298def assert_raises_regex(exception_class, expected_regexp, *args, **kwargs):

Callers 15

test_seedsequenceFunction · 0.90
test_seed_float_arrayMethod · 0.90
test_invalid_scalarMethod · 0.90
test_invalid_arrayMethod · 0.90
test_cannot_seedMethod · 0.90
test_p_is_nanMethod · 0.90
test_sizeMethod · 0.90
test_invalid_probMethod · 0.90
test_invalid_nMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_seedsequenceFunction · 0.72
test_seed_float_arrayMethod · 0.72
test_invalid_scalarMethod · 0.72
test_invalid_arrayMethod · 0.72
test_cannot_seedMethod · 0.72
test_p_is_nanMethod · 0.72
test_sizeMethod · 0.72
test_invalid_probMethod · 0.72
test_invalid_nMethod · 0.72