2
# -*- coding: utf-8 -*-
5
Unit tests for gluon.cache
10
if os.path.isdir('gluon'):
11
sys.path.append(os.path.realpath('gluon'))
13
sys.path.append(os.path.realpath('../'))
16
from storage import Storage
17
from cache import CacheInRam, CacheOnDisk
25
if not os.path.isdir('gluon'):
26
os.chdir(os.path.realpath('../../'))
34
class TestCache(unittest.TestCase):
36
def testCacheInRam(self):
38
# defaults to mode='http'
41
self.assertEqual(cache('a', lambda: 1, 0), 1)
42
self.assertEqual(cache('a', lambda: 2, 100), 1)
44
self.assertEqual(cache('a', lambda: 2, 100), 1)
46
self.assertEqual(cache('a', lambda: 2, 100), 2)
48
self.assertEqual(cache('a', lambda: 3, 100), 3)
49
self.assertEqual(cache('a', lambda: 4, 0), 4)
51
def testCacheOnDisk(self):
53
# defaults to mode='http'
55
s = Storage({'application': 'admin',
56
'folder': 'applications/admin'})
57
cache = CacheOnDisk(s)
58
self.assertEqual(cache('a', lambda: 1, 0), 1)
59
self.assertEqual(cache('a', lambda: 2, 100), 1)
61
self.assertEqual(cache('a', lambda: 2, 100), 1)
63
self.assertEqual(cache('a', lambda: 2, 100), 2)
65
self.assertEqual(cache('a', lambda: 3, 100), 3)
66
self.assertEqual(cache('a', lambda: 4, 0), 4)
69
if __name__ == '__main__':
70
setUpModule() # pre-python-2.7