[Zconfig] SVN: ZConfig/trunk/ make sure we can run through the
re-opening operation more than once
Fred L. Drake, Jr.
fdrake at gmail.com
Thu Jun 21 15:35:40 EDT 2007
Log message for revision 76917:
make sure we can run through the re-opening operation more than once
Changed:
U ZConfig/trunk/ZConfig/components/logger/loghandler.py
U ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py
U ZConfig/trunk/setup.py
-=-
Modified: ZConfig/trunk/ZConfig/components/logger/loghandler.py
===================================================================
--- ZConfig/trunk/ZConfig/components/logger/loghandler.py 2007-06-21 18:42:36 UTC (rev 76916)
+++ ZConfig/trunk/ZConfig/components/logger/loghandler.py 2007-06-21 19:35:39 UTC (rev 76917)
@@ -72,7 +72,7 @@
_remove_from_reopenable(self._wr)
def reopen(self):
- self.close()
+ self.stream.close()
self.stream = open(self.baseFilename, self.mode)
Modified: ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py
===================================================================
--- ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py 2007-06-21 18:42:36 UTC (rev 76916)
+++ ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py 2007-06-21 19:35:39 UTC (rev 76917)
@@ -319,21 +319,32 @@
return logging.LogRecord(
"foo.bar", logging.ERROR, __file__, 42, msg, (), ())
+ # This goes through the reopening operation *twice* to make
+ # sure that we don't lose our handle on the handler the first
+ # time around.
+
fn = self.mktemp()
h = loghandler.FileHandler(fn)
h.handle(mkrecord("message 1"))
- nfn = self.move(fn)
+ nfn1 = self.move(fn)
h.handle(mkrecord("message 2"))
h.reopen()
h.handle(mkrecord("message 3"))
+ nfn2 = self.move(fn)
+ h.handle(mkrecord("message 4"))
+ h.reopen()
+ h.handle(mkrecord("message 5"))
h.close()
# Check that the messages are in the right files::
- text1 = open(nfn).read()
- text2 = open(fn).read()
+ text1 = open(nfn1).read()
+ text2 = open(nfn2).read()
+ text3 = open(fn).read()
self.assert_("message 1" in text1)
self.assert_("message 2" in text1)
self.assert_("message 3" in text2)
+ self.assert_("message 4" in text2)
+ self.assert_("message 5" in text3)
def test_logfile_reopening(self):
paths = self.mktemp(), self.mktemp(), self.mktemp()
@@ -343,22 +354,34 @@
# Build the loggers from the configuration, and write to them:
conf.loggers[0]().info("message 1")
conf.loggers[1]().info("message 2")
- npaths = [self.move(fn) for fn in paths]
+ npaths1 = [self.move(fn) for fn in paths]
#
- # We expect this to re-open the original files, so we'll have
- # six files instead of three.
+ # We expect this to re-open the original filenames, so we'll
+ # have six files instead of three.
#
loghandler.reopenFiles()
#
# 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 should not have all six files:
+ # We expect this to re-open the original filenames, so we'll
+ # have nine files instead of six.
+ #
+ loghandler.reopenFiles()
+ #
+ # Write to them again:
+ conf.loggers[0]().info("message 5")
+ conf.loggers[1]().info("message 6")
+ #
+ # We should now have all nine files:
for fn in paths:
self.assert_(os.path.isfile(fn), "%r must exist" % fn)
- for fn in npaths:
+ 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)
def test_suite():
Modified: ZConfig/trunk/setup.py
===================================================================
--- ZConfig/trunk/setup.py 2007-06-21 18:42:36 UTC (rev 76916)
+++ ZConfig/trunk/setup.py 2007-06-21 19:35:39 UTC (rev 76917)
@@ -22,7 +22,7 @@
setup(
name = name,
- version = "2.4a5",
+ version = "2.4a6",
author = "Fred L. Drake, Jr.",
author_email = "fred at zope.com",
description = "Structured Configuration Library",
More information about the ZConfig
mailing list