[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ClassDirective/tests - __init__.py:1.1.2.1 testDirectives.py:1.1.2.1

Steve Alexander steve@cat-box.net
Wed, 29 May 2002 13:19:29 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/ClassDirective/tests
In directory cvs.zope.org:/tmp/cvs-serv14383/lib/python/Zope/App/ClassDirective/tests

Added Files:
      Tag: Zope3InWonderland-branch
	__init__.py testDirectives.py 
Log Message:
Added first small part of the new "class" directive.


=== Added File Zope3/lib/python/Zope/App/ClassDirective/tests/__init__.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.
# 
##############################################################################
""" Zope.App.ClassDirective unit tests """


=== Added File Zope3/lib/python/Zope/App/ClassDirective/tests/testDirectives.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: testDirectives.py,v 1.1.2.1 2002/05/29 17:19:28 stevea Exp $
"""

import unittest, sys

from Zope.Configuration.xmlconfig import xmlconfig
from StringIO import StringIO
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
from Zope.Configuration.xmlconfig import ZopeXMLConfigurationError

from Interface import Interface

class ExampleClass:
    pass
    
class IExample(Interface):
    pass

# explicitly import ExampleClass and IExample using full paths
# so that they are the same objects as resolve will get.
from Zope.App.ClassDirective.tests.testDirectives import ExampleClass, IExample

def configfile(s):
    return StringIO("""<zopeConfigure
      xmlns='http://namespaces.zope.org/zope'>
      %s
      </zopeConfigure>
      """ % s)

def metaConfigure():
    xmlconfig(StringIO("""
<zopeConfigure xmlns='http://namespaces.zope.org/zope'>

  <!-- Zope.App.ClassDirective -->
  <directives namespace="http://namespaces.zope.org/zope">
    <directive name="class"
               attributes="class"
               handler="Zope.App.ClassDirective.metaConfigure.classDirective" >
      <subdirective name="implements"
                    attributes="interface" />
    </directive>
  </directives>

</zopeConfigure>
    """))

class TestClassDirective(CleanUp, unittest.TestCase):
    def setUp(self):
        metaConfigure()
        try:
            del ExampleClass.__implements__
        except AttributeError:
            pass
            
    def testRegister(self):
        f = configfile("""
<class class="Zope.App.ClassDirective.tests.testDirectives.ExampleClass">
  <implements interface="Zope.App.ClassDirective.tests.testDirectives.IExample" />
</class>
                       """)
        xmlconfig(f)
        self.failUnless(IExample.isImplementedByInstancesOf(ExampleClass))
        

def test_suite():
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    suite.addTest(loader.loadTestsFromTestCase(TestClassDirective))
    return suite


if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())