[Checkins] SVN: Sandbox/darrylcousins/mars.macro/src/mars/macro/ Working up tests

Darryl Cousins darryl at darrylcousins.net.nz
Tue Jul 17 07:59:45 EDT 2007


Log message for revision 78068:
  Working up tests

Changed:
  U   Sandbox/darrylcousins/mars.macro/src/mars/macro/macro.txt
  U   Sandbox/darrylcousins/mars.macro/src/mars/macro/tests.py

-=-
Modified: Sandbox/darrylcousins/mars.macro/src/mars/macro/macro.txt
===================================================================
--- Sandbox/darrylcousins/mars.macro/src/mars/macro/macro.txt	2007-07-17 11:56:01 UTC (rev 78067)
+++ Sandbox/darrylcousins/mars.macro/src/mars/macro/macro.txt	2007-07-17 11:59:45 UTC (rev 78068)
@@ -5,8 +5,8 @@
 This package may be used to configure z3c.macro macros. It is worth while also
 reading the README from that package, the following is a snippet from that file:
 
-The z3c.macro package provides a adapter and a TALES expression for a expliciter and
-flexibler macro handling using the adapter registry for macros. 
+ The z3c.macro package provides a adapter and a TALES expression for a expliciter and
+ flexibler macro handling using the adapter registry for macros. 
 
 The idea being that a template is registered as an adapter providing IMacroTemplate 
 
@@ -19,18 +19,17 @@
   >>> import zope.component
   >>> from zope.publisher.interfaces.browser import IBrowserView
   >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+  >>> import os, tempfile
+  >>> temp_dir = tempfile.mkdtemp()
+
+We'll need a context for the views.
+
   >>> class Content(object):
   ...     zope.interface.implements(zope.interface.Interface)
 
   >>> content = Content()
 
-We also create a temp dir for sample templates which we define later for 
-testing:
 
-  >>> import os, tempfile
-  >>> temp_dir = tempfile.mkdtemp()
-
-
 Macro Template
 --------------
 
@@ -57,25 +56,12 @@
 looked up also defaults to factory.__name__.lower() if grok.name has not been
 used.
 
-Grok the factory
-----------------
-
 In the test we manually ``grok`` the factory, normally this happens when a
 module is ``grokked`` on start up.
 
-To do so we need also to set up a fake module info class to pass to the macro
-factory grokker.
-
-  >>> from martian.interfaces import IModuleInfo
-  >>> class ModuleInfo(object):
-  ...     zope.interface.implements(IModuleInfo)
-  ...     path = ''
-  ...     def getAnnotation(self, name, default):
-  ...         return default
-
   >>> from mars.macro.meta import MacroFactoryGrokker
   >>> MacroFactoryGrokker().grok('macro.test', Navigation, zope.interface.Interface,
-  ...                               ModuleInfo(), None)
+  ...                               module_info, None)
   True
 
 The TALES ``macro`` Expression
@@ -98,8 +84,8 @@
   ... </html>
   ... ''')
 
-As you can see, we used the ``macro`` expression to simply look up a macro
-called navigation which get inserted and replaces the HTML content at this 
+As you can see, we used the ``macro`` expression to look up a macro
+called navigation which get inserted and replaces the HTML content in its 
 place.
 
 Let's now create a view using this page template:
@@ -125,7 +111,7 @@
   >>> nav = zope.component.queryMultiAdapter((content, view, request),
   ...                                         IMacroTemplate, name='navigation')
 
-And of course we can directly render the view.
+And of course we can directly render the view which includes the macro.
 
   >>> print view().strip()
   <html>

Modified: Sandbox/darrylcousins/mars.macro/src/mars/macro/tests.py
===================================================================
--- Sandbox/darrylcousins/mars.macro/src/mars/macro/tests.py	2007-07-17 11:56:01 UTC (rev 78067)
+++ Sandbox/darrylcousins/mars.macro/src/mars/macro/tests.py	2007-07-17 11:59:45 UTC (rev 78068)
@@ -1,6 +1,20 @@
 import unittest
 from zope.testing import doctest
 
+import zope.interface
+
+from martian.interfaces import IModuleInfo
+
+class ModuleInfo(object):
+    zope.interface.implements(IModuleInfo)
+    path = ''
+    package_dotted_name = ''
+
+    def getAnnotation(self, name, default):
+        return default
+
+globs = dict(module_info=ModuleInfo())
+
 optionflags = doctest.NORMALIZE_WHITESPACE + doctest.ELLIPSIS
 
 def setUp(test):
@@ -17,7 +31,7 @@
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTests([doctest.DocFileSuite('macro.txt',
-                             setUp=setUp,
+                             setUp=setUp, globs=globs,
                              optionflags=optionflags),
                    ])
 



More information about the Checkins mailing list