diff options
| author | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-18 19:51:47 (GMT) |
|---|---|---|
| committer | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-18 19:51:47 (GMT) |
| commit | 735885428d77d5eb0e581fe60e6d1b0f9273a530 (patch) | |
| tree | 40ed388b8670e354b3a1e166654129f0c80835f4 /Lib/test/test_warnings.py | |
| parent | f3e9b2a996d9f18bf7060e0bff85c02bee47c490 (diff) | |
| download | cpython-735885428d77d5eb0e581fe60e6d1b0f9273a530.zip cpython-735885428d77d5eb0e581fe60e6d1b0f9273a530.tar.gz cpython-735885428d77d5eb0e581fe60e6d1b0f9273a530.tar.bz2 | |
#8155: Preserve backward compatibility for test_support.check_warnings(). Add regression tests.
Diffstat (limited to 'Lib/test/test_warnings.py')
| -rw-r--r-- | Lib/test/test_warnings.py | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py index e008984..79922b2 100644 --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -633,19 +633,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 test_support.check_warnings() 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, []) + if wmod is not sys.modules['warnings']: + return + with test_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 test_support.check_warnings(): + # defaults to quiet=True without argument + pass + with test_support.check_warnings(('foo', UserWarning)): + wmod.warn("foo") + with self.assertRaises(AssertionError): + with test_support.check_warnings(('', RuntimeWarning)): + # defaults to quiet=False with argument + pass + with self.assertRaises(AssertionError): + with test_support.check_warnings(('foo', RuntimeWarning)): + wmod.warn("foo") class CCatchWarningTests(CatchWarningTests): |
