MCPcopy
hub / github.com/numpy/numpy / assert_raises

Function assert_raises

numpy/testing/_private/utils.py:1508–1534  ·  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

1506
1507
1508def assert_raises(*args, **kwargs):
1509 """
1510 assert_raises(exception_class, callable, *args, **kwargs)
1511 assert_raises(exception_class)
1512
1513 Fail unless an exception of class exception_class is thrown
1514 by callable when invoked with arguments args and keyword
1515 arguments kwargs. If a different type of exception is
1516 thrown, it will not be caught, and the test case will be
1517 deemed to have suffered an error, exactly as for an
1518 unexpected exception.
1519
1520 Alternatively, `assert_raises` can be used as a context manager:
1521
1522 >>> from numpy.testing import assert_raises
1523 >>> with assert_raises(ZeroDivisionError):
1524 ... 1 / 0
1525
1526 is equivalent to
1527
1528 >>> def div(x, y):
1529 ... return x / y
1530 >>> assert_raises(ZeroDivisionError, div, 1, 0)
1531
1532 """
1533 __tracebackhide__ = True # Hide traceback for py.test
1534 return _d.assertRaises(*args, **kwargs)
1535
1536
1537def 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…