[Zodb-checkins] CVS: ZODB3/zLOG/tests - testzLog.py:1.12.34.1
Tim Peters
tim.one at comcast.net
Mon Sep 15 12:45:27 EDT 2003
Update of /cvs-repository/ZODB3/zLOG/tests
In directory cvs.zope.org:/tmp/cvs-serv32171/zLOG/tests
Modified Files:
Tag: Zope-2_7-branch
testzLog.py
Log Message:
Port recent changes from 3.2 branch so that these tests stop leaving
junk files behind on Windows.
=== ZODB3/zLOG/tests/testzLog.py 1.12 => 1.12.34.1 ===
--- ZODB3/zLOG/tests/testzLog.py:1.12 Sun Nov 24 00:24:43 2002
+++ ZODB3/zLOG/tests/testzLog.py Mon Sep 15 12:45:26 2003
@@ -17,6 +17,7 @@
import tempfile
import unittest
import zLOG
+import logging
severity_string = {
-300: 'TRACE',
@@ -50,12 +51,22 @@
self.wipeEnvironment()
self.path = tempfile.mktemp()
self._severity = 0
+ # Windows cannot remove a file that's open. The logging code
+ # keeps the log file open, and I can't find an advertised API
+ # to tell the logger to close a log file. So here we cheat:
+ # tearDown() will close and remove all the handlers that pop
+ # into existence after setUp() runs. This breaks into internals,
+ # but I couldn't find a sane way to do it.
+ self.handlers = logging._handlers.keys() # capture current handlers
def tearDown(self):
- try:
- os.remove(self.path)
- except os.error:
- pass
+ # Close and remove all the handlers that came into existence
+ # since setUp ran.
+ for h in logging._handlers.keys():
+ if h not in self.handlers:
+ h.close()
+ del logging._handlers[h]
+ os.remove(self.path)
self.wipeEnvironment()
def setLog(self, severity=0):
@@ -111,14 +122,20 @@
self.setLog()
zLOG.LOG("basic", zLOG.INFO, "summary")
f = self.getLogFile()
- self.verifyEntry(f, subsys="basic", summary="summary")
+ try:
+ self.verifyEntry(f, subsys="basic", summary="summary")
+ finally:
+ f.close()
def checkDetail(self):
self.setLog()
zLOG.LOG("basic", zLOG.INFO, "xxx", "this is a detail")
f = self.getLogFile()
- self.verifyEntry(f, subsys="basic", detail="detail")
+ try:
+ self.verifyEntry(f, subsys="basic", detail="detail")
+ finally:
+ f.close()
def checkError(self):
self.setLog()
@@ -131,9 +148,13 @@
zLOG.LOG("basic", zLOG.ERROR, "raised exception", error=err)
f = self.getLogFile()
- self.verifyEntry(f, subsys="basic", summary="summary")
- self.verifyEntry(f, subsys="basic", severity=zLOG.ERROR,
- error=err)
+ try:
+ self.verifyEntry(f, subsys="basic", summary="summary")
+ self.verifyEntry(f, subsys="basic", severity=zLOG.ERROR,
+ error=err)
+ finally:
+ f.close()
+
class EventLogTest(StupidLogTest):
""" Test alternate envvars EVENT_LOG_FILE and EVENT_LOG_SEVERITY """
More information about the Zodb-checkins
mailing list