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

Function test_suppress_warnings_record

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

Source from the content-addressed store, hash-verified

1421
1422
1423def test_suppress_warnings_record():
1424 sup = suppress_warnings()
1425 log1 = sup.record()
1426
1427 with sup:
1428 log2 = sup.record(message='Some other warning 2')
1429 sup.filter(message='Some warning')
1430 warnings.warn('Some warning')
1431 warnings.warn('Some other warning')
1432 warnings.warn('Some other warning 2')
1433
1434 assert_equal(len(sup.log), 2)
1435 assert_equal(len(log1), 1)
1436 assert_equal(len(log2),1)
1437 assert_equal(log2[0].message.args[0], 'Some other warning 2')
1438
1439 # Do it again, with the same context to see if some warnings survived:
1440 with sup:
1441 log2 = sup.record(message='Some other warning 2')
1442 sup.filter(message='Some warning')
1443 warnings.warn('Some warning')
1444 warnings.warn('Some other warning')
1445 warnings.warn('Some other warning 2')
1446
1447 assert_equal(len(sup.log), 2)
1448 assert_equal(len(log1), 1)
1449 assert_equal(len(log2), 1)
1450 assert_equal(log2[0].message.args[0], 'Some other warning 2')
1451
1452 # Test nested:
1453 with suppress_warnings() as sup:
1454 sup.record()
1455 with suppress_warnings() as sup2:
1456 sup2.record(message='Some warning')
1457 warnings.warn('Some warning')
1458 warnings.warn('Some other warning')
1459 assert_equal(len(sup2.log), 1)
1460 assert_equal(len(sup.log), 1)
1461
1462
1463def test_suppress_warnings_forwarding():

Callers

nothing calls this directly

Calls 5

suppress_warningsClass · 0.90
assert_equalFunction · 0.90
recordMethod · 0.80
filterMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected