BIND 10 trac1704, updated. 8132536f3c982f0438c0d5ff199a57a18c826411 [1704] Set B10_FROM_SOURCE for some tests so that it doesn't require the install prefix

BIND 10 source code commits bind10-changes at lists.isc.org
Thu May 17 11:14:37 UTC 2012


The branch, trac1704 has been updated
       via  8132536f3c982f0438c0d5ff199a57a18c826411 (commit)
      from  8801ca7c8d5e612629fbe7425f5c9005dd87bcfb (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 8132536f3c982f0438c0d5ff199a57a18c826411
Author: Mukund Sivaraman <muks at isc.org>
Date:   Thu May 17 16:23:40 2012 +0530

    [1704] Set B10_FROM_SOURCE for some tests so that it doesn't require the install prefix

-----------------------------------------------------------------------

Summary of changes:
 configure.ac                                       |    1 +
 src/lib/log/tests/Makefile.am                      |    1 +
 src/lib/log/tests/console_test.sh.in               |    2 ++
 src/lib/log/tests/destination_test.sh.in           |    2 ++
 src/lib/log/tests/init_logger_test.sh.in           |    2 ++
 src/lib/log/tests/local_file_test.sh.in            |    2 ++
 src/lib/log/tests/run_initializer_unittests.cc     |    2 ++
 src/lib/log/tests/run_unittests.cc                 |    2 ++
 src/lib/log/tests/severity_test.sh.in              |    2 ++
 src/lib/python/isc/log/tests/.gitignore            |    1 +
 src/lib/python/isc/log/tests/log_console.py.in     |    3 +++
 .../isc/log/tests/{log_test.py => log_test.py.in}  |    3 +++
 12 files changed, 23 insertions(+), 0 deletions(-)
 rename src/lib/python/isc/log/tests/{log_test.py => log_test.py.in} (99%)

-----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index cf70e3f..d4eed99 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1174,6 +1174,7 @@ AC_OUTPUT([doc/version.ent
            src/lib/python/isc/cc/tests/cc_test
            src/lib/python/isc/notify/tests/notify_out_test
            src/lib/python/isc/log/tests/log_console.py
+           src/lib/python/isc/log/tests/log_test.py
            src/lib/python/isc/log_messages/work/__init__.py
            src/lib/dns/gen-rdatacode.py
            src/lib/python/bind10_config.py
diff --git a/src/lib/log/tests/Makefile.am b/src/lib/log/tests/Makefile.am
index 6f3d768..dd3c08c 100644
--- a/src/lib/log/tests/Makefile.am
+++ b/src/lib/log/tests/Makefile.am
@@ -2,6 +2,7 @@ SUBDIRS = .
 
 AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CPPFLAGS += -DTOP_SRCDIR=\"${abs_top_srcdir}\"
 AM_CXXFLAGS = $(B10_CXXFLAGS)
 AM_LDADD    =
 AM_LDFLAGS  =
diff --git a/src/lib/log/tests/console_test.sh.in b/src/lib/log/tests/console_test.sh.in
index a16dc23..2b3e6ac 100755
--- a/src/lib/log/tests/console_test.sh.in
+++ b/src/lib/log/tests/console_test.sh.in
@@ -16,6 +16,8 @@
 # The logger supports the idea of a "console" logger than logs to either stdout
 # or stderr.  This test checks that both these options work.
 
+export B10_FROM_SOURCE=@abs_top_srcdir@
+
 testname="Console output test"
 echo $testname
 
diff --git a/src/lib/log/tests/destination_test.sh.in b/src/lib/log/tests/destination_test.sh.in
index 1cfb9fb..722b9a5 100755
--- a/src/lib/log/tests/destination_test.sh.in
+++ b/src/lib/log/tests/destination_test.sh.in
@@ -15,6 +15,8 @@
 
 # Checks that the logger will route messages to the chosen destination.
 
+export B10_FROM_SOURCE=@abs_top_srcdir@
+
 testname="Destination test"
 echo $testname
 
diff --git a/src/lib/log/tests/init_logger_test.sh.in b/src/lib/log/tests/init_logger_test.sh.in
index 795419b..5e05531 100755
--- a/src/lib/log/tests/init_logger_test.sh.in
+++ b/src/lib/log/tests/init_logger_test.sh.in
@@ -16,6 +16,8 @@
 # Checks that the initLogger() call uses for unit tests respects the setting of
 # the environment variables.
 
+export B10_FROM_SOURCE=@abs_top_srcdir@
+
 testname="initLogger test"
 echo $testname
 
diff --git a/src/lib/log/tests/local_file_test.sh.in b/src/lib/log/tests/local_file_test.sh.in
index 9b898e6..6ee4aec 100755
--- a/src/lib/log/tests/local_file_test.sh.in
+++ b/src/lib/log/tests/local_file_test.sh.in
@@ -16,6 +16,8 @@
 # Checks that a local message file can override the definitions in the message
 # dictionary.
 
+export B10_FROM_SOURCE=@abs_top_srcdir@
+
 testname="Local message file test"
 echo $testname
 
diff --git a/src/lib/log/tests/run_initializer_unittests.cc b/src/lib/log/tests/run_initializer_unittests.cc
index 54ee120..aadfa49 100644
--- a/src/lib/log/tests/run_initializer_unittests.cc
+++ b/src/lib/log/tests/run_initializer_unittests.cc
@@ -12,6 +12,7 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
+#include <stdlib.h>
 #include <gtest/gtest.h>
 #include <util/unittests/run_all.h>
 
@@ -20,5 +21,6 @@
 int
 main(int argc, char* argv[]) {
     ::testing::InitGoogleTest(&argc, argv);
+    setenv("B10_FROM_SOURCE", TOP_SRCDIR, 1);
     return (isc::util::unittests::run_all());
 }
diff --git a/src/lib/log/tests/run_unittests.cc b/src/lib/log/tests/run_unittests.cc
index 8a9d1e5..1376a91 100644
--- a/src/lib/log/tests/run_unittests.cc
+++ b/src/lib/log/tests/run_unittests.cc
@@ -12,6 +12,7 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
+#include <stdlib.h>
 #include <gtest/gtest.h>
 #include <util/unittests/run_all.h>
 
@@ -20,6 +21,7 @@
 int
 main(int argc, char* argv[]) {
     ::testing::InitGoogleTest(&argc, argv);
+    setenv("B10_FROM_SOURCE", TOP_SRCDIR, 1);
     isc::log::initLogger();
     return (isc::util::unittests::run_all());
 }
diff --git a/src/lib/log/tests/severity_test.sh.in b/src/lib/log/tests/severity_test.sh.in
index 78d5050..c88b117 100755
--- a/src/lib/log/tests/severity_test.sh.in
+++ b/src/lib/log/tests/severity_test.sh.in
@@ -16,6 +16,8 @@
 # Checks that the logger will limit the output of messages less severe than
 # the severity/debug setting.
 
+export B10_FROM_SOURCE=@abs_top_srcdir@
+
 testname="Severity test"
 echo $testname
 
diff --git a/src/lib/python/isc/log/tests/.gitignore b/src/lib/python/isc/log/tests/.gitignore
index b9cf241..3e6e8d0 100644
--- a/src/lib/python/isc/log/tests/.gitignore
+++ b/src/lib/python/isc/log/tests/.gitignore
@@ -1 +1,2 @@
 /log_console.py
+/log_test.py
diff --git a/src/lib/python/isc/log/tests/log_console.py.in b/src/lib/python/isc/log/tests/log_console.py.in
index af05f61..277f4c7 100755
--- a/src/lib/python/isc/log/tests/log_console.py.in
+++ b/src/lib/python/isc/log/tests/log_console.py.in
@@ -1,5 +1,8 @@
 #!@PYTHON@
 
+import os
+os.environ['B10_FROM_SOURCE'] = '@abs_top_srcdir@'
+
 import isc.log
 # This would come from a dictionary in real life
 MSG_ID = isc.log.create_message("MSG_ID", "Message with %2 %1")
diff --git a/src/lib/python/isc/log/tests/log_test.py b/src/lib/python/isc/log/tests/log_test.py
deleted file mode 100644
index 1337654..0000000
--- a/src/lib/python/isc/log/tests/log_test.py
+++ /dev/null
@@ -1,204 +0,0 @@
-# Copyright (C) 2011  Internet Systems Consortium.
-#
-# Permission to use, copy, modify, and distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
-# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
-# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
-# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
-# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
-# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-# This tests it can be loaded, nothing more yet
-import isc.log
-import unittest
-import json
-import sys
-import bind10_config
-from isc.config.ccsession import path_search
-
-class LogDict(unittest.TestCase):
-    def setUp(self):
-        # We work on a test dictionary now.
-        isc.log.set_test_dictionary(True)
-    def tearDown(self):
-        # Return to the global dictionary
-        isc.log.set_test_dictionary(False)
-
-    def test_load_msgs(self):
-        # Try loading a message and see it's there, but nothing more
-        self.assertEqual(isc.log.create_message("ID", "Text"), "ID")
-        self.assertEqual(isc.log.get_message("ID"), "Text")
-        self.assertEqual(isc.log.get_message("no-ID"), None)
-
-class Manager(unittest.TestCase):
-    def tearDown(self):
-        isc.log.reset()
-
-    def test_init_debug(self):
-        # We try calling it now only, as we don't have any other functions
-        # to check the outcome by it. Once we add the logger class, we may
-        # check more.
-        isc.log.init("root", "DEBUG", 50, None)
-
-    def test_init_defaults(self):
-        # We try calling it now only, as we don't have any other functions
-        # to check the outcome by it. Once we add the logger class, we may
-        # check more.
-        isc.log.init("root")
-
-    def test_init_notfound(self):
-        # This should not throw, because the C++ one doesn't. Should we really
-        # ignore errors like missing file?
-        isc.log.init("root", "INFO", 0, "/no/such/file");
-
-    def test_log_config_update(self):
-        log_spec = json.dumps(isc.config.module_spec_from_file(path_search('logging.spec', bind10_config.PLUGIN_PATHS)).get_full_spec())
-
-        self.assertRaises(TypeError, isc.log.log_config_update)
-        self.assertRaises(TypeError, isc.log.log_config_update, 1)
-        self.assertRaises(TypeError, isc.log.log_config_update, 1, 1)
-        self.assertRaises(TypeError, isc.log.log_config_update, 1, 1, 1)
-
-        self.assertRaises(TypeError, isc.log.log_config_update, 1, log_spec)
-        self.assertRaises(TypeError, isc.log.log_config_update, [], log_spec)
-        self.assertRaises(TypeError, isc.log.log_config_update, "foo", log_spec)
-        self.assertRaises(TypeError, isc.log.log_config_update, "{ '", log_spec)
-
-        # empty should pass
-        isc.log.log_config_update("{}", log_spec)
-
-        # bad spec
-        self.assertRaises(TypeError, isc.log.log_config_update, "{}", json.dumps({"foo": "bar"}))
-
-        # Try a correct one
-        log_conf = json.dumps({"loggers":
-                                [{"name": "b10-xfrout", "output_options":
-                                    [{"output": "/tmp/bind10.log",
-                                       "destination": "file",
-                                       "flush": True}]}]})
-        isc.log.log_config_update(log_conf, log_spec)
-
-class Logger(unittest.TestCase):
-    def tearDown(self):
-        isc.log.reset()
-
-    def setUp(self):
-        isc.log.init("root", "DEBUG", 50)
-        self.sevs = ['INFO', 'WARN', 'ERROR', 'FATAL']
-        self.TEST_MSG = isc.log.create_message('TEST_MESSAGE', '%1')
-
-    # Checks defaults of the logger
-    def defaults(self, logger):
-        self.assertEqual(logger.get_effective_severity(), "DEBUG")
-        self.assertEqual(logger.get_effective_debug_level(), 50)
-
-    def test_default_severity(self):
-        logger = isc.log.Logger("child")
-        self.defaults(logger)
-
-    # Try changing the severities little bit
-    def test_severity(self):
-        logger = isc.log.Logger("child")
-        logger.set_severity('DEBUG', 25)
-        self.assertEqual(logger.get_effective_severity(), "DEBUG")
-        self.assertEqual(logger.get_effective_debug_level(), 25)
-        for sev in self.sevs:
-            logger.set_severity(sev)
-            self.assertEqual(logger.get_effective_severity(), sev)
-            self.assertEqual(logger.get_effective_debug_level(), 0)
-        # Return to default
-        logger.set_severity(None)
-        self.defaults(logger)
-
-    def test_enabled(self):
-        logger = isc.log.Logger("child")
-        self.sevs.insert(0, 'DEBUG')
-        methods = {
-            'DEBUG': logger.is_debug_enabled,
-            'INFO': logger.is_info_enabled,
-            'WARN': logger.is_warn_enabled,
-            'ERROR': logger.is_error_enabled,
-            'FATAL': logger.is_fatal_enabled
-        }
-        for sev in self.sevs:
-            logger.set_severity(sev)
-            enabled = False
-            for tested in self.sevs:
-                if tested == sev:
-                    enabled = True
-                self.assertEqual(methods[tested](), enabled)
-        logger.set_severity('DEBUG', 50)
-        self.assertTrue(logger.is_debug_enabled())
-        self.assertTrue(logger.is_debug_enabled(0))
-        self.assertTrue(logger.is_debug_enabled(50))
-        self.assertFalse(logger.is_debug_enabled(99))
-
-    def test_invalid_params(self):
-        """
-           Tests invalid arguments for logging functions. The output is tested
-           in check_output.sh.
-        """
-        logger = isc.log.Logger("child")
-        methods = [
-            logger.info,
-            logger.warn,
-            logger.error,
-            logger.fatal
-        ]
-        for meth in methods:
-            # Not enough arguments
-            self.assertRaises(TypeError, meth)
-            # Bad type
-            self.assertRaises(TypeError, meth, 1)
-        # Too few arguments
-        self.assertRaises(TypeError, logger.debug, 42)
-        self.assertRaises(TypeError, logger.debug)
-        # Bad type
-        self.assertRaises(TypeError, logger.debug, "42", "hello")
-
-    def test_dbglevel_constants(self):
-        """
-            Just check a constant to make sure it is defined and is the
-            correct value.  (The constant chosen has a non-zero value to
-            ensure that the code has both define the constant and set its
-            value correctly.)
-        """
-        logger = isc.log.Logger("child")
-        self.assertEqual(logger.DBGLVL_COMMAND, 10)
-
-    def test_param_reference(self):
-        """
-        Check whether passing a parameter to a logger causes a reference leak.
-        """
-        class LogParam:
-            def __str__(self):
-                return 'LogParam'
-        logger = isc.log.Logger("child")
-        param = LogParam()
-        orig_msgrefcnt = sys.getrefcount(param)
-        orig_idrefcnt = sys.getrefcount(self.TEST_MSG)
-        logger.info(self.TEST_MSG, param);
-        self.assertEqual(sys.getrefcount(self.TEST_MSG), orig_idrefcnt)
-        self.assertEqual(sys.getrefcount(param), orig_msgrefcnt)
-
-        # intentionally pass an invalid type for debug level.  It will
-        # result in TypeError.  The passed object still shouldn't leak a
-        # reference.
-        self.assertRaises(TypeError, logger.debug, param, self.TEST_MSG, param)
-        self.assertEqual(sys.getrefcount(param), orig_msgrefcnt)
-
-    def test_bad_parameter(self):
-        # a log parameter cannot be converted to a string object.
-        class LogParam:
-            def __str__(self):
-                raise ValueError("LogParam can't be converted to string")
-        logger = isc.log.Logger("child")
-        self.assertRaises(ValueError, logger.info, self.TEST_MSG, LogParam())
-
-if __name__ == '__main__':
-    unittest.main()
diff --git a/src/lib/python/isc/log/tests/log_test.py.in b/src/lib/python/isc/log/tests/log_test.py.in
new file mode 100644
index 0000000..09bdf22
--- /dev/null
+++ b/src/lib/python/isc/log/tests/log_test.py.in
@@ -0,0 +1,207 @@
+# Copyright (C) 2011  Internet Systems Consortium.
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
+# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+import os
+os.environ['B10_FROM_SOURCE'] = '@abs_top_srcdir@'
+
+# This tests it can be loaded, nothing more yet
+import isc.log
+import unittest
+import json
+import sys
+import bind10_config
+from isc.config.ccsession import path_search
+
+class LogDict(unittest.TestCase):
+    def setUp(self):
+        # We work on a test dictionary now.
+        isc.log.set_test_dictionary(True)
+    def tearDown(self):
+        # Return to the global dictionary
+        isc.log.set_test_dictionary(False)
+
+    def test_load_msgs(self):
+        # Try loading a message and see it's there, but nothing more
+        self.assertEqual(isc.log.create_message("ID", "Text"), "ID")
+        self.assertEqual(isc.log.get_message("ID"), "Text")
+        self.assertEqual(isc.log.get_message("no-ID"), None)
+
+class Manager(unittest.TestCase):
+    def tearDown(self):
+        isc.log.reset()
+
+    def test_init_debug(self):
+        # We try calling it now only, as we don't have any other functions
+        # to check the outcome by it. Once we add the logger class, we may
+        # check more.
+        isc.log.init("root", "DEBUG", 50, None)
+
+    def test_init_defaults(self):
+        # We try calling it now only, as we don't have any other functions
+        # to check the outcome by it. Once we add the logger class, we may
+        # check more.
+        isc.log.init("root")
+
+    def test_init_notfound(self):
+        # This should not throw, because the C++ one doesn't. Should we really
+        # ignore errors like missing file?
+        isc.log.init("root", "INFO", 0, "/no/such/file");
+
+    def test_log_config_update(self):
+        log_spec = json.dumps(isc.config.module_spec_from_file(path_search('logging.spec', bind10_config.PLUGIN_PATHS)).get_full_spec())
+
+        self.assertRaises(TypeError, isc.log.log_config_update)
+        self.assertRaises(TypeError, isc.log.log_config_update, 1)
+        self.assertRaises(TypeError, isc.log.log_config_update, 1, 1)
+        self.assertRaises(TypeError, isc.log.log_config_update, 1, 1, 1)
+
+        self.assertRaises(TypeError, isc.log.log_config_update, 1, log_spec)
+        self.assertRaises(TypeError, isc.log.log_config_update, [], log_spec)
+        self.assertRaises(TypeError, isc.log.log_config_update, "foo", log_spec)
+        self.assertRaises(TypeError, isc.log.log_config_update, "{ '", log_spec)
+
+        # empty should pass
+        isc.log.log_config_update("{}", log_spec)
+
+        # bad spec
+        self.assertRaises(TypeError, isc.log.log_config_update, "{}", json.dumps({"foo": "bar"}))
+
+        # Try a correct one
+        log_conf = json.dumps({"loggers":
+                                [{"name": "b10-xfrout", "output_options":
+                                    [{"output": "/tmp/bind10.log",
+                                       "destination": "file",
+                                       "flush": True}]}]})
+        isc.log.log_config_update(log_conf, log_spec)
+
+class Logger(unittest.TestCase):
+    def tearDown(self):
+        isc.log.reset()
+
+    def setUp(self):
+        isc.log.init("root", "DEBUG", 50)
+        self.sevs = ['INFO', 'WARN', 'ERROR', 'FATAL']
+        self.TEST_MSG = isc.log.create_message('TEST_MESSAGE', '%1')
+
+    # Checks defaults of the logger
+    def defaults(self, logger):
+        self.assertEqual(logger.get_effective_severity(), "DEBUG")
+        self.assertEqual(logger.get_effective_debug_level(), 50)
+
+    def test_default_severity(self):
+        logger = isc.log.Logger("child")
+        self.defaults(logger)
+
+    # Try changing the severities little bit
+    def test_severity(self):
+        logger = isc.log.Logger("child")
+        logger.set_severity('DEBUG', 25)
+        self.assertEqual(logger.get_effective_severity(), "DEBUG")
+        self.assertEqual(logger.get_effective_debug_level(), 25)
+        for sev in self.sevs:
+            logger.set_severity(sev)
+            self.assertEqual(logger.get_effective_severity(), sev)
+            self.assertEqual(logger.get_effective_debug_level(), 0)
+        # Return to default
+        logger.set_severity(None)
+        self.defaults(logger)
+
+    def test_enabled(self):
+        logger = isc.log.Logger("child")
+        self.sevs.insert(0, 'DEBUG')
+        methods = {
+            'DEBUG': logger.is_debug_enabled,
+            'INFO': logger.is_info_enabled,
+            'WARN': logger.is_warn_enabled,
+            'ERROR': logger.is_error_enabled,
+            'FATAL': logger.is_fatal_enabled
+        }
+        for sev in self.sevs:
+            logger.set_severity(sev)
+            enabled = False
+            for tested in self.sevs:
+                if tested == sev:
+                    enabled = True
+                self.assertEqual(methods[tested](), enabled)
+        logger.set_severity('DEBUG', 50)
+        self.assertTrue(logger.is_debug_enabled())
+        self.assertTrue(logger.is_debug_enabled(0))
+        self.assertTrue(logger.is_debug_enabled(50))
+        self.assertFalse(logger.is_debug_enabled(99))
+
+    def test_invalid_params(self):
+        """
+           Tests invalid arguments for logging functions. The output is tested
+           in check_output.sh.
+        """
+        logger = isc.log.Logger("child")
+        methods = [
+            logger.info,
+            logger.warn,
+            logger.error,
+            logger.fatal
+        ]
+        for meth in methods:
+            # Not enough arguments
+            self.assertRaises(TypeError, meth)
+            # Bad type
+            self.assertRaises(TypeError, meth, 1)
+        # Too few arguments
+        self.assertRaises(TypeError, logger.debug, 42)
+        self.assertRaises(TypeError, logger.debug)
+        # Bad type
+        self.assertRaises(TypeError, logger.debug, "42", "hello")
+
+    def test_dbglevel_constants(self):
+        """
+            Just check a constant to make sure it is defined and is the
+            correct value.  (The constant chosen has a non-zero value to
+            ensure that the code has both define the constant and set its
+            value correctly.)
+        """
+        logger = isc.log.Logger("child")
+        self.assertEqual(logger.DBGLVL_COMMAND, 10)
+
+    def test_param_reference(self):
+        """
+        Check whether passing a parameter to a logger causes a reference leak.
+        """
+        class LogParam:
+            def __str__(self):
+                return 'LogParam'
+        logger = isc.log.Logger("child")
+        param = LogParam()
+        orig_msgrefcnt = sys.getrefcount(param)
+        orig_idrefcnt = sys.getrefcount(self.TEST_MSG)
+        logger.info(self.TEST_MSG, param);
+        self.assertEqual(sys.getrefcount(self.TEST_MSG), orig_idrefcnt)
+        self.assertEqual(sys.getrefcount(param), orig_msgrefcnt)
+
+        # intentionally pass an invalid type for debug level.  It will
+        # result in TypeError.  The passed object still shouldn't leak a
+        # reference.
+        self.assertRaises(TypeError, logger.debug, param, self.TEST_MSG, param)
+        self.assertEqual(sys.getrefcount(param), orig_msgrefcnt)
+
+    def test_bad_parameter(self):
+        # a log parameter cannot be converted to a string object.
+        class LogParam:
+            def __str__(self):
+                raise ValueError("LogParam can't be converted to string")
+        logger = isc.log.Logger("child")
+        self.assertRaises(ValueError, logger.info, self.TEST_MSG, LogParam())
+
+if __name__ == '__main__':
+    unittest.main()



More information about the bind10-changes mailing list