test_bytecode_cache.py
This file
Path
tests/test_bytecode_cache.py
78 lines · 2.0 KiB · Python
Last changed by
remove custom pytest marksDavid Lordbefore adoptiondd5a050
History of this fileTake it
The walk stopped after 200 commits: lines older than 3e4ebc8 point at it.
Bump version number to 2.9Armin Ronacherbefore adoption3e4ebc8
lines 1–2why, one step back1# -*- coding: utf-8 -*-2import pytestMerge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b
line 3why, one step back3Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
lines 4–8why, one step back4from jinja2 import Environment5from jinja2.bccache import Bucket6from jinja2.bccache import FileSystemBytecodeCache7from jinja2.bccache import MemcachedBytecodeCache8from jinja2.exceptions import TemplateNotFoundBump version number to 2.9Armin Ronacherbefore adoption3e4ebc8
lines 9–11why, one step back91011@pytest.fixtureisolate bytecode cache testsDavid Lordbefore adoptiond312609
lines 12–14why, one step back12def env(package_loader, tmp_path):13 bytecode_cache = FileSystemBytecodeCache(str(tmp_path))14 return Environment(loader=package_loader, bytecode_cache=bytecode_cache)Bump version number to 2.9Armin Ronacherbefore adoption3e4ebc8
lines 15–18why, one step back151617class TestByteCodeCache(object):18 def test_simple(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 19–21why, one step back19 tmpl = env.get_template("test.html")20 assert tmpl.render().strip() == "BAR"21 pytest.raises(TemplateNotFound, env.get_template, "missing.html")Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b
lines 22–51why, one step back222324class MockMemcached(object):25 class Error(Exception):26 pass2728 key = None29 value = None30 timeout = None3132 def get(self, key):33 return self.value3435 def set(self, key, value, timeout=None):36 self.key = key37 self.value = value38 self.timeout = timeout3940 def get_side_effect(self, key):41 raise self.Error()4243 def set_side_effect(self, *args):44 raise self.Error()454647class TestMemcachedBytecodeCache(object):48 def test_dump_load(self):49 memcached = MockMemcached()50 m = MemcachedBytecodeCache(memcached)51Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 52–53why, one step back52 b = Bucket(None, "key", "")53 b.code = "code"Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b
line 54why, one step back54 m.dump_bytecode(b)Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 55why, one step back55 assert memcached.key == "jinja2/bytecode/key"Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b
line 56why, one step back56Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 57why, one step back57 b = Bucket(None, "key", "")Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b
line 58why, one step back58 m.load_bytecode(b)Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 59why, one step back59 assert b.code == "code"Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b
lines 60–65why, one step back6061 def test_exception(self):62 memcached = MockMemcached()63 memcached.get = memcached.get_side_effect64 memcached.set = memcached.set_side_effect65 m = MemcachedBytecodeCache(memcached)Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 66–67why, one step back66 b = Bucket(None, "key", "")67 b.code = "code"Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b
lines 68–78why, one step back6869 m.dump_bytecode(b)70 m.load_bytecode(b)7172 m.ignore_memcache_errors = False7374 with pytest.raises(MockMemcached.Error):75 m.dump_bytecode(b)7677 with pytest.raises(MockMemcached.Error):78 m.load_bytecode(b)