[Checkins] SVN: Sandbox/darrylcousins/mars.template/ Working on
tests
Darryl Cousins
darryl at darrylcousins.net.nz
Mon Jul 16 05:23:48 EDT 2007
Log message for revision 78023:
Working on tests
Changed:
U Sandbox/darrylcousins/mars.template/buildout.cfg
U Sandbox/darrylcousins/mars.template/setup.py
U Sandbox/darrylcousins/mars.template/src/mars/template/ftests/directive.py
U Sandbox/darrylcousins/mars.template/src/mars/template/ftests/ftesting.zcml
U Sandbox/darrylcousins/mars.template/src/mars/template/ftests/layout.py
U Sandbox/darrylcousins/mars.template/src/mars/template/ftests/minimal-ftesting.zcml
U Sandbox/darrylcousins/mars.template/src/mars/template/ftests/template.py
D Sandbox/darrylcousins/mars.template/src/mars/template/ftests/test_all.py
A Sandbox/darrylcousins/mars.template/src/mars/template/ftests/test_functional.py
A Sandbox/darrylcousins/mars.template/src/mars/template/template.txt
A Sandbox/darrylcousins/mars.template/src/mars/template/tests.py
-=-
Modified: Sandbox/darrylcousins/mars.template/buildout.cfg
===================================================================
--- Sandbox/darrylcousins/mars.template/buildout.cfg 2007-07-16 07:59:18 UTC (rev 78022)
+++ Sandbox/darrylcousins/mars.template/buildout.cfg 2007-07-16 09:23:47 UTC (rev 78023)
@@ -5,6 +5,9 @@
[test]
recipe = zc.recipe.testrunner
eggs = mars.template [test]
+defaults = ['--tests-pattern', '^f?tests$',
+ '-v'
+ ]
[zope3]
location = .
Modified: Sandbox/darrylcousins/mars.template/setup.py
===================================================================
--- Sandbox/darrylcousins/mars.template/setup.py 2007-07-16 07:59:18 UTC (rev 78022)
+++ Sandbox/darrylcousins/mars.template/setup.py 2007-07-16 09:23:47 UTC (rev 78023)
@@ -25,9 +25,6 @@
extras_require = dict(
test=['zope.app.testing',
'zope.testbrowser',
- 'zope.app.zcmlfiles',
- 'zope.app.securitypolicy',
- 'zope.app.authentication',
'z3c.pagelet',
'mars.view',
'mars.layer',
@@ -35,14 +32,7 @@
),
install_requires = [
'setuptools',
- 'zope.app.intid',
- 'zope.app.catalog',
- 'zope.component',
- 'zope.interface',
- 'zope.publisher',
- 'zope.pagetemplate',
'grok',
- 'martian',
'z3c.form',
'z3c.layer',
'z3c.template',
Modified: Sandbox/darrylcousins/mars.template/src/mars/template/ftests/directive.py
===================================================================
--- Sandbox/darrylcousins/mars.template/src/mars/template/ftests/directive.py 2007-07-16 07:59:18 UTC (rev 78022)
+++ Sandbox/darrylcousins/mars.template/src/mars/template/ftests/directive.py 2007-07-16 09:23:47 UTC (rev 78023)
@@ -2,8 +2,8 @@
Run through and test the available directives to template factories.
>>> import grok
- >>> from mars.template.tests.directive import Mammoth
- >>> grok.grok('mars.template.tests.directive')
+ >>> from mars.template.ftests.directive import Mammoth
+ >>> grok.grok('mars.template.ftests.directive')
>>> mammoth = getRootFolder()["mammoth"] = Mammoth()
Modified: Sandbox/darrylcousins/mars.template/src/mars/template/ftests/ftesting.zcml
===================================================================
--- Sandbox/darrylcousins/mars.template/src/mars/template/ftests/ftesting.zcml 2007-07-16 07:59:18 UTC (rev 78022)
+++ Sandbox/darrylcousins/mars.template/src/mars/template/ftests/ftesting.zcml 2007-07-16 09:23:47 UTC (rev 78023)
@@ -2,7 +2,7 @@
xmlns:meta="http://namespaces.zope.org/meta"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="zope"
- package="mars.template.tests">
+ package="mars.template.ftests">
<include package="grok" file="meta.zcml" />
<include package="mars.template" file="meta.zcml" />
Modified: Sandbox/darrylcousins/mars.template/src/mars/template/ftests/layout.py
===================================================================
--- Sandbox/darrylcousins/mars.template/src/mars/template/ftests/layout.py 2007-07-16 07:59:18 UTC (rev 78022)
+++ Sandbox/darrylcousins/mars.template/src/mars/template/ftests/layout.py 2007-07-16 09:23:47 UTC (rev 78023)
@@ -2,8 +2,8 @@
LayoutFactories allow use to define page templates in python code.
>>> import grok
- >>> from mars.template.tests.layout import Mammoth
- >>> grok.grok('mars.template.tests.layout')
+ >>> from mars.template.ftests.layout import Mammoth
+ >>> grok.grok('mars.template.ftests.layout')
>>> mammoth = getRootFolder()["mammoth"] = Mammoth()
@@ -28,7 +28,7 @@
>>> import zope.component
>>> from z3c.template.interfaces import ILayoutTemplate
- >>> from mars.template.tests.layout import PlainText
+ >>> from mars.template.ftests.layout import PlainText
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
>>> plaintext = PlainText(mammoth, request)
Modified: Sandbox/darrylcousins/mars.template/src/mars/template/ftests/minimal-ftesting.zcml
===================================================================
--- Sandbox/darrylcousins/mars.template/src/mars/template/ftests/minimal-ftesting.zcml 2007-07-16 07:59:18 UTC (rev 78022)
+++ Sandbox/darrylcousins/mars.template/src/mars/template/ftests/minimal-ftesting.zcml 2007-07-16 09:23:47 UTC (rev 78023)
@@ -2,15 +2,13 @@
xmlns:meta="http://namespaces.zope.org/meta"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="zope"
- package="mars.template.tests">
+ package="mars.template.ftests">
<include package="grok" file="meta.zcml" />
<include package="mars.template" file="meta.zcml" />
<include package="mars.layer" file="meta.zcml" />
<include package="mars.view" file="meta.zcml" />
- <include package="z3c.layer.minimal.tests" file="ftesting.zcml" />
-
<include package="grok" />
</configure>
Modified: Sandbox/darrylcousins/mars.template/src/mars/template/ftests/template.py
===================================================================
--- Sandbox/darrylcousins/mars.template/src/mars/template/ftests/template.py 2007-07-16 07:59:18 UTC (rev 78022)
+++ Sandbox/darrylcousins/mars.template/src/mars/template/ftests/template.py 2007-07-16 09:23:47 UTC (rev 78023)
@@ -2,15 +2,15 @@
TemplateFactories allow use to define page templates in python code.
>>> import grok
- >>> from mars.template.tests.template import Mammoth
- >>> grok.grok('mars.template.tests.template')
+ >>> from mars.template.ftests.template import Mammoth
+ >>> grok.grok('mars.template.ftests.template')
>>> mammoth = Mammoth()
>>> import zope.component
>>> from zope.pagetemplate.interfaces import IPageTemplate
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
- >>> from mars.template.tests.template import View
+ >>> from mars.template.ftests.template import View
>>> view = View(mammoth, request)
The template can then be looked up for the object that it is registered for
@@ -26,14 +26,14 @@
TemplateFactories support a `macro` directive (see z3c.template).
- >>> from mars.template.tests.template import Macro
+ >>> from mars.template.ftests.template import Macro
>>> macro = Macro(mammoth, request)
>>> print macro.render()
<div>This is within the mymacro macro</div>
TemplateFactories also allow the setting of the contentType.
- >>> from mars.template.tests.template import PlainText
+ >>> from mars.template.ftests.template import PlainText
>>> plaintext = PlainText(mammoth, request)
>>> template = zope.component.getMultiAdapter(
... (plaintext, request), IPageTemplate)
Deleted: Sandbox/darrylcousins/mars.template/src/mars/template/ftests/test_all.py
===================================================================
--- Sandbox/darrylcousins/mars.template/src/mars/template/ftests/test_all.py 2007-07-16 07:59:18 UTC (rev 78022)
+++ Sandbox/darrylcousins/mars.template/src/mars/template/ftests/test_all.py 2007-07-16 09:23:47 UTC (rev 78023)
@@ -1,32 +0,0 @@
-import unittest
-from pkg_resources import resource_listdir
-
-from grok.ftests.test_grok_functional import FunctionalDocTestSuite
-
-from zope.app.testing import functional
-
-from martian.tests.test_all import globs, optionflags
-
-functional.defineLayer('TestLayer', 'ftesting.zcml')
-functional.defineLayer('TestMinimalLayer', 'minimal-ftesting.zcml')
-
-def test_suite():
- suite = unittest.TestSuite()
- dottedname = 'mars.template.tests.%s'
-
- for name in ['template', 'layout']:
- test = FunctionalDocTestSuite(dottedname % name)
- test.layer = TestLayer
- suite.addTest(test)
-
- test = FunctionalDocTestSuite(dottedname % 'directive')
- test.layer = TestMinimalLayer
- suite.addTest(test)
-
- return suite
-
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
-
-
Added: Sandbox/darrylcousins/mars.template/src/mars/template/ftests/test_functional.py
===================================================================
--- Sandbox/darrylcousins/mars.template/src/mars/template/ftests/test_functional.py (rev 0)
+++ Sandbox/darrylcousins/mars.template/src/mars/template/ftests/test_functional.py 2007-07-16 09:23:47 UTC (rev 78023)
@@ -0,0 +1,39 @@
+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')
+functional.defineLayer('TestMinimalLayer', 'minimal-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.template.ftests.%s'
+ for name in ['template', 'layout']:
+ test = doctest.DocTestSuite(
+ dottedname % name, setUp=setUp, globs=globs,
+ tearDown=tearDown, optionflags=optionflags)
+ test.layer = TestLayer
+ suite.addTest(test)
+ test = doctest.DocTestSuite(
+ dottedname % 'directive', setUp=setUp, globs=globs,
+ tearDown=tearDown, optionflags=optionflags)
+ test.layer = TestMinimalLayer
+ suite.addTest(test)
+ return suite
+
+
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
+
Property changes on: Sandbox/darrylcousins/mars.template/src/mars/template/ftests/test_functional.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: Sandbox/darrylcousins/mars.template/src/mars/template/template.txt
===================================================================
--- Sandbox/darrylcousins/mars.template/src/mars/template/template.txt (rev 0)
+++ Sandbox/darrylcousins/mars.template/src/mars/template/template.txt 2007-07-16 09:23:47 UTC (rev 78023)
@@ -0,0 +1,154 @@
+=============
+Mars Template
+=============
+
+The mars.template package provides the means of creating and configuring
+``templates`` for an application using Zope3.
+
+These templates use presentation patterns used by other z3c packages.
+
+z3c packages bring significant clarity and a pattern for forms, view and
+templates. As an introduction to this package I suggest reading z3c.template
+README which introduces the patterns used here also.
+
+Set up
+------
+
+First some imports.
+
+ >>> import zope.component
+ >>> import zope.interface
+ >>> from zope.pagetemplate.interfaces import IPageTemplate
+ >>> import mars.template
+ >>> import grok
+ >>> import os, tempfile
+ >>> temp_dir = tempfile.mkdtemp()
+
+Let's create a content object that will act as the context to the views.
+
+ >>> class Content(object):
+ ... zope.interface.implements(zope.interface.Interface)
+ >>> content = Content()
+
+Template view
+-------------
+
+For our view we will use a grok.View with custom render method which looks up
+a template from the registry.
+
+ >>> class ITemplateView(zope.interface.Interface):
+ ... pass
+
+ >>> class TemplateView(grok.View):
+ ... grok.name('view.html')
+ ... zope.interface.implements(ITemplateView)
+ ... def render(self):
+ ... template = zope.component.getMultiAdapter(
+ ... (self, self.request), IPageTemplate)
+ ... return template(self)
+
+We need to ``grok`` this view, usually this is done automagically on start up
+but here we do it manually, for which we need a fake module info object.
+
+ >>> from martian.interfaces import IModuleInfo
+ >>> class ModuleInfo(object):
+ ... zope.interface.implements(IModuleInfo)
+ ... path = ''
+ ... package_dotted_name = ''
+ ... def getAnnotation(self, name, default):
+ ... return default
+
+In the test we manually ``grok`` the factory, normally this happens when a
+module is ``grokked`` on start up.
+
+ >>> from grok.meta import ViewGrokker
+ >>> ViewGrokker().grok('', TemplateView, zope.interface.Interface,
+ ... ModuleInfo(), {})
+ True
+
+First template
+--------------
+
+This package offers primarily two template factories to mirror the z3c.template
+registrations, one registered as zope.pagetemplate.interfaces.IPageTemplate and
+the second as z3c.template.interfaces.ILayoutTemplate
+
+Our TemplateView expects a IPageTemplate, lets give it one to use.
+
+ >>> path = os.path.join(temp_dir, 'myTemplate.pt')
+ >>> open(path, 'w').write('''<div>My content</div>''')
+
+ >>> class Template(mars.template.TemplateFactory):
+ ... grok.template(path)
+ ... grok.context(ITemplateView)
+
+Here we assign the template to ITemplateView, the interface that the view
+implements, but we could have assigned it directly to the view class.
+
+Again we must manually ``grok`` the class.
+
+ >>> from mars.template.meta import TemplateFactoryGrokker
+ >>> TemplateFactoryGrokker().grok('', Template, None, ModuleInfo(), None)
+ True
+
+View the view
+-------------
+
+We can now look up the view and expect the template to be rendered.
+
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+
+ >>> view = zope.component.getMultiAdapter((content, request),
+ ... name='view.html')
+ >>> print view.render()
+ <div>My content</div>
+
+Layout template
+---------------
+
+First we need to register a new view class calling a layout template. Note,
+that this view uses the __call__ method for invoke a layout template:
+
+In this case we'll use a vanilla Zope3 page.
+
+ >>> from zope.publisher.browser import BrowserPage
+ >>> from z3c.template.interfaces import ILayoutTemplate
+ >>> class ILayoutView(zope.interface.Interface):
+ ... pass
+ >>> class LayoutView(BrowserPage):
+ ... zope.interface.implements(ILayoutView)
+ ... layout = None
+ ... def __call__(self):
+ ... if self.layout is None:
+ ... layout = zope.component.getMultiAdapter(
+ ... (self, self.request), ILayoutTemplate)
+ ... return layout(self)
+ ... return self.layout()
+
+Define and register a new layout template:
+
+ >>> layoutpath = os.path.join(temp_dir, 'layoutTemplate.pt')
+ >>> open(layoutpath, 'w').write('''<div>demo layout</div>''')
+
+We register the template factory on a view interface and a layer providing the
+ILayoutTemplate interface.
+
+ >>> class LayoutTemplate(mars.template.LayoutFactory):
+ ... grok.template(layoutpath)
+ ... grok.context(ILayoutView)
+
+ >>> from mars.template.meta import LayoutFactoryGrokker
+ >>> LayoutFactoryGrokker().grok('', LayoutTemplate, None, ModuleInfo(), None)
+ True
+
+ >>> view = LayoutView(content, request)
+ >>> print view()
+ <div>demo layout</div>
+
+Cleanup
+-------
+
+ >>> import shutil
+ >>> shutil.rmtree(temp_dir)
+
Property changes on: Sandbox/darrylcousins/mars.template/src/mars/template/template.txt
___________________________________________________________________
Name: svn:keywords
+ Date Author
Added: Sandbox/darrylcousins/mars.template/src/mars/template/tests.py
===================================================================
--- Sandbox/darrylcousins/mars.template/src/mars/template/tests.py (rev 0)
+++ Sandbox/darrylcousins/mars.template/src/mars/template/tests.py 2007-07-16 09:23:47 UTC (rev 78023)
@@ -0,0 +1,20 @@
+import unittest
+from zope.testing import doctest
+
+optionflags = doctest.NORMALIZE_WHITESPACE + doctest.ELLIPSIS
+
+def setUp(test):
+ pass
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTests([doctest.DocFileSuite('./template.txt',
+ setUp=setUp,
+ optionflags=optionflags),
+ ])
+
+ return suite
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
Property changes on: Sandbox/darrylcousins/mars.template/src/mars/template/tests.py
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the Checkins
mailing list