[Checkins] SVN: Sandbox/darrylcousins/mars.macro/ Renamed tests to ftests and added doctest

Darryl Cousins darryl at darrylcousins.net.nz
Mon Jul 16 02:46:43 EDT 2007


Log message for revision 78017:
  Renamed tests to ftests and added doctest

Changed:
  U   Sandbox/darrylcousins/mars.macro/buildout.cfg
  U   Sandbox/darrylcousins/mars.macro/setup.py
  U   Sandbox/darrylcousins/mars.macro/src/mars/macro/directive.txt
  U   Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/directive.py
  U   Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/ftesting.zcml
  U   Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/macro.py
  D   Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/test_all.py
  A   Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/test_functional.py
  A   Sandbox/darrylcousins/mars.macro/src/mars/macro/macro.txt
  A   Sandbox/darrylcousins/mars.macro/src/mars/macro/tests.py

-=-
Modified: Sandbox/darrylcousins/mars.macro/buildout.cfg
===================================================================
--- Sandbox/darrylcousins/mars.macro/buildout.cfg	2007-07-16 06:02:22 UTC (rev 78016)
+++ Sandbox/darrylcousins/mars.macro/buildout.cfg	2007-07-16 06:46:42 UTC (rev 78017)
@@ -5,6 +5,9 @@
 [test]
 recipe = zc.recipe.testrunner
 eggs = mars.macro [test]
+defaults = ['--tests-pattern', '^f?tests$',
+	'-v'
+	]
 
 [zope3]
 location = .

Modified: Sandbox/darrylcousins/mars.macro/setup.py
===================================================================
--- Sandbox/darrylcousins/mars.macro/setup.py	2007-07-16 06:02:22 UTC (rev 78016)
+++ Sandbox/darrylcousins/mars.macro/setup.py	2007-07-16 06:46:42 UTC (rev 78017)
@@ -25,9 +25,6 @@
     extras_require = dict(
                 test=['zope.app.testing',
                       'zope.testbrowser',
-                      'zope.app.zcmlfiles',
-                      'zope.app.securitypolicy',
-                      'zope.app.authentication',
                       'z3c.template',
                       'mars.template',
                       'mars.layer',
@@ -35,15 +32,7 @@
                 ),
     install_requires = [
         'setuptools',
-        'zope.app.intid',
-        'zope.app.catalog',
-        'zope.component',
-        'zope.interface',
-        'zope.publisher',
-        'zope.contentprovider',
-        'zope.viewlet',
         'grok',
-        'martian',
         'z3c.macro',
         ],
 )

Modified: Sandbox/darrylcousins/mars.macro/src/mars/macro/directive.txt
===================================================================
--- Sandbox/darrylcousins/mars.macro/src/mars/macro/directive.txt	2007-07-16 06:02:22 UTC (rev 78016)
+++ Sandbox/darrylcousins/mars.macro/src/mars/macro/directive.txt	2007-07-16 06:46:42 UTC (rev 78017)
@@ -9,6 +9,7 @@
   The name of the macro to be used. This allows us to reference 
   the named  macro defined with metal:define-macro if we use a 
   different IMacroDirective name.
+  Default: view name or factory.__name__.lower()
 
 * mars.macro.view(class_or_interface):
   The view for which the macro should be used',

Modified: Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/directive.py
===================================================================
--- Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/directive.py	2007-07-16 06:02:22 UTC (rev 78016)
+++ Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/directive.py	2007-07-16 06:46:42 UTC (rev 78017)
@@ -2,15 +2,14 @@
 Test the claimed directives.
 
   >>> import grok
-  >>> grok.grok('mars.macro.tests.directive')
+  >>> grok.grok('mars.macro.ftests.directive')
 
-  >>> from mars.macro.tests.directive import Mammoth
+  >>> from mars.macro.ftests.directive import Mammoth
   >>> mammoth = getRootFolder()["mammoth"] = Mammoth()
 
   >>> from zope.testbrowser.testing import Browser
   >>> browser = Browser()
   >>> browser.handleErrors = False
-  >>> #browser.addHeader('Authorization', 'Basic mgr:mgrpw')
 
   >>> browser.open('http://localhost/mammoth/@@first')
   >>> print browser.contents

Modified: Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/ftesting.zcml
===================================================================
--- Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/ftesting.zcml	2007-07-16 06:02:22 UTC (rev 78016)
+++ Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/ftesting.zcml	2007-07-16 06:46:42 UTC (rev 78017)
@@ -9,10 +9,9 @@
   <include package="mars.layer" file="meta.zcml" />
   <include package="mars.macro" file="meta.zcml" />
 
-  <include package="z3c.layer.minimal.tests" file="ftesting.zcml" />
+  <include package="grok" />
 
   <include package="z3c.macro" />
-  <include package="grok" />
 
 </configure>
 

Modified: Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/macro.py
===================================================================
--- Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/macro.py	2007-07-16 06:02:22 UTC (rev 78016)
+++ Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/macro.py	2007-07-16 06:46:42 UTC (rev 78017)
@@ -1,8 +1,8 @@
 """
   >>> import grok
-  >>> grok.grok('mars.macro.tests.macro')
+  >>> grok.grok('mars.macro.ftests.macro')
 
-  >>> from mars.macro.tests.macro import Mammoth
+  >>> from mars.macro.ftests.macro import Mammoth
   >>> mammoth = getRootFolder()["mammoth"] = Mammoth()
 
   >>> from zope.testbrowser.testing import Browser
@@ -40,14 +40,14 @@
 import mars.macro
 import mars.template
 
+class Mammoth(grok.Model):
+    pass
+
 class Navigation(mars.macro.MacroFactory):
-    """Name defaults to factory.__name__, 'navigation'"""
+    """Name defaults to factory.__name__, 'navigation' and context defaults to
+    module context - in this case Mammoth."""
     grok.template('templates/navigation.pt') # required
-    grok.context(zope.interface.Interface) # required if no module context 
 
-class Mammoth(grok.Model):
-    pass
-
 class First(grok.View):
 
     def __call__(self):

Deleted: Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/test_all.py
===================================================================
--- Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/test_all.py	2007-07-16 06:02:22 UTC (rev 78016)
+++ Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/test_all.py	2007-07-16 06:46:42 UTC (rev 78017)
@@ -1,22 +0,0 @@
-import unittest
-from pkg_resources import resource_listdir
-
-from grok.ftests.test_grok_functional import FunctionalDocTestSuite
-
-from zope.app.testing import functional
-functional.defineLayer('TestLayer', 'ftesting.zcml')
-
-def test_suite():
-    suite = unittest.TestSuite()
-    dottedname = 'mars.macro.tests.%s'
-    for name in ['directive', 'macro']:
-        test = FunctionalDocTestSuite(dottedname % name)
-        test.layer = TestLayer
-        suite.addTest(test)
-
-    return suite
-
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')
-

Added: Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/test_functional.py
===================================================================
--- Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/test_functional.py	                        (rev 0)
+++ Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/test_functional.py	2007-07-16 06:46:42 UTC (rev 78017)
@@ -0,0 +1,31 @@
+import unittest
+from zope.testing import doctest
+
+from zope.app.testing.functional import FunctionalTestSetup, getRootFolder
+from zope.app.testing import functional
+functional.defineLayer('TestLayer', 'ftesting.zcml')
+
+optionflags = doctest.NORMALIZE_WHITESPACE + doctest.ELLIPSIS
+globs = dict(getRootFolder=getRootFolder)
+
+def setUp(test):
+    FunctionalTestSetup().setUp()
+
+def tearDown(test):
+    FunctionalTestSetup().tearDown()
+
+def test_suite():
+    suite = unittest.TestSuite()
+    dottedname = 'mars.macro.ftests.%s'
+    for name in ['macro', 'directive']:
+        test = doctest.DocTestSuite(
+                    dottedname % name, setUp=setUp, globs=globs,
+                    tearDown=tearDown, optionflags=optionflags)
+        test.layer = TestLayer
+        suite.addTest(test)
+    return suite
+
+
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: Sandbox/darrylcousins/mars.macro/src/mars/macro/ftests/test_functional.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: Sandbox/darrylcousins/mars.macro/src/mars/macro/macro.txt
===================================================================
--- Sandbox/darrylcousins/mars.macro/src/mars/macro/macro.txt	                        (rev 0)
+++ Sandbox/darrylcousins/mars.macro/src/mars/macro/macro.txt	2007-07-16 06:46:42 UTC (rev 78017)
@@ -0,0 +1,143 @@
+==========
+Mars Macro
+==========
+
+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 idea being that a template is registered as an adapter providing IMacroTemplate 
+
+Set up
+------
+
+We start with creating a content object that is used as a view context later:
+
+  >>> import zope.interface
+  >>> import zope.component
+  >>> from zope.publisher.interfaces.browser import IBrowserView
+  >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+  >>> 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
+--------------
+
+A macro template is registered as a adapter providing IMacroTemplate, this
+happens when the macro factory is grokked.
+
+  >>> path = os.path.join(temp_dir, 'navigation.pt')
+  >>> open(path, 'w').write('''
+  ... <metal:block define-macro="navigation">
+  ...   <div tal:content="title">---</div>
+  ... </metal:block>
+  ... ''')
+
+Now we can use MacroFactory to define and register the macro template.
+
+  >>> import grok
+  >>> import mars.macro
+  >>> class Navigation(mars.macro.MacroFactory):
+  ...     grok.template(path)
+
+Only the template directive is required, the name of the macro which will be
+sought from the template defaults to that set by the directive grok.name which
+in turn defaults to factory.__name__.lower(). The name by which the macro is
+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)
+  True
+
+The TALES ``macro`` Expression
+------------------------------
+
+The ``macro`` expression will look up the name of the macro, call an adapter
+providing IMacroTemplate and uses them or fills a slot if defined in the 
+``macro`` expression.
+
+Let's create a page template using the ``navigation`` macros:
+
+  >>> path = os.path.join(temp_dir, 'first.pt')
+  >>> open(path, 'w').write('''
+  ... <html>
+  ...   <body>
+  ...     <tal:block define="title string:My Navigation">
+  ...       <metal:block use-macro="macro:navigation" />
+  ...     </tal:block>
+  ...   </body>
+  ... </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 
+place.
+
+Let's now create a view using this page template:
+
+  >>> from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
+  >>> FirstPage = SimpleViewClass(path, name='first.html')
+
+  >>> zope.component.provideAdapter(
+  ...     FirstPage,
+  ...     (zope.interface.Interface, IDefaultBrowserLayer),
+  ...     zope.interface.Interface,
+  ...     name='first.html')
+
+Using view and request we can directly retrieve the macro for the registry.
+
+  >>> from zope.publisher.browser import TestRequest
+  >>> request = TestRequest()
+
+  >>> view = zope.component.getMultiAdapter((content, request),
+  ...                                       name='first.html')
+
+  >>> from z3c.macro.interfaces import IMacroTemplate
+  >>> nav = zope.component.queryMultiAdapter((content, view, request),
+  ...                                         IMacroTemplate, name='navigation')
+
+And of course we can directly render the view.
+
+  >>> print view().strip()
+  <html>
+    <body>
+      <div>My Navigation</div>
+    </body>
+  </html>
+
+
+Cleanup
+-------
+
+  >>> import shutil
+  >>> shutil.rmtree(temp_dir)
+


Property changes on: Sandbox/darrylcousins/mars.macro/src/mars/macro/macro.txt
___________________________________________________________________
Name: svn:keywords
   + Date Author

Added: Sandbox/darrylcousins/mars.macro/src/mars/macro/tests.py
===================================================================
--- Sandbox/darrylcousins/mars.macro/src/mars/macro/tests.py	                        (rev 0)
+++ Sandbox/darrylcousins/mars.macro/src/mars/macro/tests.py	2007-07-16 06:46:42 UTC (rev 78017)
@@ -0,0 +1,30 @@
+import unittest
+from zope.testing import doctest
+
+optionflags = doctest.NORMALIZE_WHITESPACE + doctest.ELLIPSIS
+
+def setUp(test):
+    # register macro TALES
+    from zope.app.pagetemplate import metaconfigure
+    from z3c.macro import tales
+    metaconfigure.registerType('macro', tales.MacroExpression)
+
+    # register provider TALES
+    from zope.app.pagetemplate import metaconfigure
+    from zope.contentprovider import tales
+    metaconfigure.registerType('provider', tales.TALESProviderExpression)
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTests([doctest.DocFileSuite('macro.txt',
+                             setUp=setUp,
+                             optionflags=optionflags),
+                   ])
+
+    return suite
+
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+
+


Property changes on: Sandbox/darrylcousins/mars.macro/src/mars/macro/tests.py
___________________________________________________________________
Name: svn:keywords
   + Id



More information about the Checkins mailing list