[Zope3-checkins] CVS: Zope3/src/zope/app/fssync/tests - __init__.py:1.1.2.1 sampleclass.py:1.1.2.1 testFSDirective.py:1.1.2.1 testFSRegistry.py:1.1.2.1
Guido van Rossum
guido@python.org
Thu, 1 May 2003 16:22:54 -0400
Update of /cvs-repository/Zope3/src/zope/app/fssync/tests
In directory cvs.zope.org:/tmp/cvs-serv7039/zope/app/fssync/tests
Added Files:
Tag: fssync-branch
__init__.py sampleclass.py testFSDirective.py
testFSRegistry.py
Log Message:
Converted the fssync tests. Still nothing runs, but it imports.
=== Added File Zope3/src/zope/app/fssync/tests/__init__.py ===
#
# This file is necessary to make this directory a package.
=== Added File Zope3/src/zope/app/fssync/tests/sampleclass.py ===
##############################################################################
#
# Copyright) 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.
#
##############################################################################
"""Test SampleClass for testing File-system synchronization services
$Id: sampleclass.py,v 1.1.2.1 2003/05/01 20:22:53 gvanrossum Exp $
"""
from zope.app.interfaces.fssync import IObjectDirectory, IObjectFile
class C1: "C1 Doc"
class C2: "C2 Doc"
class CDefaultAdapter:
"""Default File-system representation for object
"""
__implements__ = IObjectFile
def __init__(self, object):
self.context = object
def extra(self):
pass
def typeIdentifier(self):
return "Default"
def factory(self):
return "Default Factory"
def getBody(self):
return self.context.__doc__
def setBody(self):
pass
class CDirAdapter:
"""Directory Adapter
"""
__implements__ = IObjectDirectory
def __init__(self, object):
self.context = object
def extra(self):
pass
def typeIdentifier(self):
return "Folder"
def factory(self):
return "Folder Factory"
def contents(self):
return []
class CFileAdapter:
"""File Adapter
"""
__implements__ = IObjectFile
def __init__(self, object):
self.context = object
def extra(self):
pass
def typeIdentifier(self):
return "File"
def factory(self):
return "File Factory"
def getBody(self):
return self.context.__doc__
def setBody(self):
pass
=== Added File Zope3/src/zope/app/fssync/tests/testFSDirective.py ===
##############################################################################
#
# Copyright) 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.
#
##############################################################################
"""Test FSRegistry File-system synchronization services
$Id: testFSDirective.py,v 1.1.2.1 2003/05/01 20:22:53 gvanrossum Exp $
"""
from cStringIO import StringIO
from unittest import TestCase, TestSuite, main, makeSuite
from zope.configuration.xmlconfig import testxmlconfig as xmlconfig, XMLConfig
from zope.testing.cleanup import CleanUp # Base class w registry cleanup
from zope.app.fssync.fsregistry import getSynchronizer
from zope.app.interfaces.fssync \
import IGlobalFSSyncService, IObjectFile, IObjectDirectory
from zope.interface.verify import verifyObject
from zope.exceptions import DuplicationError, NotFoundError
from zope.configuration.exceptions import ConfigurationError
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.component.service import UndefinedService
from zope.app.fssync.tests.sampleclass \
import C1, C2, CDirAdapter, CFileAdapter, CDefaultAdapter
import zope.app.fssync
template = """
<zopeConfigure xmlns="http://namespaces.zope.org/zope"
xmlns:FSSync="http://namespaces.zope.org/FSSync">
%s
</zopeConfigure>"""
class Test(PlacelessSetup, TestCase):
"""
"""
def setUp(self):
PlacelessSetup.setUp(self)
XMLConfig('meta.zcml', zope.app.fssync)()
def testFSDirective(self):
"""Test for Synchrozier not found and Registering the
adapter for a class.
"""
from zope.app.fssync.tests.sampleclass import C1
# Register the adapter for the class
self.assertRaises(NotFoundError, getSynchronizer, C2())
xmlconfig(StringIO(template % (
"""
<FSSync:adapter
class_="zope.app.fssync.tests.sampleclass.C2"
factory="zope.app.fssync.tests.sampleclass.CDirAdapter"
/>
"""
)))
self.assertEqual(getSynchronizer(C2()).__class__, CDirAdapter)
def testFSDirectiveDefaultAdapter(self):
"""Test for getting default adapter for not registered Classes"""
xmlconfig(StringIO(template % (
"""
<FSSync:adapter
factory = "zope.app.fssync.tests.sampleclass.CDefaultAdapter"
/>
"""
)))
self.assertEqual(getSynchronizer(C2()).__class__, CDefaultAdapter)
def testFSDirectiveDuplicate(self):
"""Duplication test"""
xmlconfig(StringIO(template % (
"""
<FSSync:adapter
class_="zope.app.fssync.tests.sampleclass.C1"
factory="zope.app.fssync.tests.sampleclass.CDirAdapter"
/>
"""
)))
self.assertRaises(DuplicationError, xmlconfig, StringIO(template % (
"""
<FSSync:adapter
class_="zope.app.fssync.tests.sampleclass.C1"
factory="zope.app.fssync.tests.sampleclass.CFileAdapter"
/>
"""
)))
def test_suite():
return TestSuite((
makeSuite(Test),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/src/zope/app/fssync/tests/testFSRegistry.py ===
##############################################################################
#
# Copyright) 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.
#
##############################################################################
"""Test FSRegistry File-system synchronization services
$Id: testFSRegistry.py,v 1.1.2.1 2003/05/01 20:22:53 gvanrossum Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.testing.cleanup import CleanUp # Base class w registry cleanup
from zope.app.interfaces.fssync \
import IGlobalFSSyncService, IObjectFile, IObjectDirectory
from zope.interface.verify import verifyObject
from zope.exceptions import DuplicationError, NotFoundError
from zope.app.fssync.tests.sampleclass \
import C1, C2, CDirAdapter, CFileAdapter, CDefaultAdapter
from zope.app.fssync.fsregistry \
import getSynchronizer, provideSynchronizer, fsRegistry
class Test(CleanUp, TestCase):
"""Test Interface for FSRegistry Instance.
"""
def testInterfaceVerification(self):
verifyObject(IGlobalFSSyncService, fsRegistry)
def testFSRegistry(self):
""" Test Class and Factory registration and getSynchronizer to get
appropriate factory for that class.
"""
self.assertRaises(NotFoundError, getSynchronizer, C1())
provideSynchronizer(C1, CFileAdapter)
cl = C1()
fac = getSynchronizer(cl)
self.assertEqual(fac.__class__, CFileAdapter)
self.assertEqual(fac.getBody(), C1.__doc__)
provideSynchronizer(C2, CDirAdapter)
fac = getSynchronizer(C2())
self.assertEqual(fac.__class__, CDirAdapter)
self.assertEqual(fac.contents(), [])
def testFSRegitryDefaultFactory(self):
"""Test for default Factory
"""
provideSynchronizer(None, CDefaultAdapter)
fac = getSynchronizer(C1())
self.assertEqual(fac.__class__, CDefaultAdapter)
fac = getSynchronizer(C2())
self.assertEqual(fac.__class__, CDefaultAdapter)
def testFSRegDuplication(self):
"""Test for duplication in registring the same class in
to the Registry.
"""
provideSynchronizer(C2, CFileAdapter)
#Try to change the adapter for same class should
#throw a duplication error
self.assertRaises(DuplicationError,
provideSynchronizer, C2, CDirAdapter)
def test_suite():
return TestSuite((makeSuite(Test),))
if __name__=='__main__':
main(defaultTest='test_suite')