summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_warnings.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-09-18 00:40:46 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-09-18 00:40:46 (GMT)
commitcb0a006fd11c06178a656cfdc6390b197b22fc67 (patch)
tree5d80fc387c5c75a3eb6ce80c0359e64d763aea2f /Lib/test/test_warnings.py
parent1b38bc65ddc337101cf0b1b02c67a9a6742b0438 (diff)
downloadcpython-cb0a006fd11c06178a656cfdc6390b197b22fc67.zip
cpython-cb0a006fd11c06178a656cfdc6390b197b22fc67.tar.gz
cpython-cb0a006fd11c06178a656cfdc6390b197b22fc67.tar.bz2
Issue #4180: The warnings registries are now reset when the filters are modified.
Diffstat (limited to 'Lib/test/test_warnings.py')
-rw-r--r--Lib/test/test_warnings.py49
1 files changed, 47 insertions, 2 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
index 43b3b9c..0f2e089 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -92,6 +92,16 @@ class FilterTests(BaseTest):
self.assertRaises(UserWarning, self.module.warn,
"FilterTests.test_error")
+ def test_error_after_default(self):
+ with original_warnings.catch_warnings(module=self.module) as w:
+ self.module.resetwarnings()
+ message = "FilterTests.test_ignore_after_default"
+ def f():
+ self.module.warn(message, UserWarning)
+ f()
+ self.module.filterwarnings("error", category=UserWarning)
+ self.assertRaises(UserWarning, f)
+
def test_ignore(self):
with original_warnings.catch_warnings(record=True,
module=self.module) as w:
@@ -100,6 +110,19 @@ class FilterTests(BaseTest):
self.module.warn("FilterTests.test_ignore", UserWarning)
self.assertEqual(len(w), 0)
+ def test_ignore_after_default(self):
+ with original_warnings.catch_warnings(record=True,
+ module=self.module) as w:
+ self.module.resetwarnings()
+ message = "FilterTests.test_ignore_after_default"
+ def f():
+ self.module.warn(message, UserWarning)
+ f()
+ self.module.filterwarnings("ignore", category=UserWarning)
+ f()
+ f()
+ self.assertEqual(len(w), 1)
+
def test_always(self):
with original_warnings.catch_warnings(record=True,
module=self.module) as w:
@@ -111,6 +134,26 @@ class FilterTests(BaseTest):
self.module.warn(message, UserWarning)
self.assertTrue(w[-1].message, message)
+ def test_always_after_default(self):
+ with original_warnings.catch_warnings(record=True,
+ module=self.module) as w:
+ self.module.resetwarnings()
+ message = "FilterTests.test_always_after_ignore"
+ def f():
+ self.module.warn(message, UserWarning)
+ f()
+ self.assertEqual(len(w), 1)
+ self.assertEqual(w[-1].message.args[0], message)
+ f()
+ self.assertEqual(len(w), 1)
+ self.module.filterwarnings("always", category=UserWarning)
+ f()
+ self.assertEqual(len(w), 2)
+ self.assertEqual(w[-1].message.args[0], message)
+ f()
+ self.assertEqual(len(w), 3)
+ self.assertEqual(w[-1].message.args[0], message)
+
def test_default(self):
with original_warnings.catch_warnings(record=True,
module=self.module) as w:
@@ -506,7 +549,9 @@ class _WarningsTests(BaseTest, unittest.TestCase):
registry=registry)
self.assertEqual(w[-1].message, message)
self.assertEqual(len(w), 1)
- self.assertEqual(len(registry), 1)
+ # One actual registry key plus the "version" key
+ self.assertEqual(len(registry), 2)
+ self.assertIn("version", registry)
del w[:]
# Test removal.
del self.module.defaultaction
@@ -516,7 +561,7 @@ class _WarningsTests(BaseTest, unittest.TestCase):
registry=registry)
self.assertEqual(w[-1].message, message)
self.assertEqual(len(w), 1)
- self.assertEqual(len(registry), 1)
+ self.assertEqual(len(registry), 2)
del w[:]
# Test setting.
self.module.defaultaction = "ignore"