Back to index

plone3  3.1.7
test_interface.py
Go to the documentation of this file.
00001 import unittest
00002 import doctest
00003 
00004 optionflags = doctest.REPORT_ONLY_FIRST_FAILURE | doctest.ELLIPSIS
00005 
00006 # Used in tests
00007 
00008 from zope.interface import Interface
00009 
00010 class IOne(Interface):
00011     pass
00012     
00013 class ITwo(Interface):
00014     pass
00015     
00016 class NotAnInterface(object):
00017     pass
00018 
00019 def test_interface_view(self):
00020     """Information about the interfaces of an object
00021     
00022     >>> from zope.interface import Interface, implements, directlyProvides, classProvides
00023     >>> from zope.component import provideAdapter, getMultiAdapter
00024     >>> from zope.publisher.interfaces.browser import IBrowserRequest
00025     >>> from zope.publisher.browser import TestRequest
00026     
00027     >>> from zope.annotation.interfaces import IAttributeAnnotatable
00028     >>> from zope.annotation.attribute import AttributeAnnotations
00029     >>> provideAdapter(AttributeAnnotations)
00030     
00031     >>> from plone.app.layout.globals.tests.test_interface import IOne, ITwo
00032     
00033     >>> class One(object):
00034     ...     implements(IOne)
00035     ...     classProvides(ITwo)
00036     
00037     >>> from plone.app.layout.globals.interface import InterfaceInformation
00038     >>> provideAdapter(InterfaceInformation, (Interface, IBrowserRequest), Interface, u'plone_interface_info')
00039     
00040     >>> obj = One()
00041     >>> request = TestRequest()
00042     
00043     >>> directlyProvides(request, IAttributeAnnotatable)
00044     >>> view = getMultiAdapter((obj, request), name=u'plone_interface_info')
00045     
00046     >>> view.provides('plone.app.layout.globals.tests.test_interface.IOne')
00047     True
00048     >>> view.provides('plone.app.layout.globals.tests.test_interface.ITwo')
00049     False
00050     >>> view.provides('plone.app.layout.globals.tests.test_interface.NotAnInterface')
00051     Traceback (most recent call last):
00052     ...
00053     ValueError: 'plone.app.layout.globals.tests.test_interface.NotAnInterface' is not a valid Interface.
00054     
00055     >>> view.class_provides('plone.app.layout.globals.tests.test_interface.IOne')
00056     False
00057     >>> view.class_provides('plone.app.layout.globals.tests.test_interface.ITwo')
00058     True
00059     >>> view.class_provides('plone.app.layout.globals.tests.test_interface.NotAnInterface')
00060     Traceback (most recent call last):
00061     ...
00062     ValueError: 'plone.app.layout.globals.tests.test_interface.NotAnInterface' is not a valid Interface.
00063     """
00064 
00065 def test_suite():
00066     suite = unittest.TestSuite()
00067     suite.addTest(doctest.DocTestSuite(optionflags=optionflags))
00068     return suite