mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Fix logic error in Python/_warnings.c and add a test to verify
This commit is contained in:
parent
c730d5f7e5
commit
d295032910
2 changed files with 11 additions and 0 deletions
|
@ -388,6 +388,15 @@ class _WarningsTests(BaseTest):
|
||||||
result = stream.getvalue()
|
result = stream.getvalue()
|
||||||
self.failUnless(text in result)
|
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):
|
def test_show_warning_output(self):
|
||||||
# With showarning() missing, make sure that output is okay.
|
# With showarning() missing, make sure that output is okay.
|
||||||
text = 'test show_warning'
|
text = 'test show_warning'
|
||||||
|
|
|
@ -400,6 +400,8 @@ warn_explicit(PyObject *category, PyObject *message,
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"warnings.showwarning() must be set to a "
|
"warnings.showwarning() must be set to a "
|
||||||
"function or method");
|
"function or method");
|
||||||
|
Py_DECREF(show_fxn);
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
defaults = PyFunction_GetDefaults(check_fxn);
|
defaults = PyFunction_GetDefaults(check_fxn);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue