Commit 5207d019 authored by Fred Drake's avatar Fred Drake

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
parent 98f91792
......@@ -135,9 +135,49 @@ class DTMLTests(unittest.TestCase):
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()
......@@ -769,11 +769,13 @@ class TALInterpreter:
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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment