[Zope-Checkins] SVN: Zope/trunk/lib/python/ add tests for on-error
handling in macros for errors in slot fillers; errors
Fred L. Drake, Jr.
fdrake at gmail.com
Tue Mar 14 12:47:30 EST 2006
Log message for revision 66017:
add tests for on-error handling in macros for errors in slot fillers; errors
in the filler can now be handled by the macro, as intended
Changed:
U Zope/trunk/lib/python/Products/PageTemplates/tests/testDTMLTests.py
U Zope/trunk/lib/python/TAL/TALInterpreter.py
-=-
Modified: Zope/trunk/lib/python/Products/PageTemplates/tests/testDTMLTests.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/tests/testDTMLTests.py 2006-03-14 17:46:42 UTC (rev 66016)
+++ Zope/trunk/lib/python/Products/PageTemplates/tests/testDTMLTests.py 2006-03-14 17:47:30 UTC (rev 66017)
@@ -135,9 +135,49 @@
expect = util.read_output('DTML3.html')
util.check_xml(expect, o)
+ def check_on_error_in_slot_filler(self):
+ # The `here` isn't defined, so the macro definition is
+ # expected to catch the error that gets raised.
+ text = '''\
+ <div metal:define-macro="foo">
+ <div tal:on-error="string:eek">
+ <div metal:define-slot="slot" />
+ cool
+ </div>
+ </div>
+
+ <div metal:use-macro="template/macros/foo">
+ <div metal:fill-slot="slot">
+ <p tal:content="here/xxx" />
+ </div>
+ </div>
+ '''
+ self.t.write(text)
+ aa = util.argv(('one', 'two', 'three', 'four', 'five'))
+ self.t.__of__(aa)()
+
+ def check_on_error_in_slot_default(self):
+ # The `here` isn't defined, so the macro definition is
+ # expected to catch the error that gets raised.
+ text = '''\
+ <div metal:define-macro="foo">
+ <div tal:on-error="string:eek">
+ <div metal:define-slot="slot">
+ <div tal:content="here/xxx" />
+ </div>
+ </div>
+ </div>
+
+ <div metal:use-macro="template/macros/foo">
+ </div>
+ '''
+ self.t.write(text)
+ aa = util.argv(('one', 'two', 'three', 'four', 'five'))
+ self.t.__of__(aa)()
+
+
def test_suite():
return unittest.makeSuite(DTMLTests, 'check')
if __name__=='__main__':
main()
-
Modified: Zope/trunk/lib/python/TAL/TALInterpreter.py
===================================================================
--- Zope/trunk/lib/python/TAL/TALInterpreter.py 2006-03-14 17:46:42 UTC (rev 66016)
+++ Zope/trunk/lib/python/TAL/TALInterpreter.py 2006-03-14 17:47:30 UTC (rev 66017)
@@ -769,11 +769,13 @@
slot = slots.get(slotName)
if slot is not None:
prev_source = self.sourceFile
- self.interpret(slot)
- if self.sourceFile != prev_source:
- self.engine.setSourceFile(prev_source)
- self.sourceFile = prev_source
- self.pushMacro(macroName, slots, entering=0)
+ try:
+ self.interpret(slot)
+ finally:
+ if self.sourceFile != prev_source:
+ self.engine.setSourceFile(prev_source)
+ self.sourceFile = prev_source
+ self.pushMacro(macroName, slots, entering=0)
return
self.pushMacro(macroName, slots)
# Falling out of the 'if' allows the macro to be interpreted.
More information about the Zope-Checkins
mailing list