[Zope-Checkins] CVS: Zope3/lib/python/Zope/Event/tests - testLogger.py:1.1.2.1
Chris Withers
chrisw@nipltd.com
Sat, 23 Feb 2002 14:38:28 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Event/tests
In directory cvs.zope.org:/tmp/cvs-serv29832/tests
Added Files:
Tag: Zope-3x-branch
testLogger.py
Log Message:
Added Event Logger as a sample (but useful ;-) implementation of ISubscriber.
=== Added File Zope3/lib/python/Zope/Event/tests/testLogger.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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
#
##############################################################################
"""
Revision information:
$Id: testLogger.py,v 1.1.2.1 2002/02/23 19:38:27 chrisw Exp $
"""
import unittest, sys
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
from Zope.Event import subscribe, unsubscribe, publishEvent
from Zope.Event.ObjectEvent import ObjectAddedEvent
from Zope.Event.Logger import Logger
import zLOG
from zLOG import BLATHER, PANIC
class DopeyLogger:
def __init__(self):
self.result=[]
def log_write(self, subsystem, severity, summary, detail, error):
self.result.append((subsystem,severity,summary,detail,error))
class TestLogger1(CleanUp,unittest.TestCase):
eventlogger = Logger()
def setUp(self):
# futz a logger in for testing
self.__old_log_write = zLOG.log_write
self.logger = DopeyLogger()
zLOG.log_write = self.logger.log_write
# register a logger
subscribe(self.eventlogger)
# send an event
publishEvent(ObjectAddedEvent('foo'))
def tearDown(self):
#unsubscribe(self.eventlogger)
zLOG.log_write = self.__old_log_write
CleanUp.tearDown(self)
def testLogger(self):
"Test the logger logs appropriately"
# check the dopey logger
self.assertEqual(self.logger.result,
[
(
'Event.Logger',
BLATHER,
'Zope.Event.ObjectEvent.ObjectAddedEvent',
"{'_ObjectAddedEvent__location': 'foo'}\n",
None,
)
])
class TestLogger2(TestLogger1):
eventlogger = Logger(PANIC)
def testLogger(self):
"Test the logger logs appropriately"
# check the dopey logger
self.assertEqual(self.logger.result,
[
(
'Event.Logger',
PANIC,
'Zope.Event.ObjectEvent.ObjectAddedEvent',
"{'_ObjectAddedEvent__location': 'foo'}\n",
None,
)
])
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestLogger1),
unittest.makeSuite(TestLogger2),
))
if __name__=='__main__':
unittest.main(defaultTest='test_suite')