[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture/tests - testServiceManagerContainer.py:1.1.2.4
Jim Fulton
jim@zope.com
Mon, 4 Mar 2002 12:01:35 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv16920
Modified Files:
Tag: Zope-3x-branch
testServiceManagerContainer.py
Log Message:
Numerous changes to make tests more reusable in test subclasses.
=== Zope3/lib/python/Zope/ComponentArchitecture/tests/testServiceManagerContainer.py 1.1.2.3 => 1.1.2.4 ===
from unittest import TestCase, TestSuite, main, makeSuite
-from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
from Zope.ComponentArchitecture.IServiceService import IServiceService
-from Zope.ComponentArchitecture.IServiceManagerContainer import IServiceManagerContainer
-from Zope.ComponentArchitecture.ServiceManagerContainer import ServiceManagerContainer
+from Zope.ComponentArchitecture.IServiceManagerContainer \
+ import IServiceManagerContainer
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
+from Interface import verify
class ServiceManager:
@@ -43,23 +43,28 @@
#
############################################################
-class TestServiceManagerContainer(CleanUp, TestCase):
-
+class BaseTestServiceManagerContainer:
+
"""This test is for objects that don't have service managers by
default and that always give back the service manager they were
- given."""
+ given.
- def _createInstance(self):
- return ServiceManagerContainer()
+
+ Subclasses need to define a method, '_Test__new', that takes no
+ arguments and that returns a new service manager
+ container that has no service manager."""
+
+ def testIServiceManagerContainerVerify(self):
+ verify(IServiceManagerContainer, self._Test__new())
def testHas(self):
- smc=self._createInstance()
+ smc=self._Test__new()
self.failIf(smc.hasServiceManager())
smc.setServiceManager(ServiceManager())
self.failUnless(smc.hasServiceManager())
def testGet(self):
- smc=self._createInstance()
+ smc=self._Test__new()
self.failUnless(smc.getServiceManager(self) is self)
self.assertRaises(ComponentLookupError, smc.getServiceManager)
sm=ServiceManager()
@@ -68,12 +73,21 @@
self.failUnless(smc.getServiceManager(self) is sm)
def testSet(self):
- smc=self._createInstance()
+ smc=self._Test__new()
self.assertRaises(Exception, smc.setServiceManager, self)
+
+
+class Test(BaseTestServiceManagerContainer, TestCase):
+ def _Test__new(self):
+ from Zope.ComponentArchitecture.ServiceManagerContainer \
+ import ServiceManagerContainer
+ return ServiceManagerContainer()
+
+
def test_suite():
return TestSuite((
- makeSuite(TestServiceManagerContainer),
+ makeSuite(Test),
))
if __name__=='__main__':