SVN: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/ Moved logging to its own feature.

Christian Theune <[email protected]>
Newsgroups gmane.comp.web.zope.zope3.cvs
Message-ID <[email protected]>
Log message for revision 86341:
  Moved logging to its own feature.
  

Changed:
  A   zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/logsupport.py
  U   zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py

-=-
Added: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/logsupport.py
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/logsupport.py	                        (rev 0)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/logsupport.py	2008-05-04 12:06:43 UTC (rev 86341)
@@ -0,0 +1,65 @@
+##############################################################################
+#
+# Copyright (c) 2004-2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Logging support.
+
+This code is pretty much untested and was only mechanically refactored.
+
+The module name is not 'logging' because of a name collision with Python's
+logging module.
+
+$Id: __init__.py 86218 2008-05-03 14:17:26Z ctheune $
+"""
+
+import logging
+import logging.config
+import os.path
+
+from zope.testing import doctest
+import zope.testing.testrunner.feature
+
+
+class Logging(zope.testing.testrunner.feature.Feature):
+
+    active = True
+
+    def global_setup(self):
+        # Get the log.ini file from the current directory instead of
+        # possibly buried in the build directory.  TODO: This isn't
+        # perfect because if log.ini specifies a log file, it'll be
+        # relative to the build directory.  Hmm...  logini =
+        # os.path.abspath("log.ini")
+
+        logini = os.path.abspath("log.ini")
+        if os.path.exists(logini):
+            logging.config.fileConfig(logini)
+        else:
+            # If there's no log.ini, cause the logging package to be
+            # silent during testing.
+            root = logging.getLogger()
+            root.addHandler(NullHandler())
+            logging.basicConfig()
+
+        if os.environ.has_key("LOGGING"):
+            level = int(os.environ["LOGGING"])
+            logging.getLogger().setLevel(level)
+
+
+class NullHandler(logging.Handler):
+    """Logging handler that drops everything on the floor.
+
+    We require silence in the test environment.  Hush.
+    """
+
+    def emit(self, record):
+        pass


Property changes on: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/logsupport.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py	2008-05-04 11:51:38 UTC (rev 86340)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py	2008-05-04 12:06:43 UTC (rev 86341)
@@ -20,7 +20,6 @@
 import cStringIO
 import gc
 import glob
-import logging
 import os
 import pdb
 import sys
@@ -39,6 +38,7 @@
 from zope.testing.testrunner.options import get_options
 import zope.testing.testrunner.coverage
 import zope.testing.testrunner.doctest
+import zope.testing.testrunner.logsupport
 
 
 real_pdb_set_trace = pdb.set_trace
@@ -170,6 +170,7 @@
         # XXX I moved this here mechanically.
         self.test_directories = test_dirs(self.options, {})
 
+        self.features.append(zope.testing.testrunner.logsupport.Logging(self))
         self.features.append(zope.testing.testrunner.coverage.Coverage(self))
         self.features.append(zope.testing.testrunner.doctest.DocTest(self))
 
@@ -181,11 +182,6 @@
         # to make tests of the test runner work properly. :)
         pdb.set_trace = real_pdb_set_trace
 
-        # Set the default logging policy.
-        # XXX There are no tests for this logging behavior.
-        # It's not at all clear that the test runner should be doing this.
-        configure_logging()
-
         # Setup profiling
         if (self.options.profile
             and sys.version_info[:3] <= (2,4,1)
@@ -638,45 +634,11 @@
                         post_mortem(sys.exc_info())
                 else:
                     raise
-                    
+
         output.stop_set_up(time.time() - t)
         setup_layers[layer] = 1
 
-def configure_logging():
-    """Initialize the logging module."""
-    import logging.config
 
-    # Get the log.ini file from the current directory instead of
-    # possibly buried in the build directory.  TODO: This isn't
-    # perfect because if log.ini specifies a log file, it'll be
-    # relative to the build directory.  Hmm...  logini =
-    # os.path.abspath("log.ini")
-
-    logini = os.path.abspath("log.ini")
-    if os.path.exists(logini):
-        logging.config.fileConfig(logini)
-    else:
-        # If there's no log.ini, cause the logging package to be
-        # silent during testing.
-        root = logging.getLogger()
-        root.addHandler(NullHandler())
-        logging.basicConfig()
-
-    if os.environ.has_key("LOGGING"):
-        level = int(os.environ["LOGGING"])
-        logging.getLogger().setLevel(level)
-
-
-class NullHandler(logging.Handler):
-    """Logging handler that drops everything on the floor.
-
-    We require silence in the test environment.  Hush.
-    """
-
-    def emit(self, record):
-        pass
-
-
 class TestResult(unittest.TestResult):
 
     def __init__(self, options, tests, layer_name=None):
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.