Skip to content
Myr

rewrite tests to match usage

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

authored by David Lord · committed by David Lord · parent 6e74191 · Browse files · 1 file+37 added−40 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+37 added−40 removed

  • tests:+37 added−40 removed

1 file+37 added−40 removed

modified:tests/test_bytecode_cache.py+37 added-40 removed
6 unmodified lines
78 :copyright: (c) 2017 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10"""1112import pytest1314from jinja2 import Environment13from jinja2.bccache import FileSystemBytecodeCache, MemcachedBytecodeCache,\14 Bucket15from jinja2.bccache import Bucket, FileSystemBytecodeCache, \16 MemcachedBytecodeCache17from jinja2.exceptions import TemplateNotFound181920@pytest.fixture
14 unmodified lines
35 pytest.raises(TemplateNotFound, env.get_template, 'missing.html')363738class MockMemcached(object):39 class Error(Exception):40 pass4142 key = None43 value = None44 timeout = None4546 def get(self, key):39 return "value"47 return self.value4841 def set(self, *args):42 pass49 def set(self, key, value, timeout=None):50 self.key = key51 self.value = value52 self.timeout = timeout5354 def get_side_effect(self, key):45 raise Exception()55 raise self.Error()5657 def set_side_effect(self, *args):48 raise Exception()58 raise self.Error()596061class TestMemcachedBytecodeCache(object):62 def test_dump_load(self):63 memcached = MockMemcached()64 m = MemcachedBytecodeCache(memcached)6553 def test_load_bytecode(self):66 b = Bucket(None, 'key', '')67 b.code = 'code'68 m.dump_bytecode(b)69 assert memcached.key == 'jinja2/bytecode/key'7055 # 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, "")71 b = Bucket(None, 'key', '')72 m.load_bytecode(b)73 assert b.code == 'code'7466 def test_load_bytecode_exception(self):75 def test_exception(self):76 memcached = MockMemcached()77 memcached.get = memcached.get_side_effect78 memcached.set = memcached.set_side_effect79 m = MemcachedBytecodeCache(memcached)70 b = Bucket("", "key", "")71 m.load_bytecode(b)80 b = Bucket(None, 'key', '')81 b.code = 'code'8273 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"83 m.dump_bytecode(b)84 m.load_bytecode(b)8588 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):86 m.ignore_memcache_errors = False8788 with pytest.raises(MockMemcached.Error):89 m.dump_bytecode(b)9091 with pytest.raises(MockMemcached.Error):92 m.load_bytecode(b)