[Python-checkins] r62785 - in python/trunk: Lib/test/test_warnings.py Python/_warnings.c

benjamin.peterson python-checkins at python.org
Wed May 7 00:18:11 CEST 2008


Author: benjamin.peterson
Date: Wed May  7 00:18:11 2008
New Revision: 62785

Log:
Fix logic error in Python/_warnings.c and add a test to verify


Modified:
   python/trunk/Lib/test/test_warnings.py
   python/trunk/Python/_warnings.c

Modified: python/trunk/Lib/test/test_warnings.py
==============================================================================
--- python/trunk/Lib/test/test_warnings.py	(original)
+++ python/trunk/Lib/test/test_warnings.py	Wed May  7 00:18:11 2008
@@ -388,6 +388,15 @@
                 result = stream.getvalue()
         self.failUnless(text in result)
 
+    def test_showwarning_not_callable(self):
+        self.module.filterwarnings("always", category=UserWarning)
+        old_showwarning = self.module.showwarning
+        self.module.showwarning = 23
+        try:
+            self.assertRaises(TypeError, self.module.warn, "Warning!")
+        finally:
+            self.module.showwarning = old_showwarning
+
     def test_show_warning_output(self):
         # With showarning() missing, make sure that output is okay.
         text = 'test show_warning'

Modified: python/trunk/Python/_warnings.c
==============================================================================
--- python/trunk/Python/_warnings.c	(original)
+++ python/trunk/Python/_warnings.c	Wed May  7 00:18:11 2008
@@ -400,6 +400,8 @@
                     PyErr_SetString(PyExc_TypeError,
                                     "warnings.showwarning() must be set to a "
                                     "function or method");
+                    Py_DECREF(show_fxn);
+                    goto cleanup;
                 }
 
                 defaults = PyFunction_GetDefaults(check_fxn);


More information about the Python-checkins mailing list