PrefixLoader raises correct error message now. This fixes #358.
authorArmin Ronacher <armin.ronacher@active-4.com>
Tue, 9 Feb 2010 00:27:57 +0000 (01:27 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Tue, 9 Feb 2010 00:27:57 +0000 (01:27 +0100)
--HG--
branch : trunk

jinja2/loaders.py
tests/test_old_bugs.py

index 7dda2aecfb159ada7bf073729c3697f98e380461..cfc738b78c48401ca06b802272722c75f4aef9f3 100644 (file)
@@ -277,11 +277,16 @@ class PrefixLoader(BaseLoader):
 
     def get_source(self, environment, template):
         try:
-            prefix, template = template.split(self.delimiter, 1)
+            prefix, name = template.split(self.delimiter, 1)
             loader = self.mapping[prefix]
         except (ValueError, KeyError):
             raise TemplateNotFound(template)
-        return loader.get_source(environment, template)
+        try:
+            return loader.get_source(environment, name)
+        except TemplateNotFound:
+            # re-raise the exception with the correct fileame here.
+            # (the one that includes the prefix)
+            raise TemplateNotFound(template)
 
 
 class ChoiceLoader(BaseLoader):
index 5e51391a781c782dc1ceebf6906d1ca735b042bb..1ff5a5506f5d3f347f571f7fbbf58b6634b4eaec 100644 (file)
@@ -8,7 +8,8 @@
     :copyright: (c) 2009 by the Jinja Team.
     :license: BSD.
 """
-from jinja2 import Template, Environment, DictLoader, TemplateSyntaxError
+from jinja2 import Template, Environment, DictLoader, TemplateSyntaxError, \
+     TemplateNotFound, PrefixLoader
 
 env = Environment()
 
@@ -168,3 +169,15 @@ def test_recursive_loop_bug():
         {% endfor %}
     {% endfor %}
     """)
+
+
+def test_correct_prefix_loader_name():
+    env = Environment(loader=PrefixLoader({
+        'foo':  DictLoader({})
+    }))
+    try:
+        env.get_template('foo/bar.html')
+    except TemplateNotFound, e:
+        assert e.name == 'foo/bar.html'
+    else:
+        assert False, 'expected error here'