Skip to content
Myr

Adds tests for the memcached bytecode cache module

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Alex Kahan · committed by David Lord · parent 711ad9d · Browse files · 1 file+64 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+64 added−1 removed

  • tests:+64 added−1 removed

1 file+64 added−1 removed

modified:tests/test_bytecode_cache.py+64 added-1 removed
8 unmodified lines
9 :license: BSD, see LICENSE for more details.10"""11import pytest12from jinja2 import Environment13from jinja2.bccache import FileSystemBytecodeCache13from jinja2.bccache import FileSystemBytecodeCache, MemcachedBytecodeCache,\14 Bucket15from jinja2.exceptions import TemplateNotFound161718@pytest.fixture
11 unmodified lines
30 def test_simple(self, env):31 tmpl = env.get_template('test.html')32 assert tmpl.render().strip() == 'BAR'33 pytest.raises(TemplateNotFound, env.get_template, 'missing.html')343536class MockMemcached(object):3738 def get(self, key):39 return "value"4041 def set(self, *args):42 pass4344 def get_side_effect(self, key):45 raise Exception()4647 def set_side_effect(self, *args):48 raise Exception()495051class TestMemcachedBytecodeCache(object):5253 def test_load_bytecode(self):5455 # Python 2.X does not have explicit bytes type and Python 3.X's56 # str type does not support Buffer interface57 try:58 key = bytes("key", "utf-8") # PY 3.X59 except:60 key = "key" # PY 2.X6162 m = MemcachedBytecodeCache(MockMemcached())63 b = Bucket("", key, "")64 m.load_bytecode(b)6566 def test_load_bytecode_exception(self):67 memcached = MockMemcached()68 memcached.get = memcached.get_side_effect69 m = MemcachedBytecodeCache(memcached)70 b = Bucket("", "key", "")71 m.load_bytecode(b)7273 def test_load_bytecode_exception_raise(self):74 memcached = MockMemcached()75 memcached.get = memcached.get_side_effect76 m = MemcachedBytecodeCache(memcached, ignore_memcache_errors=False)77 b = Bucket("", "key", "")78 with pytest.raises(Exception):79 m.load_bytecode(b)8081 def test_dump_bytecode(self):82 memcached = MockMemcached()83 m = MemcachedBytecodeCache(memcached, timeout=10)84 b = Bucket("", "key", "")85 b.code = "code"86 m.dump_bytecode(b)8788 def test_dump_bytecode_exception_raise(self):89 memcached = MockMemcached()90 memcached.set = memcached.set_side_effect91 m = MemcachedBytecodeCache(memcached, ignore_memcache_errors=False)92 b = Bucket("", "key", "")93 b.code = "code"94 with pytest.raises(Exception):95 m.dump_bytecode(b)