Skip to content
Myr

PrefixLoader raises correct error message now. This fixes #358.

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 9b4cc9f · Browse files · 2 files+21 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+21 added−3 removed

  • tests:+14 added−1 removed
  • other:+7 added−2 removed

2 files+21 added−3 removed

modified:jinja2/loaders.py+7 added-2 removed
275 unmodified lines
276 self.delimiter = delimiter277278 def get_source(self, environment, template):279 try:280 prefix, template = template.split(self.delimiter, 1)280 prefix, name = template.split(self.delimiter, 1)281 loader = self.mapping[prefix]282 except (ValueError, KeyError):283 raise TemplateNotFound(template)284 try:284 return loader.get_source(environment, template)285 return loader.get_source(environment, name)286 except TemplateNotFound:287 # re-raise the exception with the correct fileame here.288 # (the one that includes the prefix)289 raise TemplateNotFound(template)290291292class ChoiceLoader(BaseLoader):293 """This loader works like the `PrefixLoader` just that no prefix is
22 unmodified lines
modified:tests/test_old_bugs.py+14 added-1 removed
6 unmodified lines
78 :copyright: (c) 2009 by the Jinja Team.9 :license: BSD.10"""11from jinja2 import Template, Environment, DictLoader, TemplateSyntaxError11from jinja2 import Template, Environment, DictLoader, TemplateSyntaxError, \12 TemplateNotFound, PrefixLoader1314env = Environment()1516from nose import SkipTest
151 unmodified lines
168 {% endif %}169 {% endfor %}170 {% endfor %}171 """)172173174def test_correct_prefix_loader_name():175 env = Environment(loader=PrefixLoader({176 'foo': DictLoader({})177 }))178 try:179 env.get_template('foo/bar.html')180 except TemplateNotFound, e:181 assert e.name == 'foo/bar.html'182 else:183 assert False, 'expected error here'