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

Function test_suppress_warnings_module

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

Source from the content-addressed store, hash-verified

1332
1333
1334def test_suppress_warnings_module():
1335 # Initial state of module, no warnings
1336 my_mod = _get_fresh_mod()
1337 assert_equal(getattr(my_mod, '__warningregistry__', {}), {})
1338
1339 def warn_other_module():
1340 # Apply along axis is implemented in python; stacklevel=2 means
1341 # we end up inside its module, not ours.
1342 def warn(arr):
1343 warnings.warn("Some warning 2", stacklevel=2)
1344 return arr
1345 np.apply_along_axis(warn, 0, [0])
1346
1347 # Test module based warning suppression:
1348 assert_warn_len_equal(my_mod, 0)
1349 with suppress_warnings() as sup:
1350 sup.record(UserWarning)
1351 # suppress warning from other module (may have .pyc ending),
1352 # if apply_along_axis is moved, had to be changed.
1353 sup.filter(module=np.lib.shape_base)
1354 warnings.warn("Some warning")
1355 warn_other_module()
1356 # Check that the suppression did test the file correctly (this module
1357 # got filtered)
1358 assert_equal(len(sup.log), 1)
1359 assert_equal(sup.log[0].message.args[0], "Some warning")
1360 assert_warn_len_equal(my_mod, 0)
1361 sup = suppress_warnings()
1362 # Will have to be changed if apply_along_axis is moved:
1363 sup.filter(module=my_mod)
1364 with sup:
1365 warnings.warn('Some warning')
1366 assert_warn_len_equal(my_mod, 0)
1367 # And test repeat works:
1368 sup.filter(module=my_mod)
1369 with sup:
1370 warnings.warn('Some warning')
1371 assert_warn_len_equal(my_mod, 0)
1372
1373 # Without specified modules
1374 with suppress_warnings():
1375 warnings.simplefilter('ignore')
1376 warnings.warn('Some warning')
1377 assert_warn_len_equal(my_mod, 0)
1378
1379
1380def test_suppress_warnings_type():

Callers

nothing calls this directly

Calls 8

assert_equalFunction · 0.90
suppress_warningsClass · 0.90
_get_fresh_modFunction · 0.85
assert_warn_len_equalFunction · 0.85
warn_other_moduleFunction · 0.85
recordMethod · 0.80
filterMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected