test_bytecode_cache.py
This file
Path
tests/test_bytecode_cache.py
79 lines · 2.0 KiB · Python
Last changed by
Merge pull request #1121 from pallets/the-great-renameDavid Lordbefore adoption457b59b
History of this fileTake it
The walk stopped after 200 commits: lines older than 0020a47 point at it.
Added a more convenient autoescaping functionArmin Ronacherbefore adoption0020a47
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 #1121 from pallets/the-great-renameDavid Lordbefore adoption457b59b
lines 4–8why, one step back4from jinja import Environment5from jinja.bccache import Bucket6from jinja.bccache import FileSystemBytecodeCache7from jinja.bccache import MemcachedBytecodeCache8from jinja.exceptions import TemplateNotFoundAdded a more convenient autoescaping functionArmin Ronacherbefore adoption0020a47
lines 9–11why, one step back91011@pytest.fixtureMerge pull request #1121 from pallets/the-great-renameDavid Lordbefore adoption457b59b
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)Added a more convenient autoescaping functionArmin Ronacherbefore adoption0020a47
lines 15–19why, one step back151617@pytest.mark.byte_code_cache18class TestByteCodeCache(object):19 def test_simple(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 20–22why, one step back20 tmpl = env.get_template("test.html")21 assert tmpl.render().strip() == "BAR"22 pytest.raises(TemplateNotFound, env.get_template, "missing.html")Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b
lines 23–52why, one step back232425class MockMemcached(object):26 class Error(Exception):27 pass2829 key = None30 value = None31 timeout = None3233 def get(self, key):34 return self.value3536 def set(self, key, value, timeout=None):37 self.key = key38 self.value = value39 self.timeout = timeout4041 def get_side_effect(self, key):42 raise self.Error()4344 def set_side_effect(self, *args):45 raise self.Error()464748class TestMemcachedBytecodeCache(object):49 def test_dump_load(self):50 memcached = MockMemcached()51 m = MemcachedBytecodeCache(memcached)52Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 53–54why, one step back53 b = Bucket(None, "key", "")54 b.code = "code"Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b
line 55why, one step back55 m.dump_bytecode(b)Merge pull request #1121 from pallets/the-great-renameDavid Lordbefore adoption457b59b
line 56why, one step back56 assert memcached.key == "jinja/bytecode/key"Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b
line 57why, one step back57Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 58why, one step back58 b = Bucket(None, "key", "")Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b
line 59why, one step back59 m.load_bytecode(b)Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 60why, one step back60 assert b.code == "code"Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b
lines 61–66why, one step back6162 def test_exception(self):63 memcached = MockMemcached()64 memcached.get = memcached.get_side_effect65 memcached.set = memcached.set_side_effect66 m = MemcachedBytecodeCache(memcached)Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 67–68why, one step back67 b = Bucket(None, "key", "")68 b.code = "code"Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b
lines 69–79why, one step back6970 m.dump_bytecode(b)71 m.load_bytecode(b)7273 m.ignore_memcache_errors = False7475 with pytest.raises(MockMemcached.Error):76 m.dump_bytecode(b)7778 with pytest.raises(MockMemcached.Error):79 m.load_bytecode(b)