[Checkins] SVN: z3c.pt/trunk/ Reduce and restore template instances before returning render-method to doctest; this verifies correct operation of templates that are restored from disk.

Malthe Borch mborch at gmail.com
Tue Sep 9 09:38:50 EDT 2008


Log message for revision 90998:
  Reduce and restore template instances before returning render-method to doctest; this verifies correct operation of templates that are restored from disk.

Changed:
  U   z3c.pt/trunk/CHANGES.txt
  U   z3c.pt/trunk/src/z3c/pt/testing.py

-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt	2008-09-09 13:36:54 UTC (rev 90997)
+++ z3c.pt/trunk/CHANGES.txt	2008-09-09 13:38:49 UTC (rev 90998)
@@ -17,6 +17,9 @@
 
   Features
 
+- Added reduce and restore operation to the compilation and rendering
+  flow in the test examples to verify integrity. [malthe]
+
 - The ZPT parser now supports prefixed native attributes,
   e.g. <tal:foo tal:bar="" />. [malthe]
   

Modified: z3c.pt/trunk/src/z3c/pt/testing.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/testing.py	2008-09-09 13:36:54 UTC (rev 90997)
+++ z3c.pt/trunk/src/z3c/pt/testing.py	2008-09-09 13:38:49 UTC (rev 90998)
@@ -11,7 +11,14 @@
 import genshi
 
 from StringIO import StringIO
+from cPickle import dumps, loads
 
+class TestCompiler(translation.Compiler):
+    def __call__(self, *args, **kwargs):
+        template = translation.Compiler.__call__(self, *args, **kwargs)
+        template = loads(dumps(template))
+        return template
+
 def pyexp(string):
     return expressions.python_translation.expression(string)
 
@@ -26,7 +33,7 @@
     return out, write, stream
 
 def compile_xhtml(body, **kwargs):
-    compiler = translation.Compiler(
+    compiler = TestCompiler(
         body, mock_parser, implicit_doctype=doctypes.xhtml)
     return compiler(params=sorted(kwargs.keys()))
 
@@ -35,19 +42,19 @@
     return template.render(**kwargs)    
     
 def render_text(body, **kwargs):
-    compiler = translation.Compiler.from_text(
+    compiler = TestCompiler.from_text(
         body, mock_parser, implicit_doctype=doctypes.xhtml)
     template = compiler(params=sorted(kwargs.keys()))
     return template.render(**kwargs)    
 
 def render_zpt(body, **kwargs):
-    compiler = translation.Compiler(
+    compiler = TestCompiler(
         body, zpt.ZopePageTemplateParser(), implicit_doctype=doctypes.xhtml)
     template = compiler(params=sorted(kwargs.keys()))
     return template.render(**kwargs)    
 
 def render_genshi(body, **kwargs):
-    compiler = translation.Compiler(
+    compiler = TestCompiler(
         body, genshi.GenshiParser(), implicit_doctype=doctypes.xhtml)
     template = compiler(params=sorted(kwargs.keys()))
     kwargs.update(template.selectors)
@@ -61,7 +68,7 @@
     @property
     def macros(self):
         def render(macro=None, **kwargs):
-            compiler = translation.Compiler(self.body, self.parser)
+            compiler = TestCompiler(self.body, self.parser)
             template = compiler(macro=macro, params=kwargs.keys())
             return template.render(**kwargs)
         return macro.Macros(render)



More information about the Checkins mailing list