summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_warnings.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-04-01 18:03:59 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-04-01 18:03:59 (GMT)
commit15ba4dae5a2b0bd2f06dff586cb469e7b5325209 (patch)
tree90c38806dad0ab8ae71a6544096f844d53c30b27 /Lib/test/test_warnings.py
parent24565d296c874402bfc91c32546cb0e0f3eedec5 (diff)
downloadcpython-15ba4dae5a2b0bd2f06dff586cb469e7b5325209.zip
cpython-15ba4dae5a2b0bd2f06dff586cb469e7b5325209.tar.gz
cpython-15ba4dae5a2b0bd2f06dff586cb469e7b5325209.tar.bz2
_warnings was importing itself to get an attribute. That's bad if warnings gets
called in a thread that was spawned by an import itself. Last part to close #1665206.
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'