[Zope3-checkins] CVS: Zope3/src/zope/app/apidoc/zcmlmodule - ftests.py:1.1 browser.py:1.3 tests.py:1.2

Stephan Richter srichter at cosmos.phy.tufts.edu
Sun Mar 28 18:42:20 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/apidoc/zcmlmodule
In directory cvs.zope.org:/tmp/cvs-serv23571/src/zope/app/apidoc/zcmlmodule

Modified Files:
	browser.py tests.py 
Added Files:
	ftests.py 
Log Message:


Added tests.




=== Added File Zope3/src/zope/app/apidoc/zcmlmodule/ftests.py ===
##############################################################################
#
# Copyright (c) 2003, 2004 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.
#
##############################################################################
"""Functional Tests for ZCML Documentation Module.

$Id: ftests.py,v 1.1 2004/03/28 23:42:19 srichter Exp $
"""
import unittest
from zope.testing.functional import BrowserTestCase

class ZCMLModuleTests(BrowserTestCase):
    """Just a couple of tests ensuring that the templates render."""

    def testMenu(self):
        response = self.publish(
            '/++apidoc++/ZCML/menu.html', 
            basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)
        body = response.getBody()
        self.assert_(body.find('All Namespaces') > 0)
        self.checkForBrokenLinks(body, '/++apidoc++/ZCML/menu.html',
                                 basic='mgr:mgrpw')

    def testDirectiveDetailsView(self):
        response = self.publish('/++apidoc++/ZCML/ALL/configure/index.html',
                                basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)
        body = response.getBody()
        self.assert_(body.find('<i>all namespaces</i>') > 0)
        self.checkForBrokenLinks(body,
                                 '/++apidoc++/ZCML/ALL/configure/index.html',
                                 basic='mgr:mgrpw')


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(ZCMLModuleTests),
        ))

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')


=== Zope3/src/zope/app/apidoc/zcmlmodule/browser.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/apidoc/zcmlmodule/browser.py:1.2	Wed Feb 25 17:26:47 2004
+++ Zope3/src/zope/app/apidoc/zcmlmodule/browser.py	Sun Mar 28 18:42:19 2004
@@ -24,10 +24,48 @@
 from zope.app.apidoc.ifacemodule.browser import InterfaceDetails
 from zope.app.apidoc.utilities import getPythonPath
 
-__metaclass__ = type
+class Menu(object):
+    """Menu View Helper Class
 
-class Menu:
-    """Menu View Helper Class"""
+    Examples::
+
+      >>> from zope.app.tree.node import Node 
+      >>> from zope.app.apidoc.zcmlmodule import Namespace, Directive
+      >>> from zope.app.apidoc.zcmlmodule import ZCMLModule
+      >>> from zope.app.apidoc.tests import Root
+      >>> menu = Menu()
+
+      >>> module = ZCMLModule()
+      >>> module.__parent__ = Root()
+      >>> module.__name__ = 'ZCML'
+
+      Namespace representing directives available in all namespaces.
+
+      >>> ns = Namespace(module, 'ALL')
+      >>> node = Node(ns)
+      >>> menu.getMenuTitle(node)
+      'All Namespaces'
+      >>> menu.getMenuLink(node) is None
+      True
+
+      From now on we use the browser namespace.
+      
+      >>> ns = Namespace(module, 'http://namespaces.zope.org/browser')
+      >>> node = Node(ns)
+      >>> menu.getMenuTitle(node)
+      'browser'
+      >>> menu.getMenuLink(node) is None
+      True
+
+      The namespace has a page directive.
+
+      >>> dir = Directive(ns, 'page', None, None, None)
+      >>> node = Node(dir)
+      >>> menu.getMenuTitle(node)
+      'page'
+      >>> menu.getMenuLink(node)
+      './http_co__sl__sl_namespaces.zope.org_sl_browser/page/index.html'
+    """
 
     def getMenuTitle(self, node):
         """Return the title of the node that is displayed in the menu."""
@@ -47,43 +85,144 @@
             return './'+zapi.name(ns) + '/' + zapi.name(obj) + '/index.html'
         return None
 
-class DirectiveDetails:
+
+class DirectiveDetails(object):
     """View class for a Directive."""
 
     def getSchema(self):
-        """Return the schema of the directive.""" 
+        """Return the schema of the directive.
+
+        Examples::
+        
+          >>> from zope.interface import Interface
+          >>> from zope.publisher.browser import TestRequest
+          >>> from tests import getDirective
+          >>> details = DirectiveDetails()
+          >>> details.context = getDirective()
+          >>> details.request = TestRequest()
+
+          >>> class IFoo(Interface):
+          ...     pass
+          >>> details.context.schema = IFoo
+          >>> iface = details.getSchema()
+          >>> if_class = iface.__class__
+          >>> if_class.__module__ + '.' + if_class.__name__
+          'zope.app.apidoc.ifacemodule.browser.InterfaceDetails'
+          >>> iface.context
+          <InterfaceClass zope.app.apidoc.zcmlmodule.browser.IFoo>
+        """
         schema = LocationProxy(self.context.schema,
                                self.context,
                                getPythonPath(self.context.schema))
-        return InterfaceDetails(schema, self.request)
+        details = InterfaceDetails()
+        details.context = schema
+        details.request = self.request
+        return details
 
     def getNamespaceName(self):
-        """Return the name of the namespace."""
+        """Return the name of the namespace.
+
+        Examples::
+
+          >>> from tests import getDirective
+          >>> details = DirectiveDetails()
+
+          >>> details.context = getDirective()
+          >>> details.getNamespaceName()
+          'http://namespaces.zope.org/browser'
+
+          >>> details.context.__parent__.__realname__ = 'ALL'
+          >>> details.getNamespaceName()
+          '<i>all namespaces</i>'
+        """
         name = zapi.getParent(self.context).getFullName()
         if name == 'ALL':
             return '<i>all namespaces</i>'
         return name
 
     def getFile(self):
-        """Get the file where the directive was declared."""
+        """Get the file where the directive was declared.
+
+        Examples::
+        
+          >>> from zope.configuration.xmlconfig import ParserInfo
+          >>> from tests import getDirective
+          >>> details = DirectiveDetails()
+          >>> details.context = getDirective()
+
+          >>> details.getFile() is None
+          True
+
+          >>> details.context.info = ParserInfo('foo.zcml', 2, 3)
+          >>> details.getFile()
+          'foo.zcml'
+
+        """
         info = removeAllProxies(self.context.info)
         if isinstance(info, ParserInfo):
             return info.file
         return None
 
     def getInfo(self):
-        """Get info, if available."""
+        """Get info, if available.
+
+        Examples::
+        
+          >>> from zope.configuration.xmlconfig import ParserInfo
+          >>> from tests import getDirective
+          >>> details = DirectiveDetails()
+          >>> details.context = getDirective()
+
+          >>> details.getInfo() is None
+          True
+
+          >>> details.context.info = ParserInfo('foo.zcml', 2, 3)
+          >>> details.getInfo()
+          File "foo.zcml", line 2.3
+        """
         info = removeAllProxies(self.context.info)
-        if isinstance(info, ParserInfo):
+        if not isinstance(info, ParserInfo):
             return None
         return info
     
     def getSubdirectives(self):
-        """Create a list of subdirectives."""
+        """Create a list of subdirectives.
+
+        Examples::
+        
+          >>> import pprint
+          >>> pprint = pprint.PrettyPrinter(width=69).pprint
+          >>> from zope.configuration.xmlconfig import ParserInfo
+          >>> from zope.interface import Interface
+          >>> from zope.publisher.browser import TestRequest
+          >>> from tests import getDirective
+          >>> details = DirectiveDetails()
+          >>> details.context = getDirective()
+          >>> details.request = TestRequest()
+
+          >>> class IFoo(Interface):
+          ...     pass
+
+          >>> details.getSubdirectives()
+          []
+
+          >>> details.context.subdirs = (('browser', 'foo', IFoo, 'info'),)
+          >>> info = details.getSubdirectives()[0]
+          >>> info['schema'] = info['schema'].__module__ + '.InterfaceDetails'
+          >>> info = info.items()
+          >>> info.sort()
+          >>> pprint(info)
+          [('info', 'info'),
+           ('name', 'foo'),
+           ('namespace', 'browser'),
+           ('schema', 'zope.app.apidoc.ifacemodule.browser.InterfaceDetails')]
+        """
         dirs = []
         for ns, name, schema, info in self.context.subdirs:
             schema = LocationProxy(schema, self.context, getPythonPath(schema))
-            schema = InterfaceDetails(schema, self.request)
+            schema = InterfaceDetails()
+            schema.context = schema
+            schema.request = self.request
             dirs.append({'namespace': ns,
                          'name': name,
                          'schema': schema,


=== Zope3/src/zope/app/apidoc/zcmlmodule/tests.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/apidoc/zcmlmodule/tests.py:1.1	Thu Feb 19 15:46:43 2004
+++ Zope3/src/zope/app/apidoc/zcmlmodule/tests.py	Sun Mar 28 18:42:19 2004
@@ -17,10 +17,44 @@
 """
 import unittest
 from zope.testing.doctestunit import DocTestSuite
+from zope.app.tests import placelesssetup, ztapi
+from zope.app.apidoc.tests import Root
+
+from zope.app.tree.interfaces import IUniqueId
+from zope.app.tree.adapters import LocationUniqueId 
+
+from zope.app.traversing.interfaces import IPhysicallyLocatable
+from zope.app.location import LocationPhysicallyLocatable
+
+from zope.app.apidoc.zcmlmodule import Namespace, Directive
+from zope.app.apidoc.zcmlmodule import ZCMLModule
+from zope.app.apidoc.tests import Root
+
+
+def setUp():
+    placelesssetup.setUp()
+
+    ztapi.provideAdapter(None, IUniqueId, LocationUniqueId)
+    ztapi.provideAdapter(None, IPhysicallyLocatable,
+                         LocationPhysicallyLocatable)
+
+def tearDown():
+    placelesssetup.tearDown()
+
+def getDirective():
+    module = ZCMLModule()
+    module.__parent__ = Root()
+    module.__name__ = 'ZCML'
+
+    ns = Namespace(module, 'http://namespaces.zope.org/browser')
+    return Directive(ns, 'page', None, None, ())
     
+
 def test_suite():
     return unittest.TestSuite((
         DocTestSuite('zope.app.apidoc.zcmlmodule'),
+        DocTestSuite('zope.app.apidoc.zcmlmodule.browser',
+                     setUp=setUp, tearDown=tearDown),
         ))
 
 if __name__ == '__main__':




More information about the Zope3-Checkins mailing list