Ticket #11461: 11461.diff

File 11461.diff, 5.2 KB (added by Karen Tracey, 14 years ago)
  • django/template/__init__.py

     
    104104invalid_var_format_string = None
    105105
    106106class TemplateSyntaxError(Exception):
    107     def __str__(self):
    108         try:
    109             import cStringIO as StringIO
    110         except ImportError:
    111             import StringIO
    112         output = StringIO.StringIO()
    113         output.write(Exception.__str__(self))
    114         # Check if we wrapped an exception and print that too.
    115         if hasattr(self, 'exc_info'):
    116             import traceback
    117             output.write('\n\nOriginal ')
    118             e = self.exc_info
    119             traceback.print_exception(e[0], e[1], e[2], 500, output)
    120         return output.getvalue()
     107    pass
    121108
    122109class TemplateDoesNotExist(Exception):
    123110    pass
  • django/template/debug.py

     
    7979            wrapped = TemplateSyntaxError(u'Caught an exception while rendering: %s' % force_unicode(e, errors='replace'))
    8080            wrapped.source = node.source
    8181            wrapped.exc_info = exc_info()
    82             raise wrapped
     82            raise wrapped, None, wrapped.exc_info[2]
    8383        return result
    8484
    8585class DebugVariableNode(VariableNode):
  • tests/regressiontests/debug/views.py

     
     1from django.shortcuts import render_to_response
     2
    13from regressiontests.debug import BrokenException, except_args
    24
    35def view_exception(request, n):
     
    35    raise BrokenException(except_args[int(n)])
    46
     7def template_exception(request, n):
     8    return render_to_response('debug/template_exception.html',
     9        {'arg': except_args[int(n)]})
  • tests/regressiontests/debug/tests.py

     
     1import inspect
     2
    13from django.test import TestCase
    24from django.conf import settings
    35from django.core.urlresolvers import reverse
     6from django.template import TemplateSyntaxError
    47
    58from regressiontests.debug import BrokenException, except_args
    69
     
    1013    def setUp(self):
    1114        self.old_debug = settings.DEBUG
    1215        settings.DEBUG = True
     16        self.old_template_debug = settings.TEMPLATE_DEBUG
     17        settings.TEMPLATE_DEBUG = True
    1318
    1419    def tearDown(self):
    1520        settings.DEBUG = self.old_debug
     21        settings.TEMPLATE_DEBUG = self.old_template_debug
    1622
    1723    def test_view_exceptions(self):
    1824        for n in range(len(except_args)):
    1925            self.assertRaises(BrokenException, self.client.get,
    2026                reverse('view_exception', args=(n,)))
    2127
     28    def test_template_exceptions(self):
     29        for n in range(len(except_args)):
     30            try:
     31                self.client.get(reverse('template_exception', args=(n,)))
     32            except TemplateSyntaxError, e:
     33                raising_loc = inspect.trace()[-1][-2][0].strip()
     34                self.failIf(raising_loc.find('raise BrokenException') == -1,
     35                    "Failed to find 'raise BrokenException' in last frame of traceback, instead found: %s" % raising_loc)
     36
  • tests/regressiontests/debug/templatetags/debugtags.py

     
     1from django import template
     2
     3from regressiontests.debug import BrokenException
     4
     5register = template.Library()
     6
     7@register.simple_tag
     8def go_boom(arg):
     9    raise BrokenException(arg)
     10
  • tests/regressiontests/debug/urls.py

    Property changes on: tests\regressiontests\debug\templatetags\debugtags.py
    ___________________________________________________________________
    Added: svn:eol-style
       + native
    
     
    22
    33urlpatterns = patterns('regressiontests.debug.views',
    44    url(r'view_exception/(?P<n>\d+)/$', 'view_exception', name='view_exception'),
     5    url(r'template_exception/(?P<n>\d+)/$', 'template_exception', name='template_exception'),
    56)
  • tests/regressiontests/debug/templates/debug/template_exception.html

     
     1{% load debugtags %}
     2{% go_boom arg %}
Back to Top