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

Fred L. Drake, Jr. fred@zope.com
Wed, 18 Dec 2002 15:46:04 -0500


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

Modified Files:
      Tag: ZODB3-fast-restart-branch
	testzLog.py 
Log Message:
- Some refactoring
- wipeEnvironment(): make sure we always wipe the ZLOG_CONFIG_FILE envvar
- add tests that guard against the UnboundLocalError Guido triggered
  using EVENT_LOG_FILE=''.


=== ZODB3/zLOG/tests/testzLog.py 1.9.42.2 => 1.9.42.3 ===
--- ZODB3/zLOG/tests/testzLog.py:1.9.42.2	Tue Dec 17 18:53:05 2002
+++ ZODB3/zLOG/tests/testzLog.py	Wed Dec 18 15:46:03 2002
@@ -28,13 +28,8 @@
      300: 'PANIC',
     }
 
-class StupidLogTest(unittest.TestCase):
-    """Test zLOG with the default implementation.
 
-    The default implementation uses the environment variables
-    STUPID_LOG_FILE and STUPID_LOG_SEVERITY.
-    """
-    prefix = 'STUPID'
+class LogTestBase(unittest.TestCase):
 
     def wipeEnvironment(self):
         if os.environ.has_key('STUPID_LOG_FILE'):
@@ -45,17 +40,14 @@
             del os.environ['STUPID_LOG_SEVERITY']
         if os.environ.has_key('EVENT_LOG_SEVERITY'):
             del os.environ['EVENT_LOG_SEVERITY']
+        if os.environ.has_key('ZLOG_CONFIG_FILE'):
+            del os.environ['ZLOG_CONFIG_FILE']
 
     def setUp(self):
         self.wipeEnvironment()
-        self.path = tempfile.mktemp()
         self._severity = 0
 
     def tearDown(self):
-        try:
-            os.remove(self.path)
-        except os.error:
-            pass
         self.wipeEnvironment()
 
     def setLog(self, severity=0):
@@ -65,6 +57,26 @@
         self._severity = severity
         zLOG.initialize()
 
+
+class StupidLogTest(LogTestBase):
+    """Test zLOG with the default implementation.
+
+    The default implementation uses the environment variables
+    STUPID_LOG_FILE and STUPID_LOG_SEVERITY.
+    """
+    prefix = 'STUPID'
+
+    def setUp(self):
+        LogTestBase.setUp(self)
+        self.path = tempfile.mktemp()
+
+    def tearDown(self):
+        try:
+            os.remove(self.path)
+        except os.error:
+            pass
+        LogTestBase.tearDown(self)
+
     def verifyEntry(self, f, time=None, subsys=None, severity=None,
                     summary=None, detail=None, error=None):
         # skip to the beginning of next entry
@@ -187,14 +199,25 @@
             os.remove(self.configfile)
         except os.error:
             pass
-        if os.environ.has_key("ZLOG_CONFIG_FILE"):
-            del os.environ["ZLOG_CONFIG_FILE"]
 
+class StderrStupidLogTest(LogTestBase):
+    prefix = 'STUPID'
+
+    def setUp(self):
+        self.path = ''
+
+    def checkEmptyLogFile(self):
+        self.setLog()
+
+class StderrEventLogTest(StderrStupidLogTest):
+    prefix = 'EVENT'
 
 def test_suite():
     suite = unittest.makeSuite(StupidLogTest, 'check')
     suite.addTest(unittest.makeSuite(EventLogTest, 'check'))
     suite.addTest(unittest.makeSuite(ConfigLogTest, 'check'))
+    suite.addTest(unittest.makeSuite(StderrStupidLogTest, 'check'))
+    suite.addTest(unittest.makeSuite(StderrEventLogTest, 'check'))
     return suite
 
 if __name__ == "__main__":