Chris McDonough
2011-08-19 9f7f4f5219335e8bca108018c699ffdda8f40425
- Better Mako rendering exceptions via
``pyramid.mako_templating.MakoRenderingException``
2 files modified
29 ■■■■■ changed files
CHANGES.txt 3 ●●●●● patch | view | raw | blame | history
pyramid/tests/test_mako_templating.py 26 ●●●●● patch | view | raw | blame | history
CHANGES.txt
@@ -72,6 +72,9 @@
  ``authorization_policy``) to override the same settings obtained via an
  "include".
- Better Mako rendering exceptions via
  ``pyramid.mako_templating.MakoRenderingException``
Internal
--------
pyramid/tests/test_mako_templating.py
@@ -300,6 +300,17 @@
        instance = self._makeOne('path', lookup)
        self.assertRaises(ValueError, instance, None, {})
    def test_call_render_raises(self):
        from pyramid.mako_templating import MakoRenderingException
        lookup = DummyLookup(exc=NotImplementedError)
        instance = self._makeOne('path', lookup)
        try:
            instance({}, {})
        except MakoRenderingException, e:
            self.assertTrue('NotImplementedError' in e.text)
        else: # pragma: no cover
            raise AssertionError
    def test_implementation(self):
        lookup = DummyLookup()
        instance = self._makeOne('path', lookup)
@@ -412,7 +423,20 @@
        self.assertRaises(TopLevelLookupException, inst.get_template,
                          'pyramid.tests:fixtures/notthere.mak')
class TestMakoRenderingException(unittest.TestCase):
    def _makeOne(self, text):
        from pyramid.mako_templating import MakoRenderingException
        return MakoRenderingException(text)
    def test_repr_and_str(self):
        exc = self._makeOne('text')
        self.assertEqual(str(exc), 'text')
        self.assertEqual(repr(exc), 'text')
class DummyLookup(object):
    def __init__(self, exc=None):
        self.exc = exc
    def get_template(self, path):
        self.path = path
        return self
@@ -422,6 +446,8 @@
        return self
    def render_unicode(self, **values):
        if self.exc:
            raise self.exc
        self.values = values
        return u'result'