[Zope-Checkins] CVS: ZODB3/zLOG/tests - testzLogConfig.py:1.1
Fred L. Drake, Jr.
fred@zope.com
Fri, 10 Jan 2003 13:33:12 -0500
Update of /cvs-repository/ZODB3/zLOG/tests
In directory cvs.zope.org:/tmp/cvs-serv4197/tests
Added Files:
testzLogConfig.py
Log Message:
Preliminary support for configuring logging using ZConfig.
Needs more work, but can deal with at least logging to files and STDERR.
Log rotation has been tested.
=== Added File ZODB3/zLOG/tests/testzLogConfig.py ===
##############################################################################
#
# Copyright (c) 2002, 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests for zLOG configuration via ZConfig."""
import cStringIO as StringIO
import logging
import unittest
import ZConfig
import zLOG.tests
class TestzLOGConfig(unittest.TestCase):
_schema = None
_schematext = """
<schema>
<import package='zLOG'/>
<section type='logger' name='*' attribute='logger'/>
</schema>
"""
def get_schema(self):
if self._schema is None:
sio = StringIO.StringIO(self._schematext)
self.__class__._schema = ZConfig.loadSchemaFile(sio)
return self._schema
def get_config(self, text):
conf, handler = ZConfig.loadConfigFile(self.get_schema(),
StringIO.StringIO(text))
self.assert_(not handler)
return conf
def test_config_without_logger(self):
conf = self.get_config("")
self.assert_(conf.logger is None)
def test_config_without_handlers(self):
conf = self.get_config("<logger/>")
self.assert_(conf.logger is not None)
self.assertEqual(conf.logger.level, logging.INFO)
logger = conf.logger()
self.assert_(isinstance(logger, logging.Logger))
self.assertEqual(logger.handlers, [])
# XXX need to make sure each loghandler datatype gets exercised.
def test_suite():
return unittest.makeSuite(TestzLOGConfig)
if __name__ == '__main__':
unittest.main(defaultTest="test_suite")