[Zope-Checkins] CVS: ZODB3/zLOG/tests - testzLog.py:1.9.42.2

Fred L. Drake, Jr. fred@zope.com
Tue, 17 Dec 2002 18:53:05 -0500


Update of /cvs-repository/ZODB3/zLOG/tests
In directory cvs.zope.org:/tmp/cvs-serv9964/zLOG/tests

Modified Files:
      Tag: ZODB3-fast-restart-branch
	testzLog.py 
Log Message:
Add a way to call on the stock configurability of the logging package.

=== ZODB3/zLOG/tests/testzLog.py 1.9.42.1 => 1.9.42.2 ===
--- ZODB3/zLOG/tests/testzLog.py:1.9.42.1	Tue Dec 17 14:32:41 2002
+++ ZODB3/zLOG/tests/testzLog.py	Tue Dec 17 18:53:05 2002
@@ -139,9 +139,62 @@
     """ Test alternate envvars EVENT_LOG_FILE and EVENT_LOG_SEVERITY """
     prefix = 'EVENT'
 
+class ConfigLogTest(StupidLogTest):
+    """ Test use of ZLOG_CONFIG_FILE envvar. """
+
+    def setLog(self, severity=0):
+        f = open(self.configfile, 'w')
+        f.write("\n".join(["[loggers]",
+                           "keys=root,event",
+                           "[handlers]",
+                           "keys=normal",
+                           "[formatters]",
+                           "keys=common",
+                           "[logger_root]",
+                           "level=NOTSET",
+                           "handlers=",
+                           "[logger_event]",
+                           "level=NOTSET",
+                           "handlers=normal",
+                           "parent=(root)",
+                           "qualname=event",
+                           "[handler_normal]",
+                           "class=FileHandler",
+                           "level=NOTSET",
+                           "formatter=common",
+                           "args=('" + self.path + "', 'a')",
+                           "filename=" + self.path,
+                           "mode=a",
+                           "[formatter_common]",
+                           "format=------",
+                           "       %(asctime)s %(message)s",
+                           "datefmt=%Y-%m-%dT%H:%M:%S",
+                           ""]))
+        f.close()
+        os.environ["ZLOG_CONFIG_FILE"] = self.configfile
+        if severity:
+            os.environ['EVENT_LOG_SEVERITY' % self.prefix] = str(severity)
+        self._severity = severity
+        zLOG.initialize()
+
+    def setUp(self):
+        StupidLogTest.setUp(self)
+        self.configfile = tempfile.mktemp()
+
+    def tearDown(self):
+        StupidLogTest.tearDown(self)
+        try:
+            os.remove(self.configfile)
+        except os.error:
+            pass
+        if os.environ.has_key("ZLOG_CONFIG_FILE"):
+            del os.environ["ZLOG_CONFIG_FILE"]
+
+
 def test_suite():
     suite = unittest.makeSuite(StupidLogTest, 'check')
     suite.addTest(unittest.makeSuite(EventLogTest, 'check'))
+    suite.addTest(unittest.makeSuite(ConfigLogTest, 'check'))
     return suite
 
 if __name__ == "__main__":