Commit df8709d7 authored by Brett Cannon's avatar Brett Cannon

Merged revisions 70975 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r70975 | brett.cannon | 2009-04-01 12:57:10 -0700 (Wed, 01 Apr 2009) | 4 lines

  test_logging was blindly clearing the warnings filter. This caused
  PendingDeprecationWarnings to be spewed all over by unittest.failIf*(). Fix
  moves over to using warnings.catch_warning to protect the warnings filter.
........
parent 3f10a952
...@@ -910,30 +910,32 @@ class EncodingTest(BaseTest): ...@@ -910,30 +910,32 @@ class EncodingTest(BaseTest):
class WarningsTest(BaseTest): class WarningsTest(BaseTest):
def test_warnings(self): def test_warnings(self):
logging.captureWarnings(True) logging.captureWarnings(True)
warnings.filterwarnings("always", category=UserWarning) with warnings.catch_warnings():
try: warnings.filterwarnings("always", category=UserWarning)
file = io.StringIO() try:
h = logging.StreamHandler(file) file = io.StringIO()
logger = logging.getLogger("py.warnings") h = logging.StreamHandler(file)
logger.addHandler(h) logger = logging.getLogger("py.warnings")
warnings.warn("I'm warning you...") logger.addHandler(h)
logger.removeHandler(h) warnings.warn("I'm warning you...")
s = file.getvalue() logger.removeHandler(h)
h.close() s = file.getvalue()
self.assertTrue(s.find("UserWarning: I'm warning you...\n") > 0) h.close()
self.assertTrue(s.find("UserWarning: I'm warning you...\n") > 0)
#See if an explicit file uses the original implementation
file = io.StringIO() #See if an explicit file uses the original implementation
warnings.showwarning("Explicit", UserWarning, "dummy.py", 42, file, file = io.StringIO()
"Dummy line") warnings.showwarning("Explicit", UserWarning, "dummy.py", 42,
s = file.getvalue() file, "Dummy line")
file.close() s = file.getvalue()
self.assertEqual(s, "dummy.py:42: UserWarning: Explicit\n Dummy line\n") file.close()
finally: self.assertEqual(s,
warnings.resetwarnings() "dummy.py:42: UserWarning: Explicit\n Dummy line\n")
logging.captureWarnings(False) finally:
logging.captureWarnings(False)
# Set the locale to the platform-dependent default. I have no idea # Set the locale to the platform-dependent default. I have no idea
# why the test does this, but in any case we save the current locale # why the test does this, but in any case we save the current locale
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment