Mercurial > genshi > genshi-test
changeset 206:d122ff386411
`TypeError`s raised by `py:def` macros (and other expressions producing streams) are no longer silently ignored. Closes #44.
author | cmlenz |
---|---|
date | Tue, 29 Aug 2006 10:56:33 +0000 |
parents | 56f5e93edc48 |
children | 0619a27f5e67 |
files | markup/template.py markup/tests/template.py |
diffstat | 2 files changed, 17 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/markup/template.py +++ b/markup/template.py @@ -961,15 +961,16 @@ # Test if the expression evaluated to an iterable, in which # case we yield the individual items try: - substream = _ensure(result) + substream = _ensure(iter(result)) + except TypeError: + # Neither a string nor an iterable, so just pass it + # through + yield TEXT, unicode(result), pos + else: for filter_ in filters: substream = filter_(substream, ctxt) for event in substream: yield event - except TypeError: - # Neither a string nor an iterable, so just pass it - # through - yield TEXT, unicode(result), pos else: yield kind, data, pos
--- a/markup/tests/template.py +++ b/markup/tests/template.py @@ -319,6 +319,17 @@ <p>bar</p> </doc>""", str(tmpl.generate())) + def test_function_raising_typeerror(self): + def badfunc(): + raise TypeError + tmpl = Template("""<html xmlns:py="http://markup.edgewall.org/"> + <div py:def="dobadfunc()"> + ${badfunc()} + </div> + <div py:content="dobadfunc()"/> + </html>""") + self.assertRaises(TypeError, list, tmpl.generate(badfunc=badfunc)) + class ForDirectiveTestCase(unittest.TestCase): """Tests for the `py:for` template directive."""