Skip to content
Myr

test_bytecode_cache.py

This file

Path

tests/test_bytecode_cache.py

79 lines · 2.0 KiB · Python

Last changed by

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

History of this file

Take 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 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

Bump version number to 2.9Armin Ronacherbefore adoption3e4ebc8

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

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

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

Bump version number to 2.9Armin Ronacherbefore adoption3e4ebc8

lines 15–19why, one step back
15
1617@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 back
20 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 back
23
2425class 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)52

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

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

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

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

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

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

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

line 57why, one step back
57

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

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

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

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

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

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

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

lines 61–66why, one step back
61
62 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 back
67 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 back
69
70 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)