[z3-checkins] r14431 - z3/Five/trunk/browser/tests

philikon at codespeak.net philikon at codespeak.net
Fri Jul 8 15:48:55 CEST 2005


Author: philikon
Date: Fri Jul  8 15:48:53 2005
New Revision: 14431

Modified:
   z3/Five/trunk/browser/tests/test_recurse.py
Log:
convert test to doctest


Modified: z3/Five/trunk/browser/tests/test_recurse.py
==============================================================================
--- z3/Five/trunk/browser/tests/test_recurse.py	(original)
+++ z3/Five/trunk/browser/tests/test_recurse.py	Fri Jul  8 15:48:53 2005
@@ -19,45 +19,53 @@
 if __name__ == '__main__':
     execfile(os.path.join(sys.path[0], 'framework.py'))
 
-import unittest
-from Testing.ZopeTestCase import installProduct
-installProduct('Five')
-
-from OFS.Traversable import Traversable
-from zope.interface import Interface, implements
-from Products.Five.fiveconfigure import classDefaultViewable
-
-class IRecurse(Interface):
-    pass
-
-class Recurse(Traversable):
-    implements(IRecurse)
-
-    def view(self):
-        return self()
-
-    def __call__(self):
-        return 'foo'
-
-classDefaultViewable(Recurse)
-
-class RecursionTest(unittest.TestCase):
-
-    def setUp(self):
-        self.ob = Recurse()
-
-    def test_recursive_call(self):
-        from zope.app import zapi
-        from zope.publisher.interfaces.browser import IBrowserRequest
-        pres = zapi.getGlobalService('Presentation')
-        pres.setDefaultViewName(IRecurse, IBrowserRequest, 'view')
-        self.assertEquals(self.ob.view(), 'foo')
-        self.assertEquals(self.ob(), 'foo')
+def test_recursion():
+    """
+    Test recursion
+
+    This test makes sure that recursion is avoided for view lookup.
+    First, we need to set up a stub interface...
+
+      >>> from zope.interface import Interface, implements
+      >>> class IRecurse(Interface):
+      ...     pass
+      ...
+
+    and a class that is callable and has a view method:
+
+      >>> from OFS.Traversable import Traversable
+      >>> class Recurse(Traversable):
+      ...     implements(IRecurse)
+      ...     def view(self):
+      ...         return self()
+      ...     def __call__(self):
+      ...         return 'foo'
+      ...
+
+    Now we make the class default viewable and register a default view
+    name for it:
+
+      >>> from Products.Five.fiveconfigure import classDefaultViewable
+      >>> classDefaultViewable(Recurse)
+
+      >>> from zope.app import zapi
+      >>> from zope.publisher.interfaces.browser import IBrowserRequest
+      >>> pres = zapi.getGlobalService('Presentation')
+      >>> pres.setDefaultViewName(IRecurse, IBrowserRequest, 'view')
+
+    Here comes the actual test:
+
+      >>> ob = Recurse()
+      >>> ob.view()
+      'foo'
+      >>> ob()
+      'foo'
+    """
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(RecursionTest))
-    return suite
+    from Testing.ZopeTestCase import installProduct, ZopeDocTestSuite
+    installProduct('Five')
+    return ZopeDocTestSuite()
 
 if __name__ == '__main__':
     framework()


More information about the z3-checkins mailing list