[Checkins] SVN: hurry.custom/trunk/src/hurry/custom/ actually test the directives.
Martijn Faassen
faassen at startifact.com
Fri May 22 15:12:33 EDT 2009
Log message for revision 100251:
actually test the directives.
Changed:
U hurry.custom/trunk/src/hurry/custom/tests.py
U hurry.custom/trunk/src/hurry/custom/zcml.py
A hurry.custom/trunk/src/hurry/custom/zcml.txt
-=-
Modified: hurry.custom/trunk/src/hurry/custom/tests.py
===================================================================
--- hurry.custom/trunk/src/hurry/custom/tests.py 2009-05-22 18:51:14 UTC (rev 100250)
+++ hurry.custom/trunk/src/hurry/custom/tests.py 2009-05-22 19:12:33 UTC (rev 100251)
@@ -1,18 +1,25 @@
import unittest
import doctest
+from hurry import custom
+
from zope.testing import cleanup
import zope.component.eventtesting
+from zope.configuration.xmlconfig import XMLConfig
from hurry.custom.testing import setHooks, setSite, getSite, DummySite
-def setUpReadMe(test):
+def setUpCustom(test):
# set up special local component architecture
setHooks()
+
# set up event handling
zope.component.eventtesting.setUp(test)
-def tearDownReadMe(test):
+ # set up the directives
+ XMLConfig('meta.zcml', custom)()
+
+def tearDownCustom(test):
# clean up Zope
cleanup.cleanUp()
setSite(None)
@@ -28,9 +35,10 @@
suite = unittest.TestSuite()
suite.addTest(doctest.DocFileSuite(
- 'README.txt', 'jsontemplate.txt',
+ 'README.txt', 'jsontemplate.txt', 'zcml.txt',
optionflags=optionflags,
- setUp=setUpReadMe,
- tearDown=tearDownReadMe,
+ setUp=setUpCustom,
+ tearDown=tearDownCustom,
globs=globs))
+
return suite
Modified: hurry.custom/trunk/src/hurry/custom/zcml.py
===================================================================
--- hurry.custom/trunk/src/hurry/custom/zcml.py 2009-05-22 18:51:14 UTC (rev 100250)
+++ hurry.custom/trunk/src/hurry/custom/zcml.py 2009-05-22 19:12:33 UTC (rev 100251)
@@ -4,7 +4,7 @@
from hurry import custom
-class TemplateLanguage(Interface):
+class ITemplateLanguage(Interface):
template_class = GlobalObject(
title=u'Template Class',
description=u'The class that implements the template language')
@@ -20,7 +20,7 @@
description=u'The filesystem extension used for sample input data.',
required=False)
-class DataLanguage(Interface):
+class IDataLanguage(Interface):
parse_func = GlobalObject(
title=u'Parse function',
description=u'A function that can parse text and deliver input data.')
@@ -31,7 +31,7 @@
u'for example .json) '
u'recognzied for this input language')
-class Collection(Interface):
+class ICollection(Interface):
id = TextLine(
title=u'Collection ID',
description=u"Globally unique collection id")
Added: hurry.custom/trunk/src/hurry/custom/zcml.txt
===================================================================
--- hurry.custom/trunk/src/hurry/custom/zcml.txt (rev 0)
+++ hurry.custom/trunk/src/hurry/custom/zcml.txt 2009-05-22 19:12:33 UTC (rev 100251)
@@ -0,0 +1,50 @@
+ZCML directives
+===============
+
+``hurry.custom`` defines a number of ZCML directives to configure
+itself. We'll go through them here.
+
+This helper will let us easily execute ZCML snippets::
+
+ >>> from cStringIO import StringIO
+ >>> from zope.configuration.xmlconfig import xmlconfig
+ >>> def runSnippet(snippet):
+ ... template = """\
+ ... <configure xmlns='http://namespaces.zope.org/zope'
+ ... xmlns:custom='http://namespaces.zope.org/custom'
+ ... i18n_domain="zope">
+ ... %s
+ ... </configure>"""
+ ... xmlconfig(StringIO(template % snippet))
+
+We'll set up a .jsont template in a temporary directory::
+
+ >>> import tempfile, os
+ >>> templates_path = tempfile.mkdtemp(prefix='hurry.custom')
+ >>> test1_path = os.path.join(templates_path, 'test1.jsont')
+ >>> f = open(test1_path, 'w')
+ >>> f.write('Hello {thing}')
+ >>> f.close()
+
+Now we can register the ``.jsont`` template language and register the
+collection::
+
+ >>> runSnippet('''
+ ... <custom:templateLanguage
+ ... template_class="hurry.custom.JsonTemplate"
+ ... extension=".jsont"
+ ... sample_extension=".json" />
+ ...
+ ... <custom:collection
+ ... id="templates"
+ ... path="%s"
+ ... title="Templates" />
+ ... ''' % templates_path)
+
+We can now look up the template in this collection::
+
+ >>> from hurry import custom
+ >>> template = custom.lookup('templates', 'test1.jsont')
+ >>> print template({'thing': "world"})
+ Hello world
+
More information about the Checkins
mailing list