[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture/tests - testService.py:1.1.2.1
Jim Fulton
jim@zope.com
Wed, 26 Dec 2001 17:04:07 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv19995/tests
Added Files:
Tag: Zope-3x-branch
testService.py
Log Message:
added basic service implementation
=== Added File Zope3/lib/python/Zope/ComponentArchitecture/tests/testService.py ===
##############################################################################
#
# Copyright (c) 2001 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
#
##############################################################################
from Zope.ComponentArchitecture import defineService, provideService, getService
from Zope.ComponentArchitecture import _clear
from Zope.ComponentArchitecture.Service import UndefinedService, InvalidService
from Zope.Exceptions import DuplicationError
from Interface import Interface
import unittest, sys
class IOne(Interface):
pass
class ITwo(Interface):
pass
class ServiceOne:
__implements__ = IOne
class ServiceTwo:
pass
class Test(unittest.TestCase):
def tearDown(self):
_clear()
def testNormal(self):
defineService('one', IOne)
c = ServiceOne()
provideService('one', c)
self.assertEqual(id(getService(None, 'one')), id(c))
def testDup(self):
defineService('one', IOne)
self.assertRaises(DuplicationError,
defineService,
'one', ITwo)
c = ServiceOne()
provideService('one', c)
c2 = ServiceOne()
self.assertRaises(DuplicationError,
provideService,
'one', c2)
self.assertEqual(id(getService(None, 'one')), id(c))
def testUndefined(self):
c = ServiceOne()
self.assertRaises(UndefinedService,
provideService,
'one', c)
def testInvalid(self):
defineService('one', IOne)
defineService('two', ITwo)
c = ServiceOne()
self.assertRaises(InvalidService,
provideService,
'two', c)
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())