layout='...',
index='{% extends 'layout' %}...'
)))
+
+ This loader does not have any caching capabilities.
"""
def __init__(self, templates):
simple_env = Environment(trim_blocks=True, friendly_traceback=False, loader=loader)
+class MemcacheClient(object):
+ """
+ Helper for the loader test.
+ """
+
+ def __init__(self, hosts):
+ self.cache = {}
+
+ def get(self, name):
+ return self.cache.get(name)
+
+ def set(self, name, data, time):
+ self.cache[name] = data
+
+sys.modules['memcache'] = memcache = type(sys)('memcache')
+memcache.Client = MemcacheClient
+
+
class Module(py.test.collect.Module):
def __init__(self, *args, **kwargs):
filesystem_loader = loaders.FileSystemLoader('loaderres/templates')
+memcached_loader = loaders.MemcachedFileSystemLoader('loaderres/templates')
+
function_loader = loaders.FunctionLoader({'justfunction.html': 'FOO'}.get)
choice_loader = loaders.ChoiceLoader([dict_loader, package_loader])
raise AssertionError('expected template exception')
+def test_memcached_loader():
+ env = Environment(loader=memcached_loader)
+ tmpl = env.get_template('test.html')
+ assert tmpl.render().strip() == 'BAR'
+ tmpl = env.get_template('foo/test.html')
+ assert tmpl.render().strip() == 'FOO'
+ try:
+ env.get_template('missing.html')
+ except TemplateNotFound:
+ pass
+ else:
+ raise AssertionError('expected template exception')
+
+
def test_choice_loader():
env = Environment(loader=choice_loader)
tmpl = env.get_template('justdict.html')