test_bytecode_cache.py
This file
Path
tests/test_bytecode_cache.py
77 lines · 1.9 KiB · Python
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than d312609 point at it.
isolate bytecode cache testsDavid Lordbefore adoptiond312609
lines 1–15why, one step back1import pytest23from jinja2 import Environment4from jinja2.bccache import Bucket5from jinja2.bccache import FileSystemBytecodeCache6from jinja2.bccache import MemcachedBytecodeCache7from jinja2.exceptions import TemplateNotFound8910@pytest.fixture11def env(package_loader, tmp_path):12 bytecode_cache = FileSystemBytecodeCache(str(tmp_path))13 return Environment(loader=package_loader, bytecode_cache=bytecode_cache)1415Merge pull request #1136 from pallets/drop-python2David Lordbefore adoption3915eb5
line 16why, one step back16class TestByteCodeCache:isolate bytecode cache testsDavid Lordbefore adoptiond312609
lines 17–22why, one step back17 def test_simple(self, env):18 tmpl = env.get_template("test.html")19 assert tmpl.render().strip() == "BAR"20 pytest.raises(TemplateNotFound, env.get_template, "missing.html")2122Merge pull request #1136 from pallets/drop-python2David Lordbefore adoption3915eb5
line 23why, one step back23class MockMemcached:isolate bytecode cache testsDavid Lordbefore adoptiond312609
lines 24–45why, one step back24 class Error(Exception):25 pass2627 key = None28 value = None29 timeout = None3031 def get(self, key):32 return self.value3334 def set(self, key, value, timeout=None):35 self.key = key36 self.value = value37 self.timeout = timeout3839 def get_side_effect(self, key):40 raise self.Error()4142 def set_side_effect(self, *args):43 raise self.Error()4445Merge pull request #1136 from pallets/drop-python2David Lordbefore adoption3915eb5
line 46why, one step back46class TestMemcachedBytecodeCache:isolate bytecode cache testsDavid Lordbefore adoptiond312609
lines 47–77why, one step back47 def test_dump_load(self):48 memcached = MockMemcached()49 m = MemcachedBytecodeCache(memcached)5051 b = Bucket(None, "key", "")52 b.code = "code"53 m.dump_bytecode(b)54 assert memcached.key == "jinja2/bytecode/key"5556 b = Bucket(None, "key", "")57 m.load_bytecode(b)58 assert b.code == "code"5960 def test_exception(self):61 memcached = MockMemcached()62 memcached.get = memcached.get_side_effect63 memcached.set = memcached.set_side_effect64 m = MemcachedBytecodeCache(memcached)65 b = Bucket(None, "key", "")66 b.code = "code"6768 m.dump_bytecode(b)69 m.load_bytecode(b)7071 m.ignore_memcache_errors = False7273 with pytest.raises(MockMemcached.Error):74 m.dump_bytecode(b)7576 with pytest.raises(MockMemcached.Error):77 m.load_bytecode(b)