From: Armin Ronacher Date: Fri, 1 Jun 2007 23:47:34 +0000 (+0200) Subject: [svn] added simple memcached loader test X-Git-Tag: 2.0rc1~300 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=143a07e896f5a6db36b235611e379327f437a487;p=jinja2.git [svn] added simple memcached loader test --HG-- branch : trunk --- diff --git a/jinja/loaders.py b/jinja/loaders.py index c6b82f0..b17c44c 100644 --- a/jinja/loaders.py +++ b/jinja/loaders.py @@ -666,6 +666,8 @@ class DictLoader(BaseLoader): layout='...', index='{% extends 'layout' %}...' ))) + + This loader does not have any caching capabilities. """ def __init__(self, templates): diff --git a/tests/conftest.py b/tests/conftest.py index e97e30c..0c5a5ff 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -73,6 +73,24 @@ loader = GlobalLoader(globals()) 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): diff --git a/tests/test_loaders.py b/tests/test_loaders.py index 0111dd7..2335b9c 100644 --- a/tests/test_loaders.py +++ b/tests/test_loaders.py @@ -21,6 +21,8 @@ package_loader = loaders.PackageLoader('loaderres', 'templates') 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]) @@ -68,6 +70,20 @@ def test_filesystem_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')