Fixed some tests for python 2.4. Disabled a test for 2.4 that does not work because of a python limitation.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Armin Ronacher · committed by Armin Ronacher · parent 28decdb · Browse files · 3 files·+23 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+23 added−8 removed
- other:+23 added−8 removed
Provenance
- Commit
821a423- Tree
d28b234- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
28decdb
3 files changed+23 added−8 removed
modified:jinja2/testsuite/debug.py+7 added-5 removed
6 unmodified lines7 8 :copyright: (c) 2010 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10 """11+import sys12 import unittest13 14 from jinja2.testsuite import JinjaTestCase, filesystem_loader15 3 unmodified lines19 20 21 class DebugTestCase(JinjaTestCase):22 23+ if sys.version_info[:2] != (2, 4):22- def test_runtime_error(self):23- def test():24- tmpl.render(fail=lambda: 1 / 0)25- tmpl = env.get_template('broken.html')26- self.assert_traceback_matches(test, r'''24+ def test_runtime_error(self):25+ def test():26+ tmpl.render(fail=lambda: 1 / 0)27+ tmpl = env.get_template('broken.html')28+ self.assert_traceback_matches(test, r'''29 File ".*?broken.html", line 2, in (top-level template code|<module>)30 \{\{ fail\(\) \}\}31 File ".*?debug.pyc?", line \d+, in <lambda>32 tmpl\.render\(fail=lambda: 1 / 0\)28 unmodified linesmodified:jinja2/compiler.py+15 added-2 removed
42 unmodified lines43 else:44 dict_item_iter = 'items'45 46 47+# does if 0: dummy(x) get us x into the scope?48+def unoptimize_before_dead_code():49+ x = 4250+ def f():51+ if 0: dummy(x)52+ return f53+unoptimize_before_dead_code = bool(unoptimize_before_dead_code().func_closure)54+55+56 def generate(node, environment, name, filename, stream=None):57 """Generate the python source for a node tree."""58 if not isinstance(node, nodes.Template):59 raise TypeError('Can\'t compile non template nodes')524 unmodified lines584 # mainly works because python finds the locals before dead code585 # is removed. If that breaks we have to add a dummy function586 # that just accepts the arguments and does nothing.587 if frame.identifiers.declared:579- self.writeline('if 0: dummy(%s)' % ', '.join(580- 'l_' + name for name in frame.identifiers.declared))588+ self.writeline('%sdummy(%s)' % (589+ unoptimize_before_dead_code and 'if 0: ' or '',590+ ', '.join('l_' + name for name in frame.identifiers.declared)591+ ))592 593 def push_scope(self, frame, extra_vars=()):594 """This function returns all the shadowed variables in a dict595 in the form name: alias and will write the required assignments153 unmodified lines749 assert frame is None, 'no root frame allowed'750 from jinja2.runtime import __all__ as exported751 self.writeline('from __future__ import division')752 self.writeline('from jinja2.runtime import ' + ', '.join(exported))753+ if not unoptimize_before_dead_code:754+ self.writeline('dummy = lambda *x: None')755 756 # do we have an extends tag at all? If not, we can save some757 # overhead by just not processing any inheritance code.758 have_extends = node.find(nodes.Extends) is not None812 unmodified linesmodified:jinja2/debug.py+1 added-1 removed
111 unmodified lines112 def translate_syntax_error(error, source=None):113 """Rewrites a syntax error to please traceback systems."""114 error.source = source115 error.translated = True116- exc_info = (type(error), error, None)116+ exc_info = (error.__class__, error, None)117 filename = error.filename118 if filename is None:119 filename = '<unknown>'120 return fake_exc_info(exc_info, filename, error.lineno)188 unmodified lines