Automated merge with ssh://team@pocoo.org/jinja2-main
[jinja2.git] / tests / test_lrucache.py
1 # -*- coding: utf-8 -*-
2 """
3     Tests the LRUCache
4     ~~~~~~~~~~~~~~~~~~
5
6     This module tests the LRU Cache
7
8     :copyright: Copyright 2008 by Armin Ronacher.
9     :license: BSD.
10 """
11 import thread
12 import time
13 import random
14 import pickle
15 from jinja2.utils import LRUCache
16
17
18 def test_simple():
19     d = LRUCache(3)
20     d["a"] = 1
21     d["b"] = 2
22     d["c"] = 3
23     d["a"]
24     d["d"] = 4
25     assert len(d) == 3
26     assert 'a' in d and 'c' in d and 'd' in d and 'b' not in d
27
28
29 def test_pickleable():
30     cache = LRUCache(2)
31     cache["foo"] = 42
32     cache["bar"] = 23
33     cache["foo"]
34
35     for protocol in range(3):
36         copy = pickle.loads(pickle.dumps(cache, protocol))
37         assert copy.capacity == cache.capacity
38         assert copy._mapping == cache._mapping
39         assert copy._queue == cache._queue