blob: 9a1d7d10b58c1ce5bd60d8225069805075c1d138 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
from __future__ import unicode_literals
import unittest
from rich._lru_cache import LRUCache
def test_lru_cache():
cache = LRUCache(3)
# insert some values
cache["foo"] = 1
cache["bar"] = 2
cache["baz"] = 3
assert "foo" in cache
# Cache size is 3, so the following should kick oldest one out
cache["egg"] = 4
assert "foo" not in cache
assert "egg" in "egg" in cache
# cache is now full
# look up two keys
cache["bar"]
cache["baz"]
# Insert a new value
cache["eggegg"] = 5
# Check it kicked out the 'oldest' key
assert "egg" not in cache
|