[Zope-CVS] SVN: zope.tutorial/trunk/ Added tests for all the existing code.

Stephan Richter srichter at cosmos.phy.tufts.edu
Sat Nov 12 14:26:04 EST 2005


Log message for revision 40077:
  Added tests for all the existing code.
  

Changed:
  A   zope.tutorial/trunk/README.txt
  U   zope.tutorial/trunk/configure.zcml
  U   zope.tutorial/trunk/directives.txt
  U   zope.tutorial/trunk/interfaces.py
  U   zope.tutorial/trunk/metaconfigure.py
  _U  zope.tutorial/trunk/selenium/
  U   zope.tutorial/trunk/tests.py
  U   zope.tutorial/trunk/tutorial.py

-=-
Added: zope.tutorial/trunk/README.txt
===================================================================
--- zope.tutorial/trunk/README.txt	2005-11-12 19:13:45 UTC (rev 40076)
+++ zope.tutorial/trunk/README.txt	2005-11-12 19:26:03 UTC (rev 40077)
@@ -0,0 +1,74 @@
+================
+Online Tutorials
+================
+
+We have recently started to write our functional doctests using the
+``zope.testbrowser`` package. The advantage of using the testbrowser is, of
+course, that we are describing the real interaction of the user with the
+browser. This does not only provide much nicer documentation, but also
+provides us with additional information about the usage of the Web
+application.
+
+Let's imagine we could use those documentation files to create fully generated
+tutorials. This package provides the necessary framework to run testbrowser
+tests inside a real browser in a tutorial style:
+
+  >>> from zope.tutorial import tutorial
+
+Tutorial
+--------
+
+Each doctest file that you wish to be available as a tutorial is represented
+by the `Tutorial` class.
+
+
+Tutorial Manager
+----------------
+
+All tutorials are managed by the tutorial manager, which also serves as an
+entrance point in the Web UI.
+
+  >>> manager = tutorial.TutorialManager()
+
+The tutorial manager implements the `IReadContainer` interface to query for
+tutorials. Initially there are no tutorials:
+
+  >>> manager.keys()
+  []
+
+Once we add some tutorials by registering soem utilities,
+
+  >>> import zope.component
+
+  >>> tut1 = tutorial.Tutorial('Tutorial 1', 'tut1.txt')
+  >>> zope.component.provideUtility(tut1, name='tut1')
+
+  >>> tut2 = tutorial.Tutorial('Tutorial 2', 'tut2.txt')
+  >>> zope.component.provideUtility(tut2, name='tut2')
+
+we have some results:
+
+  >>> manager.items()
+  [(u'tut1', <Tutorial title='Tutorial 1', file='tut1.txt'>),
+   (u'tut2', <Tutorial title='Tutorial 2', file='tut2.txt'>)]
+
+
+`++tutorials++` Namespace
+-------------------------
+
+For URLs and TALES expression, a namespace is provided that provides you with
+an entrance point to the tutorial application. Once the namespace is created.
+
+  >>> parent = object()
+  >>> namespace = tutorial.tutorialsNamespace(parent)
+
+you can traverse the parent to the tutorial manager. If an empty name is
+passed into the namespace, the manager is returned:
+
+  >>> namespace.traverse('')
+  <zope.tutorial.tutorial.TutorialManager object at ...>
+
+If a name is provided, then the actual tutorial is looked up:
+
+  >>> namespace.traverse('tut1')
+  <Tutorial title='Tutorial 1', file='tut1.txt'>


Property changes on: zope.tutorial/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: zope.tutorial/trunk/configure.zcml
===================================================================
--- zope.tutorial/trunk/configure.zcml	2005-11-12 19:13:45 UTC (rev 40076)
+++ zope.tutorial/trunk/configure.zcml	2005-11-12 19:26:03 UTC (rev 40077)
@@ -16,6 +16,12 @@
       factory=".tutorial.tutorialsNamespace"
       />
 
+  <!-- Setup of initial tutorials -->
+
+  <include file="tutorials.zcml" />
+
+  <!-- Browser Configuration -->
+
   <include package=".browser" />
 
 </configure>

Modified: zope.tutorial/trunk/directives.txt
===================================================================
--- zope.tutorial/trunk/directives.txt	2005-11-12 19:13:45 UTC (rev 40076)
+++ zope.tutorial/trunk/directives.txt	2005-11-12 19:26:03 UTC (rev 40077)
@@ -22,7 +22,8 @@
 
   >>> context = xmlconfig.string('''
   ...     <configure
-  ...         xmlns="http://namespaces.zope.org/zope">
+  ...         xmlns="http://namespaces.zope.org/zope"
+  ...         i18n_domain="zope">
   ...       <tutorial
   ...           name="zope_tutorial_directive"
   ...           title="zope:tutorial Directive"
@@ -34,4 +35,5 @@
 not actually work in the Web interface. Now the tutorial is available:
 
   >>> list(zapi.getUtilitiesFor(interfaces.ITutorial))
-  [(u'zope_tutorial_directive', )]
+  [(u'zope_tutorial_directive',
+    <Tutorial title=u'zope:tutorial Directive', file=u'directives.txt'>)]

Modified: zope.tutorial/trunk/interfaces.py
===================================================================
--- zope.tutorial/trunk/interfaces.py	2005-11-12 19:13:45 UTC (rev 40076)
+++ zope.tutorial/trunk/interfaces.py	2005-11-12 19:26:03 UTC (rev 40077)
@@ -42,7 +42,7 @@
         description=u'The title of the tutorial.',
         required=True)
 
-    filename = zope.schema.URI(
-        title=u'File name',
+    path = zope.schema.URI(
+        title=u'File Path',
         description=u'Path to the file used for the tutorial',
         required=True)

Modified: zope.tutorial/trunk/metaconfigure.py
===================================================================
--- zope.tutorial/trunk/metaconfigure.py	2005-11-12 19:13:45 UTC (rev 40076)
+++ zope.tutorial/trunk/metaconfigure.py	2005-11-12 19:26:03 UTC (rev 40077)
@@ -17,7 +17,8 @@
 """
 __docformat__ = 'restructuredtext'
 
-from zope.tutorial import tutorial, interfaces
+from zope.tutorial import interfaces
+from zope.tutorial.tutorial import Tutorial
 from zope.app.component import metaconfigure
 
 def tutorial(_context, name, title, path):
@@ -26,5 +27,5 @@
     metaconfigure.utility(
         _context,
         provides = interfaces.ITutorial,
-        component = tutorial.Tutorial(title, path),
+        component = Tutorial(title, path),
         name = name)


Property changes on: zope.tutorial/trunk/selenium
___________________________________________________________________
Name: svn:externals
   + javascript svn://selenium.codehaus.org/selenium/scm/trunk/code/javascript
license svn://selenium.codehaus.org/selenium/scm/trunk/code/license
doc svn://selenium.codehaus.org/selenium/scm/trunk/code/doc



Modified: zope.tutorial/trunk/tests.py
===================================================================
--- zope.tutorial/trunk/tests.py	2005-11-12 19:13:45 UTC (rev 40076)
+++ zope.tutorial/trunk/tests.py	2005-11-12 19:26:03 UTC (rev 40077)
@@ -20,12 +20,19 @@
 import unittest
 from zope.testing import doctest
 from zope.testing.doctestunit import DocFileSuite
-from zope.app.testing import setup
+from zope.app.testing import placelesssetup
 
+
 def test_suite():
     return unittest.TestSuite((
+        DocFileSuite('README.txt',
+                     setUp=placelesssetup.setUp,
+                     tearDown=placelesssetup.tearDown,
+                     optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+                     ),
         DocFileSuite('directives.txt',
-                     setUp=setup.SetUp, tearDown=setup.TearDown,
+                     setUp=placelesssetup.setUp,
+                     tearDown=placelesssetup.tearDown,
                      optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
                      ),
         ))

Modified: zope.tutorial/trunk/tutorial.py
===================================================================
--- zope.tutorial/trunk/tutorial.py	2005-11-12 19:13:45 UTC (rev 40076)
+++ zope.tutorial/trunk/tutorial.py	2005-11-12 19:26:03 UTC (rev 40077)
@@ -16,34 +16,34 @@
 $Id$
 """
 __docformat__ = "reStructuredText"
-
+import os
 import zope.interface
 from zope.app.apidoc import utilities
 from zope.app import location
+from zope.app import zapi
 
 from zope.tutorial import interfaces
 
 
 class TutorialManager(utilities.ReadContainerBase):
     """TutorialManager"""
-
     zope.interface.implements(interfaces.ITutorialManager,
                               location.interfaces.ILocation)
 
-    def __init__(self, parent):
+    def __init__(self, parent=None):
         self.__parent__ = parent
         self.__name__ = '++tutorials++'
 
     def get(self, key, default=None):
         """See zope.app.container.interfaces.IReadContainer"""
-        utility = zapi.queryUtility(ITutorial, key, default)
+        utility = zapi.queryUtility(interfaces.ITutorial, key, default)
         if utility != default:
             location.locate(utility, self, key)
         return utility
 
     def items(self):
         """See zope.app.container.interfaces.IReadContainer"""
-        items = list(zapi.getUtilitiesFor(ITutorial))
+        items = list(zapi.getUtilitiesFor(interfaces.ITutorial))
         items.sort()
         utils = []
         for key, value in items:
@@ -52,14 +52,27 @@
         return utils
 
 
+class Tutorial(object):
+    """Tutorial"""
+    zope.interface.implements(interfaces.ITutorial)
+
+    def __init__(self, title, path):
+        self.title = title
+        self.path = path
+
+    def __repr__(self):
+        return '<%s title=%r, file=%r>' %(
+            self.__class__.__name__, self.title, os.path.split(self.path)[-1])
+
+
 class tutorialsNamespace(object):
     """Used to traverse the `++tutorials++` namespace"""
 
-    def __init__(self, ob, request=None):
+    def __init__(self, ob=None, request=None):
         self.tutorialManager = TutorialManager(ob)
 
-    def traverse(self, name, ignore):
+    def traverse(self, name, ignore=None):
         if name == '':
             return self.tutorialManager
         else:
-            return self.tutorialManager[key]
+            return self.tutorialManager[name]



More information about the Zope-CVS mailing list