[z3-checkins] r18352 - in z3/sqlos/trunk: . ftests

jinty at codespeak.net jinty at codespeak.net
Tue Oct 11 04:39:21 CEST 2005


Author: jinty
Date: Tue Oct 11 04:39:18 2005
New Revision: 18352

Modified:
   z3/sqlos/trunk/README.txt
   z3/sqlos/trunk/ftests/test_doctest.py
Log:
Make the README.txt a functional doctest.

Modified: z3/sqlos/trunk/README.txt
==============================================================================
--- z3/sqlos/trunk/README.txt	(original)
+++ z3/sqlos/trunk/README.txt	Tue Oct 11 04:39:18 2005
@@ -89,6 +89,21 @@
 Making SQLObject-based objects editable inside Zope
 ---------------------------------------------------
 
+Firstly you need to create an IPerson interface::
+
+    >>> from zope.schema import TextLine
+    >>> from zope.interface import Interface, Attribute
+
+    >>> class IPerson(Interface):
+    ...
+    ...     id = Attribute('Id')
+    ...     username = TextLine(title=u'Username',
+    ... 		        description=u'The name of the user')
+    ...     fname = TextLine(title=u'Given Name',
+    ...                      description=u'The given name of the user')
+    ...     lname = TextLine(title=u'Surname',
+    ...                      description=u'The surname of the user')
+
 Now, for making the SQLObject's editable there are only a few more
 steps. We already created an interface called ISQLObject, with all the
 methods and declared that the SQLObject class implements this
@@ -98,18 +113,15 @@
 
 See this example::
 
- from zope.interface import implements
- from sqlobject import *
- from sqlos import SQLOS
- from myproject.interfaces import IPerson
-
- class Person(SQLOS):
-
-     implements(IPerson)
-
-     _columns = [StringCol('username', length=20, notNull=True),
-                 StringCol('fname', length=20, notNull=True),
-                 StringCol('lname', length=20, notNull=True),]
+    >>> from zope.interface import implements
+    >>> from sqlobject import *
+    >>> from sqlos import SQLOS
+
+    >>> class Person(SQLOS):
+    ...     implements(IPerson)
+    ...     _columns = [StringCol('username', length=20, notNull=True),
+    ...          StringCol('fname', length=20, notNull=True),
+    ...          StringCol('lname', length=20, notNull=True),]
 
 Here you can see that there is almost nothing special needed for
 making the object be recognized by Zope 3. In fact, if you remove the
@@ -119,21 +131,6 @@
 declare that an object implements a given interface in a separate
 file, or even in ZCML).
 
-Let's take a look at what the IPerson interface says::
-
- from zope.schema import TextLine
- from zope.interface import Interface, Attribute
-
- class IPerson(Interface):
-
-     id = Attribute('Id')
-     username = TextLine(title=u'Username',
-		     description=u'The name of the user')
-     fname    = TextLine(title=u'Given Name',
-                     description=u'The given name of the user')
-     lname    = TextLine(title=u'Surname',
-                     description=u'The surname of the user')
-
 As you can see, there's not much here either. We're just saying that
 classes that implement IPerson will have an ``id`` attribute (all
 SQLObject instance have that by default) and a ``username`` attribute,
@@ -223,26 +220,24 @@
 
 As always, the first step is to declare the interface::
 
-    from zope.app.container.constraints import ItemTypePrecondition
-    from sqlos.interfaces.container import ISQLObjectContainer
-    from myproject.interfaces import IPerson
-
-    class IPersonContainer(ISQLObjectContainer) :
-
-        def __setitem__(name, item) :
-            pass
-        __setitem__.precondition = ItemTypePrecondition( IPerson )
+    >>> from zope.app.container.constraints import ItemTypePrecondition
+    >>> from sqlos.interfaces.container import ISQLObjectContainer
+
+    >>> class IPersonContainer(ISQLObjectContainer) :
+    ...
+    ...     def __setitem__(name, item) :
+    ...         pass
+    ...     __setitem__.precondition = ItemTypePrecondition( IPerson )
 
 The zope container infrastructure checks the __setitem__ precondition
 to determine what type of content the container is allowed to contain.
 
 Next, define the implementation::
 
-    from sqlos.container import SQLObjectContainer
-    from myproject.interfaces import IPersonContainer
+    >>> from sqlos.container import SQLObjectContainer
 
-    class PersonContainer(SQLObjectContainer) :
-        implements(IPersonContainer)
+    >>> class PersonContainer(SQLObjectContainer) :
+    ...     implements(IPersonContainer)
 
 All that needs to be done at this point is to connect an
 implementation with the interface.  SQLObjectContainer provides all
@@ -312,21 +307,21 @@
 
 The code is as follows::
 
-    from zope.app.dublincore.interfaces import IZopeDublinCore
-
-    class PersonDublinCore(object):
-        """An adapter providing DublinCore metadata for IPerson objects"""
-
-        implements(IZopeDublinCore)
-        __used_for__ = IPerson
-
-        def __init__(self, context):
-            self.context = context
-
-        def Title(self) :
-            return "%s, %s" % (self.context.lname, self.context.fname)
+    >>> from zope.app.dublincore.interfaces import IZopeDublinCore
 
-        title = property(Title)
+    >>> class PersonDublinCore(object):
+    ...     """An adapter providing DublinCore metadata for IPerson objects"""
+    ...
+    ...     implements(IZopeDublinCore)
+    ...     __used_for__ = IPerson
+    ...
+    ...     def __init__(self, context):
+    ...         self.context = context
+    ...
+    ...     def Title(self) :
+    ...         return "%s, %s" % (self.context.lname, self.context.fname)
+    ...
+    ...     title = property(Title)
 
 
 

Modified: z3/sqlos/trunk/ftests/test_doctest.py
==============================================================================
--- z3/sqlos/trunk/ftests/test_doctest.py	(original)
+++ z3/sqlos/trunk/ftests/test_doctest.py	Tue Oct 11 04:39:18 2005
@@ -1,6 +1,12 @@
+import os
 from zope.testing import doctest
 from zope.app.tests.functional import FunctionalDocFileSuite
 
+here = os.path.dirname(__file__)
+readme = os.path.join('..', 'README.txt')
+
 def test_suite():
-    return FunctionalDocFileSuite('containers.txt',
-                                  optionflags=doctest.ELLIPSIS)
+    filelist = ['containers.txt']
+    if os.path.isfile(os.path.join(here, readme)):
+        filelist.append(readme)
+    return FunctionalDocFileSuite(*filelist)


More information about the z3-checkins mailing list