[svn] added simple memcached loader test
authorArmin Ronacher <armin.ronacher@active-4.com>
Fri, 1 Jun 2007 23:47:34 +0000 (01:47 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Fri, 1 Jun 2007 23:47:34 +0000 (01:47 +0200)
--HG--
branch : trunk

jinja/loaders.py
tests/conftest.py
tests/test_loaders.py

index c6b82f006178ce32ae619abfc69c8dc2fec5d353..b17c44c7e92f13fb50a44f996bb6cb3e3d258af3 100644 (file)
@@ -666,6 +666,8 @@ class DictLoader(BaseLoader):
             layout='...',
             index='{% extends 'layout' %}...'
         )))
+
+    This loader does not have any caching capabilities.
     """
 
     def __init__(self, templates):
index e97e30cfceb4c11790afce41289eb32946f15188..0c5a5fff9399d37ac4477f7b75ac7cf678bd1579 100644 (file)
@@ -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):
index 0111dd70e69fa482502b33b22d80e8bc982e93ee..2335b9cbaad3eac2b17e8895573187f6ee5bb1be 100644 (file)
@@ -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')