[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/onlinehelp/ 1. Added support for different source types.

Eckart Hertzler eckart at hertzler.de
Wed May 26 10:12:40 EDT 2004


Log message for revision 25008:

1. Added support for different source types.
The source type is determined by the file extension.

The supported source types are
 - plain text (*.txt)
 - structured text (*.stx)
 - restructured text (*.rst)

2. Changed tests of OnlineHelp and OnlineHelpTopic
to doctests





-=-
Added: Zope3/trunk/src/zope/app/onlinehelp/README.stx
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/README.stx	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/README.stx	2004-05-26 14:12:40 UTC (rev 25008)
@@ -0,0 +1,65 @@
+What's the Online Help System?
+
+    Stephan Richter has implemented a very basic Online Help that supports
+    plain text and HTML files for content in help topics. Topics are a piece
+    of the help document that contains useful information. Topics are also
+    containers and can simply contain further Topics. This way we can have
+    nested help pages, which will help with content organization. It is
+    possible to associate a topic with a particular view of an interface.
+    The online help system is implemented as global service.
+
+
+Usage:
+
+    To register help topic for your code, you need to add 'register'
+    directive in the configuration file (see example below). You can
+    specify the following attributes:
+
+    -  'parent'   - Location of this topic's parent in the OnlineHelp tree.
+                 Optional.
+
+    -  'id'       - The id of the help topic. Required.
+
+    -  'title'    - The title of the topic. It will be used in the tree as
+                  Identification. Required.
+
+    -  'doc_path' - Path to the file that contains the topic. Required.
+
+    -  'doc_type' - Defines the type of document this topic will be. Optional.
+
+    -  'for'      - The interface this topic apllies to. Optional.
+
+    -  'view'     - The name of the view for wich this topic is registered.
+                 Optional.
+
+    To unregister a particular help topic use directive unregister. You need
+    to specify the path to the help topic.
+
+
+Examples::
+
+    <configure
+        xmlns="http://namespaces.zope.org/zope"
+        xmlns:help="http://namespaces.zope.org/help"
+        >
+
+    ....
+
+    <!-- Register Help Topics -->
+
+    <help:register
+        id="ui"
+        title="Zope UI Help"
+        doc_path="./ui.txt"
+        />
+
+    <help:register 
+        id="welcome"
+        title="Welcome"
+        parent="ui"
+        for="zope.app.onlinehelp.interfaces.IOnlineHelpTopic"
+        view="index.html"
+        doc_path="./help.stx"
+        />
+
+    </configure>


Property changes on: Zope3/trunk/src/zope/app/onlinehelp/README.stx
___________________________________________________________________
Name: svn:eol-style
   + native

Deleted: Zope3/trunk/src/zope/app/onlinehelp/README.txt
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/README.txt	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/README.txt	2004-05-26 14:12:40 UTC (rev 25008)
@@ -1,61 +0,0 @@
-Online Help System
-
-  What's the Online Help System?
-
-    Stephan Richter has implemented a very basic Online Help that supports
-    plain text and HTML files for content in help topics. Topics are a piece
-    of the help document that contains useful information. Topics are also
-    containers and can simply contain further Topics. This way we can have
-    nested help pages, which will help with content organization. It is
-    possible to associate a topic with a particular view of an interface.
-    The online help system is implemented as global service.
-
-
-  Usage:
-
-    To register help topic for your code, you need to add 'register'
-    directive in the configuration file (see example below). You can
-    specify the following attributes:
-
-      parent   - Location of this topic's parent in the OnlineHelp tree.
-                 Optional.
-      id       - The id of the help topic. Required.
-      title    - The title of the topic. It will be used in the tree as
-                 Identification. Required.
-      doc_path - Path to the file that contains the topic. Required.
-      doc_type - Defines the type of document this topic will be. Optional.
-      for      - The interface this topic apllies to. Optional.
-      view     - The name of the view for wich this topic is registred.
-                 Optional.
-
-    To unregister a particular help topic use directive unregister. You need
-    to specify the path to the help topic.
-
-
-  Examples:
-
-    <configure
-        xmlns="http://namespaces.zope.org/zope"
-        xmlns:help="http://namespaces.zope.org/help"
-        >
-
-    ....
-
-    <!-- Register initial Help Topics -->
-
-    <help:register
-        id="ui"
-        title="Zope UI Help"
-        doc_path="./ui.txt"
-        />
-
-    <help:register 
-        id="welcome"
-        title="Welcome"
-        parent="ui"
-        for="zope.app.interfaces.onlinehelp.IOnlineHelpTopic"
-        view="zope.app.browser.onlinehelp.OnlineHelpTopicView"
-        doc_path="./help.txt"
-        />
-
-    </configure>

Modified: Zope3/trunk/src/zope/app/onlinehelp/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/__init__.py	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/__init__.py	2004-05-26 14:12:40 UTC (rev 25008)
@@ -19,69 +19,145 @@
 $Id$
 """
 import os
+#import os.path
 
 import zope.app
 from zope.app import zapi
 from zope.app.container.sample import SampleContainer
 from zope.app.traversing.interfaces import IContainmentRoot
-from zope.app.traversing.api import traverse
 
 from zope.app.onlinehelp.interfaces import IOnlineHelpTopic, IOnlineHelp
 from zope.interface import implements
 
 class OnlineHelpTopic(SampleContainer):
-    __doc__ = IOnlineHelpTopic.__doc__
+    """
+    Represents a Help Topic.
+    
+    >>> from zope.app.onlinehelp.tests.test_onlinehelp import testdir
+    >>> path = os.path.join(testdir(), 'help.txt')
 
+    Create a Help Topic from a file
+    
+    >>> topic = OnlineHelpTopic('Help',path)
+
+    Test the title
+    
+    >>> topic.title
+    'Help'
+
+    The type should be set to plaintext, since
+    the file extension is 'txt'
+    
+    >>> topic.type
+    'zope.source.plaintext'
+
+    Test the help content.
+
+    >>> topic.source
+    'This is a help!'
+
+    >>> path = os.path.join(testdir(), 'help.stx')
+    >>> topic = OnlineHelpTopic('Help',path)
+
+    The type should now be structured text
+    >>> topic.type
+    'zope.source.stx'
+
+    >>> path = os.path.join(testdir(), 'help.rst')
+    >>> topic = OnlineHelpTopic('Help',path)
+
+    The type should now be restructured text
+    >>> topic.type
+    'zope.source.rest'
+
+    """
     implements(IOnlineHelpTopic)
 
     title = u""
 
-    def __init__(self, title, path, doc_type='txt'):
+    source = None
+
+    path = u""
+
+    type = None
+
+    def __init__(self, title, path):
         """Initialize object."""
         self.title = title
-        self.setContentPath(path, doc_type)
-        super(OnlineHelpTopic, self).__init__()
+        self.path = path
 
-    def setContentPath(self, path, doc_type='txt'):
-        "See Zope.App.OnlineHelp.interfaces.IOnlineHelpTopic"
-        self._content_path = path
-        self._doc_type = doc_type
+        filename = os.path.basename(path.lower())
+        file_ext = 'txt'
+        if len(filename.split('.'))>1:
+            file_ext = filename.split('.')[-1]
 
-    def getContent(self):
-        "See Zope.App.OnlineHelp.interfaces.IOnlineHelpTopic"
-        raw = open(self._content_path).read()
+        self.type = 'zope.source.plaintext'
+        
+        if file_ext == ('rst' or 'rest') :
+            self.type = 'zope.source.rest'
+        elif file_ext == 'stx':
+            self.type = 'zope.source.stx'
+        
+        self.source = open(self.path).read()
 
-        if self._doc_type == 'txt':
-            # XXX This should be cleaned up when reST is implemented
-            raw = raw.replace('<', '&lt;')
-            raw = raw.replace('>', '&gt;')
-            raw = '<p>' + raw.replace('\n\n', '\n</p><p>') + '</p>'
-            raw = raw.replace('\n', '<br>')
-            raw = raw.replace('  ', '&nbsp;&nbsp;')
-            return raw
-        else:
-            return raw
+        super(OnlineHelpTopic, self).__init__()
 
 
 class OnlineHelp(OnlineHelpTopic):
-    __doc__ = IOnlineHelp.__doc__
+    """
+    >>> from zope.app.onlinehelp.tests.test_onlinehelp import testdir
+    >>> from zope.app.onlinehelp.tests.test_onlinehelp import I1
+    >>> path = os.path.join(testdir(), 'help.txt')
 
+    Create an onlinehelp instance
+    
+    >>> onlinehelp = OnlineHelp('Help', path)
+
+    First do the inteface verifing tests.
+    
+    >>> from zope.interface.verify import verifyObject
+    >>> from zope.app.traversing.interfaces import IContainmentRoot
+    >>> verifyObject(IOnlineHelp, onlinehelp)
+    True
+    >>> verifyObject(IContainmentRoot, onlinehelp)
+    True
+
+    Register a new subtopic for interface 'I1' and view 'view.html'
+    
+    >>> path = os.path.join(testdir(), 'help2.txt')
+    >>> onlinehelp.registerHelpTopic('', 'help2', 'Help 2',
+    ...     path, I1, 'view.html')
+
+    Test if the subtopic is set correctly
+    >>> onlinehelp['help2'].title
+    'Help 2'
+
+    >>> onlinehelp._registry[(I1, 'view.html')][0].title
+    'Help 2'
+
+    The help topic must be found if the onlinehelp is queried
+    with interface and view name.
+    
+    >>> onlinehelp.getTopicsForInterfaceAndView(I1, 'view.html')[0].title
+    'Help 2'
+    
+    """
     implements(IOnlineHelp, IContainmentRoot)
 
-    def __init__(self, title, path, doc_type='txt'):
+    def __init__(self, title, path):
         self._registry = {}
-        super(OnlineHelp, self).__init__(title, path, doc_type)
+        super(OnlineHelp, self).__init__(title, path)
 
     def getTopicsForInterfaceAndView(self, interface=None, view=None):
         "See Zope.App.OnlineHelp.interfaces.IOnlineHelp"
         return self._registry.get((interface, view), [])
 
     def registerHelpTopic(self, parent_path, id, title,
-                          doc_path, doc_type='txt', interface=None, view=None):
+                          doc_path, interface=None, view=None):
         "See Zope.App.OnlineHelp.interfaces.IOnlineHelp"
-        parent = traverse(self, parent_path)
+        parent = zapi.traverse(self, parent_path)
         # Create and add topic
-        parent[id] = OnlineHelpTopic(title, doc_path, doc_type)
+        parent[id] = OnlineHelpTopic(title, doc_path)
         topic = parent[id]
         # Add topic to registry
         if interface is not None:

Modified: Zope3/trunk/src/zope/app/onlinehelp/browser/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/browser/__init__.py	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/browser/__init__.py	2004-05-26 14:12:40 UTC (rev 25008)
@@ -22,22 +22,77 @@
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
 from zope.app.onlinehelp.interfaces import IOnlineHelpTopic
 
-class OnlineHelpTopicView(object):
-    """View for one particular help topic."""
+class TopicTreeView(object):
 
     def __init__(self, context, request, base_url=''):
         self.context = context
+        self.treecontext = context
         self.request = request
         self.base_url = base_url
-        self.onlinehelp = removeAllProxies(zapi.getRoot(self.context))
-        if base_url == '':
-            self.base_url = zapi.getPath(self.onlinehelp.context)+"/++help++"
 
     def getTopicTree(self):
         """ return the tree of help topics."""
-        self.context = zapi.getRoot(self.context)
+        # set up the root values
+        if self.base_url == '':
+            self.base_url = '/++help++'
+        self.treecontext = zapi.getService("OnlineHelp")
         return self.subtopics()
 
+    def listHelpItems(self):
+        """ recurse through the help topic tree"""
+        children=[]
+        for name, helpitem in self.treecontext.items():
+            info={}
+            info['title'] = helpitem.title
+            info['path'] = self.base_url+'/'+name
+            topic = TopicTreeView(
+                helpitem,
+                self.request,
+                self.base_url+'/'+name)
+
+            info['topics']=topic.subtopics()
+            children.append(info)
+
+        return children
+
+    subtopics = ViewPageTemplateFile('topiclink.pt')
+
+
+class OnlineHelpTopicView(TopicTreeView):
+    """View for one particular help topic."""
+
+    def __init__(self, context, request):
+        super(OnlineHelpTopicView, self).__init__(context, request)
+        self.context = context
+        self.request = request
+
+    def renderTopic(self):
+        """ render the source of the help topic """
+        source = zapi.createObject(None,
+                                   self.context.type,
+                                   self.context.source)
+        view = zapi.getView(removeAllProxies(source), '', self.request)
+        html = view.render()
+        return html
+
+class ContextHelpView(TopicTreeView):
+
+    def __init__(self, context, request):
+        super(ContextHelpView, self).__init__(context, request)
+        self.context = context
+        self.request = request
+        self.topic = None
+
+    def renderContextTopic(self):
+        """ retrieve and render the source of a context help topic """
+        topic = self.getContextHelpTopic()
+        source = zapi.createObject(None,
+                                   topic.type,
+                                   topic.source)
+        view = zapi.getView(removeAllProxies(source), '', self.request)
+        html = view.render()
+        return html
+
     def getContextHelpTopic(self):
         """ Retrieve a help topic based on the context of the
         help namespace.
@@ -53,63 +108,47 @@
         If nothing is found, return the onlinehelp root topic
 
         """
-        help_context = self.onlinehelp.context
-        topic = self.context
+        if self.topic is not None:
+            return self.topic
+
+        onlinehelp = zapi.getService("OnlineHelp")
+        help_context = onlinehelp.context
+        self.topic = self.context
         if IBrowserView.providedBy(help_context):
             # called from a view
             for iface in providedBy(zapi.getParent(help_context)):
                 # try for interface and view match
-                topics = self.onlinehelp.getTopicsForInterfaceAndView(
+                topics = onlinehelp.getTopicsForInterfaceAndView(
                     iface,
                     zapi.getName(help_context)
                     )
                 if len(topics)>0:
-                    topic = topics[0]
+                    self.topic = topics[0]
                     break
-            if topic == self.context:
+            if self.topic == self.context:
                 # nothing found for view try iface only
                 for iface in providedBy(zapi.getParent(help_context)):
-                    topics = self.onlinehelp.getTopicsForInterfaceAndView(
+                    topics = onlinehelp.getTopicsForInterfaceAndView(
                         iface,
                         None
                         )
                     if len(topics)>0:
-                        topic = topics[0]
+                        self.topic = topics[0]
                         break
         else:
             # called without view
             for iface in providedBy(help_context):
-                topics = self.onlinehelp.getTopicsForInterfaceAndView(
+                topics = onlinehelp.getTopicsForInterfaceAndView(
                     iface,
                     None
                     )
                 if len(topics)>0:
-                    topic = topics[0]
+                    self.topic = topics[0]
                     break
-                
+
         # XXX returns only the first of the matching topics.
         #     The page template only processes one topic
-        return topic
+        return self.topic
 
-    def listHelpItems(self):
-        """ recurse through the help topic tree"""
-        # 
-        children=[]
-        for name, helpitem in self.context.items():
-            info={}
-            info['title'] = helpitem.title
-            info['path'] = self.base_url+'/'+name
-            topic = OnlineHelpTopicView(
-                helpitem,
-                self.request,
-                self.base_url+'/'+name)
 
-            info['topics']=topic.subtopics()
-            children.append(info)
 
-        return children
-
-    subtopics = ViewPageTemplateFile('topiclink.pt')
-
-
-

Modified: Zope3/trunk/src/zope/app/onlinehelp/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/browser/configure.zcml	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/browser/configure.zcml	2004-05-26 14:12:40 UTC (rev 25008)
@@ -16,11 +16,17 @@
       >
 
       <page name="index.html" template="helptopic.pt" />
-      <page name="contexthelp.html" template="contexthelp.pt" />
       <page name="getTopicTree" attribute="getTopicTree" />
 
   </pages>
 
+  <page
+      for="zope.app.onlinehelp.interfaces.IOnlineHelp"
+      permission="zope.Public"
+      class=".ContextHelpView"
+      name="contexthelp.html" 
+      template="contexthelp.pt" />
+
   <menuItem
       for="*"
       filter="python:request.getURL().find('++help++')==-1"

Modified: Zope3/trunk/src/zope/app/onlinehelp/browser/contexthelp.pt
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/browser/contexthelp.pt	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/browser/contexthelp.pt	2004-05-26 14:12:40 UTC (rev 25008)
@@ -19,16 +19,12 @@
 
 <div metal:fill-slot="body">
 
-  <div tal:define="topic view/getContextHelpTopic"> 
-
-    <h1 tal:content="topic/title"
+    <h1 tal:content="view/getContextHelpTopic/title"
         i18n:translate="">Title of Help Topic</h1>
 
-    <p tal:content="structure topic/getContent"
+    <p tal:content="structure view/renderContextTopic"
         i18n:translate="">Content of Online Help.</p>
 
-  </div>
-
 </div>
 
 </body>

Modified: Zope3/trunk/src/zope/app/onlinehelp/browser/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/browser/ftests.py	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/browser/ftests.py	2004-05-26 14:12:40 UTC (rev 25008)
@@ -22,18 +22,18 @@
 from zope.app.folder.interfaces import IRootFolder
 from zope.app.file import File
 from zope.app.tests.functional import BrowserTestCase
-from zope.app.onlinehelp.tests.test_onlinehelptopic import testdir
+from zope.app.onlinehelp.tests.test_onlinehelp import testdir
 from zope.app.onlinehelp import help
 
 class Test(BrowserTestCase):
 
     def test_contexthelp(self):
         path = os.path.join(testdir(), 'help.txt')
-        help.registerHelpTopic('ui','help','Help',path, 'txt',
+        help.registerHelpTopic('ui','help','Help',path,
              IRootFolder,
              None)
         path = os.path.join(testdir(), 'help2.txt')
-        help.registerHelpTopic('ui','help2','Help2',path, 'txt',
+        help.registerHelpTopic('ui','help2','Help2',path,
              IRootFolder,
              'contents.html')
         root = self.getRootFolder()

Modified: Zope3/trunk/src/zope/app/onlinehelp/browser/helptopic.pt
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/browser/helptopic.pt	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/browser/helptopic.pt	2004-05-26 14:12:40 UTC (rev 25008)
@@ -23,7 +23,7 @@
   <h1 tal:content="context/title"
       i18n:translate="">Title of Help Topic</h1>
 
-  <p tal:content="structure context/getContent"
+  <p tal:content="structure view/renderTopic"
       i18n:translate="">Content of Online Help.</p>
 
 </div>

Modified: Zope3/trunk/src/zope/app/onlinehelp/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/configure.zcml	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/configure.zcml	2004-05-26 14:12:40 UTC (rev 25008)
@@ -39,7 +39,7 @@
   <help:register
       id="onlinehelp"
       title="Online help system"
-      doc_path="./README.txt"
+      doc_path="./README.stx"
       />
 
   <!-- include browser package -->

Modified: Zope3/trunk/src/zope/app/onlinehelp/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/interfaces.py	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/interfaces.py	2004-05-26 14:12:40 UTC (rev 25008)
@@ -17,9 +17,11 @@
 
 $Id$
 """
-from zope.schema import TextLine
+from zope.schema import TextLine, SourceText, Choice
 from zope.app.container.interfaces import IContainer
+from zope.i18n import MessageIDFactory
 
+_ = MessageIDFactory('messageboard')
 
 class IOnlineHelpTopic(IContainer):
     """A Topic is one help page that you could view. Topics will be able to
@@ -37,20 +39,31 @@
     """
 
     title = TextLine(
-        title = u"Help Topic Title",
-        description = u"The Title of a Help Topic",
-        default = u"Help Topic",
+        title = _(u"Help Topic Title"),
+        description = _(u"The Title of a Help Topic"),
+        default = _(u"Help Topic"),
         required = True)
 
-    def setContentPath(filename, doc_type="stx"):
-        """Tell the Topic where it can find"""
+    source = SourceText(
+        title=_(u"Source Text"),
+        description=_(u"Renderable source text of the topic."),
+        default=u"",
+        required=True)
 
-    def getContent():
-        """Get the content of the Topic's file and return it. If the contents
-        is STX or Plain Text, the content is processed to HTML at this
-        point."""
+    path = TextLine(
+        title = _(u"Path to the Topic"),
+        description = _(u"The Path to the Definition of a Help Topic"),
+        default = u"./README.TXT",
+        required = True)
 
-        
+    type = Choice(
+        title=_(u"Source Type"),
+        description=_(u"Type of the source text, e.g. structured text"),
+        default=u"zope.source.rest",
+        required = True,
+        vocabulary = "SourceTypes")
+
+
 class IOnlineHelp(IOnlineHelpTopic):
     """This service manages all the HelpTopics."""
 
@@ -58,22 +71,21 @@
         """Returns a list of Topics that were registered to be
         applicable to a particular view of an interface."""
 
-    def registerHelpTopic(parent_path, title, doc_path, doc_type, 
+    def registerHelpTopic(parent_path, id, title, doc_path,  
                           interface=None, view=None):
         """This method registers a topic at the correct place.
 
            parent_path -- Location of this topic's parent in the OnlineHelp
            tree.
 
+           id -- Specifies the id of the topic 
+
            title -- Specifies title of the topic. This title will be used in
            the tree as Identification.
 
            doc_path -- Specifies where the file that contains the topic
            content is located.
 
-           doc_type -- Defines the type of document this topic will
-           be. Examples (not necessarily available) are: TXT, reST, HTML
-
            interface -- Name of the interface for which the help topic is
            being registered. This can be optional, since not all topics must
            be bound to a particular interface.

Modified: Zope3/trunk/src/zope/app/onlinehelp/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/metaconfigure.py	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/metaconfigure.py	2004-05-26 14:12:40 UTC (rev 25008)
@@ -24,10 +24,7 @@
              view=None):
     """Register an OnlineHelp topic"""
 
-    # XXX This should be really autodetected.
-    doc_type="txt"
-
     _context.action(
         discriminator = ('registerHelpTopic', parent, id),
         callable = help.registerHelpTopic,
-        args = (parent, id, title, doc_path, doc_type, for_, view) )
+        args = (parent, id, title, doc_path, for_, view) )

Added: Zope3/trunk/src/zope/app/onlinehelp/tests/help.rst
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/tests/help.rst	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/tests/help.rst	2004-05-26 14:12:40 UTC (rev 25008)
@@ -0,0 +1 @@
+This is a ReST help!
\ No newline at end of file


Property changes on: Zope3/trunk/src/zope/app/onlinehelp/tests/help.rst
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope3/trunk/src/zope/app/onlinehelp/tests/help.stx
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/tests/help.stx	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/tests/help.stx	2004-05-26 14:12:40 UTC (rev 25008)
@@ -0,0 +1 @@
+This is a STX help!
\ No newline at end of file


Property changes on: Zope3/trunk/src/zope/app/onlinehelp/tests/help.stx
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: Zope3/trunk/src/zope/app/onlinehelp/tests/test_onlinehelp.py
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/tests/test_onlinehelp.py	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/tests/test_onlinehelp.py	2004-05-26 14:12:40 UTC (rev 25008)
@@ -16,54 +16,36 @@
 $Id$
 """
 import os
-from unittest import TestSuite, makeSuite
-from zope.app.tests import ztapi
-from zope.app.tests.placelesssetup import PlacelessSetup
+import unittest
+
 from zope.interface import Interface
-from zope.interface.verify import verifyObject
-from zope.app.onlinehelp import OnlineHelp, IOnlineHelp
-from zope.app.traversing.interfaces import ITraversable, IPhysicallyLocatable
-from zope.app.traversing.interfaces import IContainmentRoot, ITraverser
-from zope.app.location.traversing import LocationPhysicallyLocatable
+from zope.testing.doctestunit import DocTestSuite
+from zope.app.tests import ztapi
+from zope.app.tests import placelesssetup
+from zope.app.traversing.interfaces import ITraversable, IPhysicallyLocatable,\
+     ITraverser
 from zope.app.traversing.adapters import Traverser, DefaultTraversable
-from test_onlinehelptopic import TestOnlineHelpTopic, testdir
+from zope.app.location.traversing import LocationPhysicallyLocatable
 
 class I1(Interface):
     pass
 
-class TestOnlineHelp(PlacelessSetup, TestOnlineHelpTopic):
+def testdir():
+    import zope.app.onlinehelp.tests
+    return os.path.dirname(zope.app.onlinehelp.tests.__file__)
 
-    def setUp(self):
-        super(TestOnlineHelp, self).setUp()
-        ztapi.provideAdapter(None, ITraverser, Traverser)
-        ztapi.provideAdapter(None, ITraversable, DefaultTraversable)
-        ztapi.provideAdapter(None, IPhysicallyLocatable,
-                             LocationPhysicallyLocatable)
-        path = os.path.join(testdir(), 'help.txt')
-        self.topic = OnlineHelp('Help', path, 'txt')
+def setUp():
+    placelesssetup.setUp()
+    ztapi.provideAdapter(None, ITraverser, Traverser)
+    ztapi.provideAdapter(None, ITraversable, DefaultTraversable)
+    ztapi.provideAdapter(None, IPhysicallyLocatable,
+                         LocationPhysicallyLocatable)
 
-    def test_registerHelpTopic(self):
-        path = os.path.join(testdir(), 'help2.txt')
-        self.topic.registerHelpTopic('', 'help2', 'Help 2',
-                                     path, 'txt', I1, 'view.html')
-        self.assertEqual(self.topic['help2'].title, 'Help 2')
-        self.assertEqual(self.topic._registry[(I1, 'view.html')][0].title,
-                         'Help 2')
-        
-    def test_getTopicsForInterfaceAndView(self):
-        path = os.path.join(testdir(), 'help2.txt')
-        self.topic.registerHelpTopic('', 'help2', 'Help 2',
-                                     path, 'txt', I1, 'view.html')
-        self.assertEqual(
-            self.topic.getTopicsForInterfaceAndView(I1, 'view.html')[0].title,
-            'Help 2')
-            
-    def test_interface(self):
-        verifyObject(IOnlineHelp, self.topic)
-        verifyObject(IContainmentRoot, self.topic)
 
-
 def test_suite():
-    return TestSuite((
-        makeSuite(TestOnlineHelp),
-        ))
+      return unittest.TestSuite((
+          DocTestSuite('zope.app.onlinehelp', setUp=setUp),
+          ))
+  
+if __name__ == '__main__':
+      unittest.main(defaultTest='test_suite')

Deleted: Zope3/trunk/src/zope/app/onlinehelp/tests/test_onlinehelptopic.py
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/tests/test_onlinehelptopic.py	2004-05-26 14:07:15 UTC (rev 25007)
+++ Zope3/trunk/src/zope/app/onlinehelp/tests/test_onlinehelptopic.py	2004-05-26 14:12:40 UTC (rev 25008)
@@ -1,55 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2002, 2003 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 OnlineHelpTopic
-
-$Id$
-"""
-import os
-from unittest import TestCase, TestSuite, makeSuite
-from zope.interface.verify import verifyObject
-from zope.app.onlinehelp import OnlineHelpTopic, IOnlineHelpTopic
-
-def testdir():
-    import zope.app.onlinehelp.tests
-    return os.path.dirname(zope.app.onlinehelp.tests.__file__)
-
-class TestOnlineHelpTopic(TestCase):
-
-    def setUp(self):
-        path = os.path.join(testdir(), 'help.txt')
-        self.topic = OnlineHelpTopic('Help', path, 'txt')
-
-    def test_title(self):
-        self.assertEqual(self.topic.title, 'Help')
-        self.topic.title = 'Help1'
-        self.assertEqual(self.topic.title, 'Help1')
-        self.topic.title = 'Help2'
-        self.assertEqual(self.topic.title, 'Help2')
-
-    def test_content(self):
-        self.assertEqual(self.topic.getContent(),
-                         '<p>This is a help!</p>')
-        path = os.path.join(testdir(), 'help.txt')
-        self.topic.setContentPath(path, 'foo')
-        self.assertEqual(self.topic.getContent(),
-                         'This is a help!')
-                         
-    def test_interface(self):
-        verifyObject(IOnlineHelpTopic, self.topic)
-              
-
-def test_suite():
-    return TestSuite((
-        makeSuite(TestOnlineHelpTopic),
-        ))




More information about the Zope3-Checkins mailing list