[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture/tests - testNextService.py:1.1 testService.py:1.3
Jim Fulton
jim@zope.com
Tue, 2 Jul 2002 19:44:15 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv17483/lib/python/Zope/ComponentArchitecture/tests
Modified Files:
testService.py
Added Files:
testNextService.py
Log Message:
Refactored service manager and service lookup get routines to be
consistent with the Zope 3 get style, using get and query
routines. Added some missing tests.
Moved the service-manager lookup hooks to
Zope.App.ComponentArchitecture.
=== Added File Zope3/lib/python/Zope/ComponentArchitecture/tests/testNextService.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: testNextService.py,v 1.1 2002/07/02 23:44:14 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
#############################################################################
# If your tests change any global registries, then uncomment the
# following import and include CleanUp as a base class of your
# test. It provides a setUp and tearDown that clear global data that
# has registered with the test cleanup framework. Don't use this
# tests outside the Zope package.
# from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
#############################################################################
from Interface import Interface
from Zope.ContextWrapper import Wrapper
from Zope.ComponentArchitecture.IServiceManagerContainer \
import IServiceManagerContainer
from Zope.ComponentArchitecture.IServiceManager import IServiceManager
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
class Test(TestCase):
def test_getNextServiceManager(self):
from Zope.ComponentArchitecture import getNextServiceManager
self.assertRaises(ComponentLookupError,
getNextServiceManager, None)
def test_getNextService(self):
from Zope.ComponentArchitecture import getNextService
self.assertRaises(ComponentLookupError,
getNextService, None, 'x')
def test_getNextServiceManager(self):
from Zope.ComponentArchitecture import queryNextServiceManager
self.assertEqual(queryNextServiceManager(None, ), None)
self.assertEqual(queryNextServiceManager(None, 1), 1)
def test_getNextService(self):
from Zope.ComponentArchitecture import queryNextService
self.assertEqual(queryNextService(None, 'x'), None)
self.assertEqual(queryNextService(None, 'x', 1), 1)
def test_suite():
return TestSuite((
makeSuite(Test),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Zope3/lib/python/Zope/ComponentArchitecture/tests/testService.py 1.2 => 1.3 ===
"""
-from Zope.ComponentArchitecture import getServiceDefinitions, getService, \
- getServiceManager
-from Zope.ComponentArchitecture.GlobalServiceManager import UndefinedService, \
- InvalidService
-from Zope.ComponentArchitecture.ServiceManagerContainer import \
- ServiceManagerContainer
-from Zope.Exceptions import DuplicationError
+import unittest
from Interface import Interface
+
+from Zope.Exceptions import DuplicationError
from Zope.Testing.CleanUp import CleanUp
-import unittest, sys
+from Zope.ComponentArchitecture \
+ import getServiceDefinitions, getService, getServiceManager
+from Zope.ComponentArchitecture.GlobalServiceManager \
+ import UndefinedService, InvalidService
+from Zope.ComponentArchitecture.ServiceManagerContainer \
+ import ServiceManagerContainer
+from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
+
+from Zope.ComponentArchitecture import queryService
class IOne(Interface):
pass
@@ -47,6 +51,10 @@
c = ServiceOne()
getServiceManager(None).provideService('one', c)
self.assertEqual(id(getService(None, 'one')), id(c))
+
+ def testFailedLookup(self):
+ self.assertRaises(ComponentLookupError, getService, None, 'two')
+ self.assertEqual(queryService(None, 'two'), None)
def testDup(self):
getServiceManager(None).defineService('one', IOne)