From 143a07e896f5a6db36b235611e379327f437a487 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sat, 2 Jun 2007 01:47:34 +0200 Subject: [PATCH] [svn] added simple memcached loader test --HG-- branch : trunk --- jinja/loaders.py | 2 ++ tests/conftest.py | 18 ++++++++++++++++++ tests/test_loaders.py | 16 ++++++++++++++++ 3 files changed, 36 insertions(+) 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') -- 2.26.2