(self)
| 2338 | class WarningsTest(BaseTest): |
| 2339 | |
| 2340 | def test_warnings(self): |
| 2341 | with warnings.catch_warnings(): |
| 2342 | logging.captureWarnings(True) |
| 2343 | self.addCleanup(logging.captureWarnings, False) |
| 2344 | warnings.filterwarnings("always", category=UserWarning) |
| 2345 | stream = io.StringIO() |
| 2346 | h = logging.StreamHandler(stream) |
| 2347 | logger = logging.getLogger("py.warnings") |
| 2348 | logger.addHandler(h) |
| 2349 | warnings.warn("I'm warning you...") |
| 2350 | logger.removeHandler(h) |
| 2351 | s = stream.getvalue() |
| 2352 | h.close() |
| 2353 | self.assertGreater(s.find("UserWarning: I'm warning you...\n"), 0) |
| 2354 | |
| 2355 | # See if an explicit file uses the original implementation |
| 2356 | a_file = io.StringIO() |
| 2357 | warnings.showwarning("Explicit", UserWarning, "dummy.py", 42, |
| 2358 | a_file, "Dummy line") |
| 2359 | s = a_file.getvalue() |
| 2360 | a_file.close() |
| 2361 | self.assertEqual(s, |
| 2362 | "dummy.py:42: UserWarning: Explicit\n Dummy line\n") |
| 2363 | |
| 2364 | def test_warnings_no_handlers(self): |
| 2365 | with warnings.catch_warnings(): |
nothing calls this directly
no test coverage detected