1#!/usr/bin/env python3
2
3"""Test the lru_cache decorator
4"""
5
6from chart.common.decorators import lra_cache
7
8# pylint:disable=C0111
9
10
11class Counter(object):
12 def __init__(self):
13 self.cc = 0
14
15 def inc(self):
16 self.cc += 1
17
18 def tell(self):
19 return self.cc
20
21cc = 0
22
23
24@lra_cache(maxsize=5)
25def fn(dummy_value):
26 global cc
27 cc += 1
28
29
30def test_lracache():
31 fn(1)
32 fn(2)
33 fn(3)
34 fn(4)
35 fn(5)
36 assert cc == 5
37
38 fn(1)
39 assert cc == 5
40
41 fn(6)
42 assert cc == 6
43
44 fn(1)
45 assert cc == 7