MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_warnings

Method test_warnings

Lib/test/test_logging.py:2314–2336  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2312class WarningsTest(BaseTest):
2313
2314 def test_warnings(self):
2315 with warnings.catch_warnings():
2316 logging.captureWarnings(True)
2317 self.addCleanup(logging.captureWarnings, False)
2318 warnings.filterwarnings("always", category=UserWarning)
2319 stream = io.StringIO()
2320 h = logging.StreamHandler(stream)
2321 logger = logging.getLogger("py.warnings")
2322 logger.addHandler(h)
2323 warnings.warn("I'm warning you...")
2324 logger.removeHandler(h)
2325 s = stream.getvalue()
2326 h.close()
2327 self.assertGreater(s.find("UserWarning: I'm warning you...\n"), 0)
2328
2329 # See if an explicit file uses the original implementation
2330 a_file = io.StringIO()
2331 warnings.showwarning("Explicit", UserWarning, "dummy.py", 42,
2332 a_file, "Dummy line")
2333 s = a_file.getvalue()
2334 a_file.close()
2335 self.assertEqual(s,
2336 "dummy.py:42: UserWarning: Explicit\n Dummy line\n")
2337
2338 def test_warnings_no_handlers(self):
2339 with warnings.catch_warnings():

Callers

nothing calls this directly

Calls 10

getvalueMethod · 0.95
addCleanupMethod · 0.80
getLoggerMethod · 0.80
addHandlerMethod · 0.80
removeHandlerMethod · 0.80
assertGreaterMethod · 0.80
warnMethod · 0.45
closeMethod · 0.45
findMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected