summaryrefslogtreecommitdiff
path: root/Lib/test/test_warnings.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2008-09-02 04:01:42 +0000
committerBrett Cannon <bcannon@gmail.com>2008-09-02 04:01:42 +0000
commit54bd41d81b23eb5d7f7a5f71fa2ceec28fb60296 (patch)
treeb3a716539809d01303911389ecc245e1900070b4 /Lib/test/test_warnings.py
parentec92e181fb912e9dc0935fc10bd61bfd4fb237d7 (diff)
downloadcpython-git-54bd41d81b23eb5d7f7a5f71fa2ceec28fb60296.tar.gz
The _warnings module did not properly handle cases where strings were not being
passed in as the message to use for a warning. Fixed along with making the code more robust against other errors where return values were not checked. Closes issue 3639. Code review by Benjamin Peterson.
Diffstat (limited to 'Lib/test/test_warnings.py')
-rw-r--r--Lib/test/test_warnings.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
index cd408cf145..087bf3d871 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -202,6 +202,16 @@ class WarnTests(unittest.TestCase):
self.assertEqual(str(w.message), text)
self.assert_(w.category is UserWarning)
+ # Issue 3639
+ def test_warn_nonstandard_types(self):
+ # warn() should handle non-standard types without issue.
+ for ob in (Warning, None, 42):
+ with support.catch_warning(self.module) as w:
+ self.module.warn(ob)
+ # Don't directly compare objects since
+ # ``Warning() != Warning()``.
+ self.assertEquals(str(w.message), str(UserWarning(ob)))
+
def test_filename(self):
with warnings_state(self.module):
with support.catch_warning(self.module) as w:
@@ -315,7 +325,6 @@ class WarnTests(unittest.TestCase):
self.module.warn_explicit,
None, Warning, None, 1, registry=42)
-
class CWarnTests(BaseTest, WarnTests):
module = c_warnings