summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_warnings.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_warnings.py')
-rw-r--r--Lib/test/test_warnings.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
index e90a2c2..bc177ad 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -413,6 +413,41 @@ class _WarningsTests(BaseTest):
finally:
self.module.onceregistry = original_registry
+ def test_default_action(self):
+ # Replacing or removing defaultaction should be okay.
+ message = UserWarning("defaultaction test")
+ original = self.module.defaultaction
+ try:
+ with original_warnings.catch_warnings(record=True,
+ module=self.module) as w:
+ self.module.resetwarnings()
+ registry = {}
+ self.module.warn_explicit(message, UserWarning, "<test>", 42,
+ registry=registry)
+ self.assertEqual(w[-1].message, message)
+ self.assertEqual(len(w), 1)
+ self.assertEqual(len(registry), 1)
+ del w[:]
+ # Test removal.
+ del self.module.defaultaction
+ __warningregistry__ = {}
+ registry = {}
+ self.module.warn_explicit(message, UserWarning, "<test>", 43,
+ registry=registry)
+ self.assertEqual(w[-1].message, message)
+ self.assertEqual(len(w), 1)
+ self.assertEqual(len(registry), 1)
+ del w[:]
+ # Test setting.
+ self.module.defaultaction = "ignore"
+ __warningregistry__ = {}
+ registry = {}
+ self.module.warn_explicit(message, UserWarning, "<test>", 44,
+ registry=registry)
+ self.assertEqual(len(w), 0)
+ finally:
+ self.module.defaultaction = original
+
def test_showwarning_missing(self):
# Test that showwarning() missing is okay.
text = 'del showwarning test'