~ubuntu-branches/debian/sid/web2py/sid

« back to all changes in this revision

Viewing changes to gluon/tests/test_cache.py

  • Committer: Bazaar Package Importer
  • Author(s): José L. Redrejo Rodríguez
  • Date: 2011-06-02 16:55:29 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110602165529-wq73zmx3zy9pc3ul
Tags: 1.96.1-1
* New upstream version
* Move wsgihandler.py from python-web2py to examples of python-gluon
* Added subwsgihandler.py to python-gluon examples (as a patch)
* Added web2py.apache-subdir and updated web2py.apache and README.Debian
* Refreshed debian/patches/avoid_upgrading 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
"""
 
5
    Unit tests for gluon.cache
 
6
"""
 
7
 
 
8
import sys
 
9
import os
 
10
if os.path.isdir('gluon'):
 
11
    sys.path.append(os.path.realpath('gluon'))
 
12
else:
 
13
    sys.path.append(os.path.realpath('../'))
 
14
 
 
15
import unittest
 
16
from storage import Storage
 
17
from cache import CacheInRam, CacheOnDisk
 
18
 
 
19
oldcwd = None
 
20
 
 
21
def setUpModule():
 
22
    global oldcwd
 
23
    if oldcwd is None:
 
24
        oldcwd = os.getcwd()
 
25
        if not os.path.isdir('gluon'):
 
26
            os.chdir(os.path.realpath('../../'))
 
27
 
 
28
def tearDownModule():
 
29
    global oldcwd
 
30
    if oldcwd:
 
31
        os.chdir(oldcwd)
 
32
        oldcwd = None
 
33
 
 
34
class TestCache(unittest.TestCase):
 
35
 
 
36
    def testCacheInRam(self):
 
37
 
 
38
        # defaults to mode='http'
 
39
 
 
40
        cache = CacheInRam()
 
41
        self.assertEqual(cache('a', lambda: 1, 0), 1)
 
42
        self.assertEqual(cache('a', lambda: 2, 100), 1)
 
43
        cache.clear('b')
 
44
        self.assertEqual(cache('a', lambda: 2, 100), 1)
 
45
        cache.clear('a')
 
46
        self.assertEqual(cache('a', lambda: 2, 100), 2)
 
47
        cache.clear()
 
48
        self.assertEqual(cache('a', lambda: 3, 100), 3)
 
49
        self.assertEqual(cache('a', lambda: 4, 0), 4)
 
50
 
 
51
    def testCacheOnDisk(self):
 
52
 
 
53
        # defaults to mode='http'
 
54
 
 
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)
 
60
        cache.clear('b')
 
61
        self.assertEqual(cache('a', lambda: 2, 100), 1)
 
62
        cache.clear('a')
 
63
        self.assertEqual(cache('a', lambda: 2, 100), 2)
 
64
        cache.clear()
 
65
        self.assertEqual(cache('a', lambda: 3, 100), 3)
 
66
        self.assertEqual(cache('a', lambda: 4, 0), 4)
 
67
 
 
68
 
 
69
if __name__ == '__main__':
 
70
    setUpModule()       # pre-python-2.7
 
71
    unittest.main()
 
72
    tearDownModule()