]> granicus.if.org Git - python/commitdiff
Fix logic error in Python/_warnings.c and add a test to verify
authorBenjamin Peterson <benjamin@python.org>
Tue, 6 May 2008 22:18:11 +0000 (22:18 +0000)
committerBenjamin Peterson <benjamin@python.org>
Tue, 6 May 2008 22:18:11 +0000 (22:18 +0000)
Lib/test/test_warnings.py
Python/_warnings.c

index 1b5ee3291cfca4f3ac428bff35f556a1af3c55b3..70d8c561501b1375f9fe98c61bf96cca096398ee 100644 (file)
@@ -388,6 +388,15 @@ class _WarningsTests(BaseTest):
                 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'
index 0e48675d81c7f179d6530afbbd87231a226f41ff..e75d4fd06a635c023202aa870aa635f0d9193759 100644 (file)
@@ -400,6 +400,8 @@ warn_explicit(PyObject *category, PyObject *message,
                     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);