summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2010-03-18 20:00:57 (GMT)
committerFlorent Xicluna <florent.xicluna@gmail.com>2010-03-18 20:00:57 (GMT)
commit53b506beda2e959928661f960d6b7bff5e300adb (patch)
tree5dde6cbb5d37922051a090ea0bc3a2f1b19fcbd6 /Lib/test
parent7fb4da76507dd8032964b7ae5e40f43657db2610 (diff)
downloadcpython-53b506beda2e959928661f960d6b7bff5e300adb.zip
cpython-53b506beda2e959928661f960d6b7bff5e300adb.tar.gz
cpython-53b506beda2e959928661f960d6b7bff5e300adb.tar.bz2
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. ........
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/support.py11
-rw-r--r--Lib/test/test_warnings.py37
2 files changed, 34 insertions, 14 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index 28f7e27..73c4228 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -534,14 +534,19 @@ def check_warnings(*filters, **kwargs):
Optional argument:
- if 'quiet' is True, it does not fail if a filter catches nothing
- (default False)
+ (default True without argument,
+ default False if some filters are defined)
Without argument, it defaults to:
- check_warnings(("", Warning), quiet=False)
+ check_warnings(("", Warning), quiet=True)
"""
+ quiet = kwargs.get('quiet')
if not filters:
filters = (("", Warning),)
- return _filterwarnings(filters, kwargs.get('quiet'))
+ # Preserve backward compatibility
+ if quiet is None:
+ quiet = True
+ return _filterwarnings(filters, quiet)
class CleanImport(object):
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
index d5876a7..dda704e 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -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