[Checkins] SVN: megrok.genshi/trunk/src/megrok/genshi/ The test
runs now.
Lennart Regebro
regebro at gmail.com
Thu Oct 4 08:48:05 EDT 2007
Log message for revision 80604:
The test runs now.
Changed:
A megrok.genshi/trunk/src/megrok/genshi/components.py
U megrok.genshi/trunk/src/megrok/genshi/configure.zcml
A megrok.genshi/trunk/src/megrok/genshi/ftesting.zcml
A megrok.genshi/trunk/src/megrok/genshi/templatereg.py
A megrok.genshi/trunk/src/megrok/genshi/tests/
A megrok.genshi/trunk/src/megrok/genshi/tests/__init__.py
A megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate.py
A megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate_templates/
A megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate_templates/cavepainting.gmt
A megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate_templates/food.gmt
-=-
Added: megrok.genshi/trunk/src/megrok/genshi/components.py
===================================================================
--- megrok.genshi/trunk/src/megrok/genshi/components.py (rev 0)
+++ megrok.genshi/trunk/src/megrok/genshi/components.py 2007-10-04 12:48:05 UTC (rev 80604)
@@ -0,0 +1,50 @@
+##############################################################################
+#
+# Copyright (c) 2006-2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Genshi components"""
+import zope.interface
+import grok.components
+import grok.interfaces
+import genshi.template
+
+class GenshiMarkupTemplate(grok.components.GrokPageTemplate):
+
+ zope.interface.implements(grok.interfaces.ITemplateFile)
+
+ def __init__(self, filename=None, _prefix=None, html=None):
+ if ((html is not None and filename is not None) or
+ (html is None and filename is None)):
+ raise AssertionError("You must pass either html or filename but not both.")
+
+ if html is not None:
+ self._template = genshi.template.MarkupTemplate(html)
+ else:
+ loader = genshi.template.TemplateLoader(_prefix)
+ self._template = loader.load(filename)
+
+
+ def __call__(self, namespace):
+ stream = self._template.generate(**namespace)
+ return stream.render('xhtml')
+
+ def _factory_init(self, factory):
+ pass
+
+ def _render_template(self, view):
+ namespace = {}
+ namespace['request'] = view.request
+ namespace['view'] = view
+ namespace['context'] = view.context
+ # XXX need to check whether we really want to put None here if missing
+ namespace['static'] = view.static
+ return self(namespace)
Property changes on: megrok.genshi/trunk/src/megrok/genshi/components.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: megrok.genshi/trunk/src/megrok/genshi/configure.zcml
===================================================================
--- megrok.genshi/trunk/src/megrok/genshi/configure.zcml 2007-10-04 12:05:47 UTC (rev 80603)
+++ megrok.genshi/trunk/src/megrok/genshi/configure.zcml 2007-10-04 12:48:05 UTC (rev 80604)
@@ -3,5 +3,6 @@
xmlns:grok="http://namespaces.zope.org/grok">
<include package="grok" />
+ <grok:grok package="." />
</configure>
Added: megrok.genshi/trunk/src/megrok/genshi/ftesting.zcml
===================================================================
--- megrok.genshi/trunk/src/megrok/genshi/ftesting.zcml (rev 0)
+++ megrok.genshi/trunk/src/megrok/genshi/ftesting.zcml 2007-10-04 12:48:05 UTC (rev 80604)
@@ -0,0 +1,36 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:grok="http://namespaces.zope.org/grok"
+ i18n_domain="megrok.genshi"
+ package="megrok.genshi"
+ >
+
+ <include package="grok" />
+ <grok:grok package="." />
+
+ <!-- Typical functional testing security setup -->
+ <securityPolicy
+ component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy"
+ />
+
+ <unauthenticatedPrincipal
+ id="zope.anybody"
+ title="Unauthenticated User"
+ />
+ <grant
+ permission="zope.View"
+ principal="zope.anybody"
+ />
+
+ <principal
+ id="zope.mgr"
+ title="Manager"
+ login="mgr"
+ password="mgrpw"
+ />
+
+ <role id="zope.Manager" title="Site Manager" />
+ <grantAll role="zope.Manager" />
+ <grant role="zope.Manager" principal="zope.mgr" />
+
+</configure>
Property changes on: megrok.genshi/trunk/src/megrok/genshi/ftesting.zcml
___________________________________________________________________
Name: svn:keywords
+ Id
Added: megrok.genshi/trunk/src/megrok/genshi/templatereg.py
===================================================================
--- megrok.genshi/trunk/src/megrok/genshi/templatereg.py (rev 0)
+++ megrok.genshi/trunk/src/megrok/genshi/templatereg.py 2007-10-04 12:48:05 UTC (rev 80604)
@@ -0,0 +1,26 @@
+##############################################################################
+#
+# Copyright (c) 2006-2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Genshi template registration"""
+
+import grok
+import components
+
+class GenshiMarkupTemplateFileFactory(grok.GlobalUtility):
+
+ grok.implements(grok.interfaces.ITemplateFactory)
+ grok.name('gmt')
+
+ def __call__(self, filename, _prefix=None):
+ return components.GenshiMarkupTemplate(filename, _prefix)
+
\ No newline at end of file
Property changes on: megrok.genshi/trunk/src/megrok/genshi/templatereg.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: megrok.genshi/trunk/src/megrok/genshi/tests/__init__.py
===================================================================
--- megrok.genshi/trunk/src/megrok/genshi/tests/__init__.py (rev 0)
+++ megrok.genshi/trunk/src/megrok/genshi/tests/__init__.py 2007-10-04 12:48:05 UTC (rev 80604)
@@ -0,0 +1,7 @@
+import os.path
+import megrok.genshi
+from zope.app.testing.functional import ZCMLLayer
+
+ftesting_zcml = os.path.join(
+ os.path.dirname(megrok.genshi.__file__), 'ftesting.zcml')
+FunctionalLayer = ZCMLLayer(ftesting_zcml, __name__, 'FunctionalLayer')
Property changes on: megrok.genshi/trunk/src/megrok/genshi/tests/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate.py
===================================================================
--- megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate.py (rev 0)
+++ megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate.py 2007-10-04 12:48:05 UTC (rev 80604)
@@ -0,0 +1,67 @@
+import grok
+import re
+import unittest
+from pkg_resources import resource_listdir
+from zope.testing import doctest, cleanup, renormalizing
+import zope.component.eventtesting
+
+
+class Mammoth(grok.Model):
+ pass
+
+class CavePainting(grok.View):
+ pass
+
+class Food(grok.View):
+
+ def me_do(self):
+ return "ME GROK EAT MAMMOTH!"
+
+
+class GenshiTemplateTests(unittest.TestCase):
+
+ def test_templatedir(self):
+ # Templates can be found in a directory with the same name as the module:
+
+ manfred = Mammoth()
+ from zope.publisher.browser import TestRequest
+ request = TestRequest()
+ from zope import component
+ view = component.getMultiAdapter((manfred, request), name='cavepainting')
+ self.assertEquals(view(), """<html>
+<body>
+A cave painting.
+</body>
+</html>""")
+
+ view = component.getMultiAdapter((manfred, request), name='food')
+ self.assertEquals(view(), """<html>
+<body>
+ME GROK EAT MAMMOTH!
+</body>
+</html>""")
+
+
+#def setUpZope(test):
+ #zope.component.eventtesting.setUp(test)
+
+#def cleanUpZope(test):
+ #cleanup.cleanUp()
+
+#checker = renormalizing.RENormalizing([
+ ## str(Exception) has changed from Python 2.4 to 2.5 (due to
+ ## Exception now being a new-style class). This changes the way
+ ## exceptions appear in traceback printouts.
+ #(re.compile(r"ConfigurationExecutionError: <class '([\w.]+)'>:"),
+ #r'ConfigurationExecutionError: \1:'),
+ #])
+
+def test_suite():
+ from megrok.genshi.tests import FunctionalLayer
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(GenshiTemplateTests))
+ suite.layer = FunctionalLayer
+ return suite
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate_templates/cavepainting.gmt
===================================================================
--- megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate_templates/cavepainting.gmt (rev 0)
+++ megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate_templates/cavepainting.gmt 2007-10-04 12:48:05 UTC (rev 80604)
@@ -0,0 +1,5 @@
+<html>
+<body>
+A cave painting.
+</body>
+</html>
Added: megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate_templates/food.gmt
===================================================================
--- megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate_templates/food.gmt (rev 0)
+++ megrok.genshi/trunk/src/megrok/genshi/tests/test_genshitemplate_templates/food.gmt 2007-10-04 12:48:05 UTC (rev 80604)
@@ -0,0 +1,5 @@
+<html>
+<body>
+${view.me_do()}
+</body>
+</html>
More information about the Checkins
mailing list