test_lrucache.py
This file
Path
tests/test_lrucache.py
39 lines · 802 bytes · Python
Last changed by
Copyright switch to "The Jinja Team".Armin Ronacherbefore adoption62ccd1b
History of this fileTake it
more thread safety in LRUCacheArmin Ronacherbefore adoptione25f24d
lines 1–7why, one step back1# -*- coding: utf-8 -*-2"""3 Tests the LRUCache4 ~~~~~~~~~~~~~~~~~~56 This module tests the LRU Cache7Copyright switch to "The Jinja Team".Armin Ronacherbefore adoption62ccd1b
line 8why, one step back8 :copyright: (c) 2009 by the Jinja Team.fixed a few broken license declarations. should have been BSD not GPLArmin Ronacherbefore adoptiond776437
line 9why, one step back9 :license: BSD.more thread safety in LRUCacheArmin Ronacherbefore adoptione25f24d
lines 10–13why, one step back10"""11import thread12import time13import randomadded more unittests for various tasksArmin Ronacherbefore adoption9f258ff
line 14why, one step back14import picklemore thread safety in LRUCacheArmin Ronacherbefore adoptione25f24d
lines 15–26why, one step back15from jinja2.utils import LRUCache161718def test_simple():19 d = LRUCache(3)20 d["a"] = 121 d["b"] = 222 d["c"] = 323 d["a"]24 d["d"] = 425 assert len(d) == 326 assert 'a' in d and 'c' in d and 'd' in d and 'b' not in dadded more unittests for various tasksArmin Ronacherbefore adoption9f258ff
lines 27–39why, one step back272829def test_pickleable():30 cache = LRUCache(2)31 cache["foo"] = 4232 cache["bar"] = 2333 cache["foo"]3435 for protocol in range(3):36 copy = pickle.loads(pickle.dumps(cache, protocol))37 assert copy.capacity == cache.capacity38 assert copy._mapping == cache._mapping39 assert copy._queue == cache._queue