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
Provenance
- Commit
a675c85- Tree
7b3df29- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
6e74191
1 file changed+37 added−40 removed
modified:tests/test_bytecode_cache.py+37 added-40 removed
6 unmodified lines7 8 :copyright: (c) 2017 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10 """11+12 import pytest13+14 from jinja2 import Environment13-from jinja2.bccache import FileSystemBytecodeCache, MemcachedBytecodeCache,\14- Bucket15+from jinja2.bccache import Bucket, FileSystemBytecodeCache, \16+ MemcachedBytecodeCache17 from jinja2.exceptions import TemplateNotFound18 19 20 @pytest.fixture14 unmodified lines35 pytest.raises(TemplateNotFound, env.get_template, 'missing.html')36 37 38 class MockMemcached(object):39+ class Error(Exception):40+ pass41 42+ key = None43+ value = None44+ timeout = None45+46 def get(self, key):39- return "value"47+ return self.value48 41- def set(self, *args):42- pass49+ def set(self, key, value, timeout=None):50+ self.key = key51+ self.value = value52+ self.timeout = timeout53 54 def get_side_effect(self, key):45- raise Exception()55+ raise self.Error()56 57 def set_side_effect(self, *args):48- raise Exception()58+ raise self.Error()59 60 61 class TestMemcachedBytecodeCache(object):62+ def test_dump_load(self):63+ memcached = MockMemcached()64+ m = MemcachedBytecodeCache(memcached)65 53- 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'70 55- # 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.X61-62- m = MemcachedBytecodeCache(MockMemcached())63- b = Bucket("", key, "")71+ b = Bucket(None, 'key', '')72 m.load_bytecode(b)73+ assert b.code == 'code'74 66- 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'82 73- 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)80-81- 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)85 88- 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 = False87+88+ with pytest.raises(MockMemcached.Error):89 m.dump_bytecode(b)90+91+ with pytest.raises(MockMemcached.Error):92+ m.load_bytecode(b)