Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 793ddd4 point at it.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 1–2why, one step back
1# -*- coding: utf-8 -*-
2import pytest

Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b

line 3why, one step back
3

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

lines 4–8why, one step back
4from jinja2 import Environment
5from jinja2.bccache import Bucket6from jinja2.bccache import FileSystemBytecodeCache7from jinja2.bccache import MemcachedBytecodeCache8from jinja2.exceptions import TemplateNotFound

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 9–11why, one step back
9
1011@pytest.fixture

isolate bytecode cache testsDavid Lordbefore adoptiond312609

lines 12–14why, one step back
12def env(package_loader, tmp_path):
13 bytecode_cache = FileSystemBytecodeCache(str(tmp_path))14 return Environment(loader=package_loader, bytecode_cache=bytecode_cache)

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 15–18why, one step back
15
1617class TestByteCodeCache(object):18 def test_simple(self, env):

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 19–21why, one step back
19 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 back
22
2324class 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)51

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 52–53why, one step back
52 b = Bucket(None, "key", "")
53 b.code = "code"

Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b

line 54why, one step back
54 m.dump_bytecode(b)

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 55why, one step back
55 assert memcached.key == "jinja2/bytecode/key"

Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b

line 56why, one step back
56

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

line 57why, one step back
57 b = Bucket(None, "key", "")

Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b

line 58why, one step back
58 m.load_bytecode(b)

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

line 59why, one step back
59 assert b.code == "code"

Merge pull request #672 from alexk307/tests-memcached-bytecode-cacheDavid Lordbefore adoption5828b8b

lines 60–65why, one step back
60
61 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 back
66 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 back
68
69 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)