diff options
author | Brett Cannon <bcannon@gmail.com> | 2009-04-01 18:13:07 +0000 |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2009-04-01 18:13:07 +0000 |
commit | 0759dd66c581a65381412a2ff98dac8edd58ddee (patch) | |
tree | 92ac5c8ad7f4758201b70d4ecaf5b9888b21b38c /Lib/test/test_warnings.py | |
parent | 86fe876fb5ce8520d915e7b3fa738cb2a09c859d (diff) | |
download | cpython-0759dd66c581a65381412a2ff98dac8edd58ddee.tar.gz cpython-0759dd66c581a65381412a2ff98dac8edd58ddee.zip |
Merged revisions 70965 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70965 | brett.cannon | 2009-04-01 11:03:59 -0700 (Wed, 01 Apr 2009) | 5 lines
_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.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py index 4b6feb37cb9..49f3d3a7b77 100644 --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -423,6 +423,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' |