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

Function test_suppress_warnings_forwarding

numpy/testing/tests/test_utils.py:1463–1507  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1461
1462
1463def test_suppress_warnings_forwarding():
1464 def warn_other_module():
1465 # Apply along axis is implemented in python; stacklevel=2 means
1466 # we end up inside its module, not ours.
1467 def warn(arr):
1468 warnings.warn("Some warning", stacklevel=2)
1469 return arr
1470 np.apply_along_axis(warn, 0, [0])
1471
1472 with suppress_warnings() as sup:
1473 sup.record()
1474 with suppress_warnings("always"):
1475 for i in range(2):
1476 warnings.warn("Some warning")
1477
1478 assert_equal(len(sup.log), 2)
1479
1480 with suppress_warnings() as sup:
1481 sup.record()
1482 with suppress_warnings("location"):
1483 for i in range(2):
1484 warnings.warn("Some warning")
1485 warnings.warn("Some warning")
1486
1487 assert_equal(len(sup.log), 2)
1488
1489 with suppress_warnings() as sup:
1490 sup.record()
1491 with suppress_warnings("module"):
1492 for i in range(2):
1493 warnings.warn("Some warning")
1494 warnings.warn("Some warning")
1495 warn_other_module()
1496
1497 assert_equal(len(sup.log), 2)
1498
1499 with suppress_warnings() as sup:
1500 sup.record()
1501 with suppress_warnings("once"):
1502 for i in range(2):
1503 warnings.warn("Some warning")
1504 warnings.warn("Some other warning")
1505 warn_other_module()
1506
1507 assert_equal(len(sup.log), 2)
1508
1509
1510def test_tempdir():

Callers

nothing calls this directly

Calls 5

suppress_warningsClass · 0.90
assert_equalFunction · 0.90
warn_other_moduleFunction · 0.85
recordMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected