mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Merged revisions 79049 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r79049 | florent.xicluna | 2010-03-18 20:51:47 +0100 (jeu, 18 mar 2010) | 2 lines #8155: Preserve backward compatibility for test_support.check_warnings(). Add regression tests. ........
This commit is contained in:
parent
7fb4da7650
commit
53b506beda
3 changed files with 84 additions and 62 deletions
|
@ -644,18 +644,33 @@ class CatchWarningTests(BaseTest):
|
|||
def test_check_warnings(self):
|
||||
# Explicit tests for the test.support convenience wrapper
|
||||
wmod = self.module
|
||||
if wmod is sys.modules['warnings']:
|
||||
with support.check_warnings() as w:
|
||||
self.assertEqual(w.warnings, [])
|
||||
wmod.simplefilter("always")
|
||||
if wmod is not sys.modules['warnings']:
|
||||
return
|
||||
with support.check_warnings(quiet=False) as w:
|
||||
self.assertEqual(w.warnings, [])
|
||||
wmod.simplefilter("always")
|
||||
wmod.warn("foo")
|
||||
self.assertEqual(str(w.message), "foo")
|
||||
wmod.warn("bar")
|
||||
self.assertEqual(str(w.message), "bar")
|
||||
self.assertEqual(str(w.warnings[0].message), "foo")
|
||||
self.assertEqual(str(w.warnings[1].message), "bar")
|
||||
w.reset()
|
||||
self.assertEqual(w.warnings, [])
|
||||
|
||||
with support.check_warnings():
|
||||
# defaults to quiet=True without argument
|
||||
pass
|
||||
with support.check_warnings(('foo', UserWarning)):
|
||||
wmod.warn("foo")
|
||||
|
||||
with self.assertRaises(AssertionError):
|
||||
with support.check_warnings(('', RuntimeWarning)):
|
||||
# defaults to quiet=False with argument
|
||||
pass
|
||||
with self.assertRaises(AssertionError):
|
||||
with support.check_warnings(('foo', RuntimeWarning)):
|
||||
wmod.warn("foo")
|
||||
self.assertEqual(str(w.message), "foo")
|
||||
wmod.warn("bar")
|
||||
self.assertEqual(str(w.message), "bar")
|
||||
self.assertEqual(str(w.warnings[0].message), "foo")
|
||||
self.assertEqual(str(w.warnings[1].message), "bar")
|
||||
w.reset()
|
||||
self.assertEqual(w.warnings, [])
|
||||
|
||||
class CCatchWarningTests(CatchWarningTests):
|
||||
module = c_warnings
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue