[Zope-Checkins] CVS: Zope3/lib/python/Zope/Configuration/tests - hookTestDummyModule.py:1.1.2.1 testHookRegistry.py:1.1.2.1 testNames.py:1.1.2.9
Gary Poster
garyposter@earthlink.net
Sun, 14 Apr 2002 17:21:03 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Configuration/tests
In directory cvs.zope.org:/tmp/cvs-serv2286/tests
Modified Files:
Tag: Zope-3x-branch
testNames.py
Added Files:
Tag: Zope-3x-branch
hookTestDummyModule.py testHookRegistry.py
Log Message:
added support for <hook /> and <hookable /> tags; won't be actually usable until the next commit, in which I point zope.zcml at configuration-meta.zcml. Also added a name normalization routine in names.py.
hookable tag sets up a possible object that can be overwritten:
<hookable module="Zope.ComponentArchitecture" name="getServiceManager" />
module is optional so you can also write
<hookable name=".getServiceManager" />
These are assuming you are setting up a hookable that you loaded in the package's __init__.py. Here's one more example, this time completely hypothetical (the other two will not be hypothetical after the next commit).
<hookable module="Zope.Event.hooks" name="publishEvent" />
You use a hook with the "hook" tag:
<hook module="Zope.ComponentArchitecture" name="getServiceManager"
implementation="Zope.App.OFS.ServiceManager.hooks._getServiceManager" />
or if you are in the right place in the file system, shorten the implementation value to ".hooks._getServiceManager".
Again, it won't be in use until later this evening, after I get back from doing other things. But you can glance at it now, if so desired.
=== Added File Zope3/lib/python/Zope/Configuration/tests/hookTestDummyModule.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.
#
##############################################################################
"""Hook test dummy module
$Id: hookTestDummyModule.py,v 1.1.2.1 2002/04/14 21:21:02 poster Exp $
"""
def dummyHookable():
return "original implementation"
=== Added File Zope3/lib/python/Zope/Configuration/tests/testHookRegistry.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.
#
##############################################################################
"""
$Id: testHookRegistry.py,v 1.1.2.1 2002/04/14 21:21:02 poster Exp $
"""
import unittest, sys
def dummyHook():
return "hooked implementation"
class HookRegistryTest(unittest.TestCase):
# def setUp(self):
#
# from Zope.Configuration.tests import Products_
# self.old=sys.modules.get('ZopeProducts', None)
# sys.modules['ZopeProducts']=Products_
#
# def tearDown(self):
# old=self.old
# if old is None: del sys.modules['ZopeProducts']
# else: sys.modules['ZopeProducts']=self.old
def testAddHookable(self):
from Zope.Configuration.HookRegistry import HookRegistry
hookableAddr='Zope.Configuration.tests.hookTestDummyModule.dummyHookable'
hookRegistry=HookRegistry()
hookRegistry.addHookable(hookableAddr)
hookables=hookRegistry.getHookables()
self.assertEquals(len(hookables), 1)
self.assertEquals(hookables[0][0], hookableAddr)
self.assertEquals(hookables[0][1],0)
def testAddDuplicateHookable(self):
from Zope.Configuration.HookRegistry import HookRegistry
from Zope.Exceptions import DuplicationError
hookableAddr='Zope.Configuration.tests.hookTestDummyModule.dummyHookable'
hookRegistry=HookRegistry()
hookRegistry.addHookable(hookableAddr)
self.assertRaises(DuplicationError, hookRegistry.addHookable,
hookableAddr)
def testAddInvalidHookable(self):
from Zope.Configuration.HookRegistry import HookRegistry, \
BadHookableError
hookRegistry=HookRegistry()
self.assertRaises(BadHookableError, hookRegistry.addHookable,
'foo.bar.this.should.not.resolve.anywhere')
self.assertRaises(BadHookableError, hookRegistry.addHookable,
'Zope')
self.assertRaises(BadHookableError, hookRegistry.addHookable,
'Zope.Configuration.HookRegistry.HookRegistry.addHookable')
def testAddHook(self):
from Zope.Configuration.HookRegistry import \
HookRegistry, BadHookError, DuplicateHookError, \
MissingHookableError
hookableParent='Zope.Configuration.tests.hookTestDummyModule'
hookableLast='dummyHookable'
hookableAddr='%s.%s' % (hookableParent, hookableLast)
hookRegistry=HookRegistry()
hookRegistry.addHookable(hookableAddr)
old=__import__(hookableParent,{},{}, ('__dict__',)) # for cleanup
old=getattr(old, hookableLast)
self.assertEquals(old(),"original implementation")
self.assertRaises(BadHookError, hookRegistry.addHook,
hookableAddr, 'foo.bar.this.should.not.resolve.anywhere')
hookRegistry.addHook(hookableAddr,
'Zope.Configuration.tests.testHookRegistry.dummyHook')
new=__import__(hookableParent,{},{}, ('__dict__',))
new=getattr(new, hookableLast)
self.assertEquals(new(), "hooked implementation")
self.assertRaises(DuplicateHookError, hookRegistry.addHook,
hookableAddr, 'Zope.Configuration.tests.testHookRegistry.test_suite')
self.assertRaises(MissingHookableError, hookRegistry.addHook,
'Zope.Configuration.tests.testHookRegistry.test_suite',
'Zope.Configuration.tests.testHookRegistry.dummyHook')
setattr(__import__(hookableParent,{},{}, ('__dict__',)), hookableLast, old) # cleanup
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(HookRegistryTest)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())
=== Zope3/lib/python/Zope/Configuration/tests/testNames.py 1.1.2.8 => 1.1.2.9 ===
#
##############################################################################
+"""
+
+$Id$
+"""
+
import unittest, sys
class NameTest(unittest.TestCase):
@@ -59,6 +64,28 @@
import Zope.App.ZMI
self.assertEquals(id(c), id(Zope.App.ZMI))
+
+ nameSet={
+ ('Zope.Configuration.tests','Noplace'):'Zope.Configuration.tests',
+ ('Zope.Configuration.tests.tests','Noplace'):'Zope.Configuration.tests+',
+ ('Zope.Configuration.tests.tests.tests','Noplace'):'Zope.Configuration.tests+',
+ ('Zope.Configuration.tests.tests.tests.','Noplace'):'Zope.Configuration.tests+',
+ ('Zope.Configuration.tests+','Noplace'):'Zope.Configuration.tests+',
+ ('Zope.Configuration.tests.tests.tests+','Noplace'):'Zope.Configuration.tests+',
+ ('Zope.Configuration.tests.','Noplace'):'Zope.Configuration.tests+',
+ ('.tests','Zope.Configuration'):'Zope.Configuration.tests',
+ ('.tests.tests','Zope.Configuration'):'Zope.Configuration.tests+',
+ ('.tests.tests.tests','Zope.Configuration'):'Zope.Configuration.tests+',
+ ('.tests.tests.tests.','Zope.Configuration'):'Zope.Configuration.tests+',
+ ('.tests+','Zope.Configuration'):'Zope.Configuration.tests+',
+ ('.tests.tests.tests+','Zope.Configuration'):'Zope.Configuration.tests+',
+ ('.tests.','Zope.Configuration'):'Zope.Configuration.tests+'
+ }
+
+ def testNormalizedName(self):
+ from Zope.Configuration.name import getNormalizedName
+ for args in self.nameSet:
+ self.assertEquals(self.nameSet[args], getNormalizedName(*args))
def test_suite():
loader=unittest.TestLoader()