test_bytecode_cache.py
This file
Path
tests/test_bytecode_cache.py
79 lines · 2.0 KiB · Python
Last changed by
Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
History of this fileTake it
The walk stopped after 200 commits: lines older than 147bd57 point at it.
Change grouping behavior of tests. This fixes #401Armin Ronacherbefore adoption147bd57
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 back3Change grouping behavior of tests. This fixes #401Armin Ronacherbefore adoption147bd57
line 4why, one step back4from jinja2 import EnvironmentMerge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 5–7why, one step back5from jinja2.bccache import Bucket6from jinja2.bccache import FileSystemBytecodeCache7from jinja2.bccache import MemcachedBytecodeCacheChange grouping behavior of tests. This fixes #401Armin Ronacherbefore adoption147bd57
lines 8–13why, one step back8from jinja2.exceptions import TemplateNotFound91011@pytest.fixture12def env(package_loader):13 bytecode_cache = FileSystemBytecodeCache()Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 14why, one step back14 return Environment(loader=package_loader, bytecode_cache=bytecode_cache,)Change grouping behavior of tests. This fixes #401Armin Ronacherbefore adoption147bd57
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 #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 56why, one step back56 assert memcached.key == "jinja2/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)