[Zconfig]
SVN: ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py
- add test of the FileHandler.reopen() method
Fred L. Drake, Jr.
fdrake at gmail.com
Wed Jun 20 12:04:08 EDT 2007
Log message for revision 76845:
- add test of the FileHandler.reopen() method
- avoid deprecated tempfile.mktemp()
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 2007-06-20 16:01:04 UTC (rev 76844)
+++ ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py 2007-06-20 16:04:07 UTC (rev 76845)
@@ -16,6 +16,7 @@
import cStringIO as StringIO
import logging
+import os
import sys
import tempfile
import unittest
@@ -128,7 +129,8 @@
def test_with_logfile(self):
import os
- fn = tempfile.mktemp()
+ fd, fn = tempfile.mkstemp()
+ os.close(fd)
logger = self.check_simple_logger("<eventlog>\n"
" <logfile>\n"
" path %s\n"
@@ -138,8 +140,21 @@
logfile = logger.handlers[0]
self.assertEqual(logfile.level, logging.DEBUG)
self.assert_(isinstance(logfile, loghandler.FileHandler))
+ # Test the move-and-reopen behavior:
+ logger.propagate = False
+ logger.error("message 1")
+ os.rename(fn, fn + "-")
+ logger.error("message 2")
+ logfile.reopen()
+ logger.error("message 3")
logfile.close()
+ text1 = open(fn + "-").read()
+ text2 = open(fn).read()
+ self.assert_("message 1" in text1)
+ self.assert_("message 2" in text1)
+ self.assert_("message 3" in text2)
os.remove(fn)
+ os.remove(fn + "-")
def test_with_stderr(self):
self.check_standard_stream("stderr")
More information about the ZConfig
mailing list