[Zconfig] SVN: ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py more refactoring to keep nose from discovering tests defined in mix-ins

Fred Drake fdrake at gmail.com
Sat Feb 11 20:34:49 UTC 2012


Log message for revision 124379:
  more refactoring to keep nose from discovering tests defined in mix-ins

Changed:
  U   ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py

-=-
Modified: ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py
===================================================================
--- ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py	2012-02-11 20:25:24 UTC (rev 124378)
+++ ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py	2012-02-11 20:34:47 UTC (rev 124379)
@@ -407,10 +407,12 @@
         return logger
 
 
-class TestReopeningLogfilesHelper(LoggingTestHelper):
+class TestReopeningRotatingLogfiles(LoggingTestHelper, unittest.TestCase):
 
     # These tests should not be run on Windows.
 
+    handler_factory = loghandler.RotatingFileHandler
+
     _schematext = """
       <schema>
         <import package='ZConfig.components.logger'/>
@@ -418,6 +420,40 @@
       </schema>
     """
 
+    _sampleconfig_template = """
+      <logger>
+        name  foo.bar
+        <logfile>
+          path  %(path0)s
+          level debug
+          max-size 1mb
+          old-files 10
+        </logfile>
+        <logfile>
+          path  %(path1)s
+          level info
+          max-size 1mb
+          old-files 3
+        </logfile>
+        <logfile>
+          path  %(path1)s
+          level info
+          when D
+          old-files 3
+        </logfile>
+      </logger>
+
+      <logger>
+        name  bar.foo
+        <logfile>
+          path  %(path2)s
+          level info
+          max-size 10mb
+          old-files 10
+        </logfile>
+      </logger>
+    """
+
     def test_filehandler_reopen(self):
 
         def mkrecord(msg):
@@ -461,33 +497,6 @@
         self.assert_("message 4" in text2)
         self.assert_("message 5" in text3)
 
-
-class TestReopeningLogfiles(TestReopeningLogfilesHelper, unittest.TestCase):
-
-    handler_factory = loghandler.FileHandler
-
-    _sampleconfig_template = """
-      <logger>
-        name  foo.bar
-        <logfile>
-          path  %(path0)s
-          level debug
-        </logfile>
-        <logfile>
-          path  %(path1)s
-          level info
-        </logfile>
-      </logger>
-
-      <logger>
-        name  bar.foo
-        <logfile>
-          path  %(path2)s
-          level info
-        </logfile>
-      </logger>
-    """
-
     def test_logfile_reopening(self):
         #
         # This test only applies to the simple logfile reopening; it
@@ -505,7 +514,6 @@
         # Build the loggers from the configuration, and write to them:
         conf.loggers[0]().info("message 1")
         conf.loggers[1]().info("message 2")
-        npaths1 = [self.move(fn) for fn in paths]
         #
         # We expect this to re-open the original filenames, so we'll
         # have six files instead of three.
@@ -515,7 +523,6 @@
         # Write to them again:
         conf.loggers[0]().info("message 3")
         conf.loggers[1]().info("message 4")
-        npaths2 = [self.move(fn) for fn in paths]
         #
         # We expect this to re-open the original filenames, so we'll
         # have nine files instead of six.
@@ -528,11 +535,11 @@
         #
         # We should now have all nine files:
         for fn in paths:
+            fn1 = fn + ".1"
+            fn2 = fn + ".2"
             self.assert_(os.path.isfile(fn), "%r must exist" % fn)
-        for fn in npaths1:
-            self.assert_(os.path.isfile(fn), "%r must exist" % fn)
-        for fn in npaths2:
-            self.assert_(os.path.isfile(fn), "%r must exist" % fn)
+            self.assert_(os.path.isfile(fn1), "%r must exist" % fn1)
+            self.assert_(os.path.isfile(fn2), "%r must exist" % fn2)
         #
         # Clean up:
         for logger in conf.loggers:
@@ -541,48 +548,22 @@
                 logger.removeHandler(handler)
                 handler.close()
 
-    def test_filehandler_reopen_thread_safety(self):
-        # The reopen method needs to do locking to avoid a race condition
-        # with emit calls. For simplicity we replace the "acquire" and
-        # "release" methods with dummies that record calls to them.
 
-        fn = self.mktemp()
-        h = self.handler_factory(fn)
+class TestReopeningLogfiles(TestReopeningRotatingLogfiles):
 
-        calls = []
-        h.acquire = lambda: calls.append("acquire")
-        h.release = lambda: calls.append("release")
+    handler_factory = loghandler.FileHandler
 
-        h.reopen()
-        h.close()
-
-        self.assertEqual(calls, ["acquire", "release"])
-
-
-class TestReopeningRotatingLogfiles(
-    TestReopeningLogfilesHelper, unittest.TestCase):
-
     _sampleconfig_template = """
       <logger>
         name  foo.bar
         <logfile>
           path  %(path0)s
           level debug
-          max-size 1mb
-          old-files 10
         </logfile>
         <logfile>
           path  %(path1)s
           level info
-          max-size 1mb
-          old-files 3
         </logfile>
-        <logfile>
-          path  %(path1)s
-          level info
-          when D
-          old-files 3
-        </logfile>
       </logger>
 
       <logger>
@@ -590,14 +571,10 @@
         <logfile>
           path  %(path2)s
           level info
-          max-size 10mb
-          old-files 10
         </logfile>
       </logger>
     """
 
-    handler_factory = loghandler.RotatingFileHandler
-
     def test_logfile_reopening(self):
         #
         # This test only applies to the simple logfile reopening; it
@@ -615,6 +592,7 @@
         # Build the loggers from the configuration, and write to them:
         conf.loggers[0]().info("message 1")
         conf.loggers[1]().info("message 2")
+        npaths1 = [self.move(fn) for fn in paths]
         #
         # We expect this to re-open the original filenames, so we'll
         # have six files instead of three.
@@ -624,6 +602,7 @@
         # Write to them again:
         conf.loggers[0]().info("message 3")
         conf.loggers[1]().info("message 4")
+        npaths2 = [self.move(fn) for fn in paths]
         #
         # We expect this to re-open the original filenames, so we'll
         # have nine files instead of six.
@@ -636,11 +615,11 @@
         #
         # We should now have all nine files:
         for fn in paths:
-            fn1 = fn + ".1"
-            fn2 = fn + ".2"
             self.assert_(os.path.isfile(fn), "%r must exist" % fn)
-            self.assert_(os.path.isfile(fn1), "%r must exist" % fn1)
-            self.assert_(os.path.isfile(fn2), "%r must exist" % fn2)
+        for fn in npaths1:
+            self.assert_(os.path.isfile(fn), "%r must exist" % fn)
+        for fn in npaths2:
+            self.assert_(os.path.isfile(fn), "%r must exist" % fn)
         #
         # Clean up:
         for logger in conf.loggers:
@@ -649,6 +628,24 @@
                 logger.removeHandler(handler)
                 handler.close()
 
+    def test_filehandler_reopen_thread_safety(self):
+        # The reopen method needs to do locking to avoid a race condition
+        # with emit calls. For simplicity we replace the "acquire" and
+        # "release" methods with dummies that record calls to them.
+
+        fn = self.mktemp()
+        h = self.handler_factory(fn)
+
+        calls = []
+        h.acquire = lambda: calls.append("acquire")
+        h.release = lambda: calls.append("release")
+
+        h.reopen()
+        h.close()
+
+        self.assertEqual(calls, ["acquire", "release"])
+
+
 def test_logger_convenience_function_and_ommiting_name_to_get_root_logger():
     """
 



More information about the ZConfig mailing list