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

Function test_clear_and_catch_warnings

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

Source from the content-addressed store, hash-verified

1300
1301
1302def test_clear_and_catch_warnings():
1303 # Initial state of module, no warnings
1304 my_mod = _get_fresh_mod()
1305 assert_equal(getattr(my_mod, '__warningregistry__', {}), {})
1306 with clear_and_catch_warnings(modules=[my_mod]):
1307 warnings.simplefilter('ignore')
1308 warnings.warn('Some warning')
1309 assert_equal(my_mod.__warningregistry__, {})
1310 # Without specified modules, don't clear warnings during context.
1311 # catch_warnings doesn't make an entry for 'ignore'.
1312 with clear_and_catch_warnings():
1313 warnings.simplefilter('ignore')
1314 warnings.warn('Some warning')
1315 assert_warn_len_equal(my_mod, 0)
1316
1317 # Manually adding two warnings to the registry:
1318 my_mod.__warningregistry__ = {'warning1': 1,
1319 'warning2': 2}
1320
1321 # Confirm that specifying module keeps old warning, does not add new
1322 with clear_and_catch_warnings(modules=[my_mod]):
1323 warnings.simplefilter('ignore')
1324 warnings.warn('Another warning')
1325 assert_warn_len_equal(my_mod, 2)
1326
1327 # Another warning, no module spec it clears up registry
1328 with clear_and_catch_warnings():
1329 warnings.simplefilter('ignore')
1330 warnings.warn('Another warning')
1331 assert_warn_len_equal(my_mod, 0)
1332
1333
1334def test_suppress_warnings_module():

Callers

nothing calls this directly

Calls 5

assert_equalFunction · 0.90
_get_fresh_modFunction · 0.85
assert_warn_len_equalFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected