]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[trac1024] Make "reset unit test root logger" available to Python
authorStephen Morris <stephen@isc.org>
Wed, 13 Jul 2011 17:46:10 +0000 (18:46 +0100)
committerStephen Morris <stephen@isc.org>
Wed, 13 Jul 2011 17:46:10 +0000 (18:46 +0100)
... and use it in the Python unit tests that generate logging output.

src/bin/bind10/tests/bind10_test.py.in
src/bin/cmdctl/tests/cmdctl_test.py
src/bin/xfrout/tests/xfrout_test.py.in
src/lib/python/isc/log/log.cc

index 91d326c339685aaabd90400b38219ec0ba5fbf82..9d794a6a089a880cb41de580f3bd77234942f31c 100644 (file)
@@ -26,6 +26,7 @@ import socket
 from isc.net.addr import IPAddr
 import time
 import isc
+import isc.log
 
 from isc.testutils.parse_args import TestOptParser, OptsError
 
@@ -764,4 +765,5 @@ class TestBrittle(unittest.TestCase):
         self.assertFalse(bob.runnable)
 
 if __name__ == '__main__':
+    isc.log.resetUnitTestRootLogger()
     unittest.main()
index e77c529299a18ddf7e0e304cfce3ffda1a8e8f17..3103f479c7d3e2e28a7903259f8d7b66ab83dce6 100644 (file)
@@ -19,6 +19,7 @@ import socket
 import tempfile
 import sys
 from cmdctl import *
+import isc.log
 
 SPEC_FILE_PATH = '..' + os.sep
 if 'CMDCTL_SPEC_PATH' in os.environ:
@@ -447,6 +448,7 @@ class TestFuncNotInClass(unittest.TestCase):
 
 
 if __name__== "__main__":
+    isc.log.resetUnitTestRootLogger()
     unittest.main()
 
 
index adabf48ebfa243a8f0e0083b2c4136e93ab78f42..7ab4a5895ec5553b94de5fc063fed784e0186640 100644 (file)
@@ -23,6 +23,7 @@ from isc.cc.session import *
 from pydnspp import *
 from xfrout import *
 import xfrout
+import isc.log
 
 TSIG_KEY = TSIGKey("example.com:SFuWd/q99SzF8Yzd1QbB9g==")
 
@@ -670,4 +671,5 @@ class TestInitialization(unittest.TestCase):
         self.assertEqual(xfrout.UNIX_SOCKET_FILE, "The/Socket/File")
 
 if __name__== "__main__":
+    isc.log.resetUnitTestRootLogger()
     unittest.main()
index 484151f424e568f3269f6f3f0c76dd017d4bcc64..ace1f711dfccd471c5ba915d1e777f36898739dd 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <log/message_dictionary.h>
 #include <log/logger_manager.h>
+#include <log/logger_support.h>
 #include <log/logger.h>
 
 #include <config/ccsession.h>
@@ -35,7 +36,7 @@ using boost::bind;
 // (tags/RELEASE_28 115909)) on OSX, where unwinding the stack
 // segfaults the moment this exception was thrown and caught.
 //
-// Placing it in a named namespace instead of the original
+// Placing it in a named namespace instead of the originalRecommend
 // unnamed namespace appears to solve this, so as a temporary
 // workaround, we create a local randomly named namespace here
 // to solve this issue.
@@ -184,6 +185,27 @@ init(PyObject*, PyObject* args) {
     Py_RETURN_NONE;
 }
 
+// This initialization is for unit tests.  It allows message settings to be
+// be determined by a set of B10_xxx environment variables.  (See the
+// description of initLogger() for more details.)  The function has been named
+// resetUnitTestRootLogger() here as being more descriptive and
+// trying to avoid confusion.
+PyObject*
+resetUnitTestRootLogger(PyObject*, PyObject*) {
+    try {
+        isc::log::resetUnitTestRootLogger();
+    }
+    catch (const std::exception& e) {
+        PyErr_SetString(PyExc_RuntimeError, e.what());
+        return (NULL);
+    }
+    catch (...) {
+        PyErr_SetString(PyExc_RuntimeError, "Unknown C++ exception");
+        return (NULL);
+    }
+    Py_RETURN_NONE;
+}
+
 PyObject*
 logConfigUpdate(PyObject*, PyObject* args) {
     // we have no wrappers for ElementPtr and ConfigData,
@@ -246,6 +268,11 @@ PyMethodDef methods[] = {
         "logging severity (one of 'DEBUG', 'INFO', 'WARN', 'ERROR' or "
         "'FATAL'), a debug level (integer in the range 0-99) and a file name "
         "of a dictionary with message text translations."},
+    {"resetUnitTestRootLogger", resetUnitTestRootLogger, METH_VARARGS,
+        "Initialization for unit tests.  Sets the severity and output stream "
+        "according to a set of environment variables.  This should not be "
+        "used in production code.  The name is slightly confusing, but it "
+        "mirrors a method of the same name used for the C++ unit tests."},
     {"log_config_update", logConfigUpdate, METH_VARARGS,
         "Update logger settings. This method is automatically used when "
         "ModuleCCSession is initialized with handle_logging_config set "