forked from limodou/uliweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cache.py
More file actions
161 lines (156 loc) · 3.99 KB
/
test_cache.py
File metadata and controls
161 lines (156 loc) · 3.99 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import time, sys, os
path = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, path)
from uliweb import manage, functions
def teardown():
import shutil
os.chdir('..')
if os.path.exists('TestProject'):
shutil.rmtree('TestProject', ignore_errors=True)
def test_file():
"""
>>> manage.call('uliweb makeproject -y TestProject')
>>> os.chdir('TestProject')
>>> path = os.getcwd()
>>> app = manage.make_simple_application(project_dir=path, include_apps=['uliweb.contrib.cache'])
>>> cache = functions.get_cache()
>>> cache.get('name', None)
>>> def set_name():
... return 'test'
>>> cache.get('name', creator=set_name)
'test'
>>> cache.get('name')
'test'
>>> cache.get('hello', 'default')
'default'
>>> cache['test'] = 'ooo'
>>> cache['test']
'ooo'
>>> del cache['test']
>>> cache.setdefault('a', set_name)
'test'
>>> cache['a']
'test'
>>> cache.inc('count')
1
>>> cache.dec('count')
0
>>> cache.inc('count')
1
>>> cache.get('count')
1
>>> cache.set('count', 2)
True
>>> cache.inc('count', 2)
4
>>> teardown()
"""
def test_redis():
"""
>>> manage.call('uliweb makeproject -y TestProject')
>>> os.chdir('TestProject')
>>> path = os.getcwd()
>>> app = manage.make_simple_application(project_dir=path, include_apps=['uliweb.contrib.cache'])
>>> cache = functions.get_cache(storage_type='redis', options={'connection_pool':{'host':'localhost', 'port':6379}})
>>> cache.get('name', None)
>>> def set_name():
... return 'test'
>>> cache.get('name', creator=set_name)
'test'
>>> cache.get('name')
'test'
>>> cache.get('hello', 'default')
'default'
>>> cache['test'] = 'ooo'
>>> cache['test']
'ooo'
>>> del cache['test']
>>> cache.setdefault('a', set_name)
'test'
>>> cache['a']
'test'
>>> cache.inc('count')
1
>>> cache.dec('count')
0
>>> cache.inc('count')
1
>>> cache.get('count')
1
>>> cache.set('count', 2)
True
>>> cache.inc('count', 2)
4
>>> cache.set('a', 1.0)
True
>>> cache.get('a')
1.0
>>> cache.delete('name')
True
>>> cache.delete('count')
True
>>> cache.delete('a')
True
>>> teardown()
"""
def test_memcache():
"""
>>> manage.call('uliweb makeproject -y TestProject')
>>> os.chdir('TestProject')
>>> path = os.getcwd()
>>> app = manage.make_simple_application(project_dir=path, include_apps=['uliweb.contrib.cache'])
>>> cache = functions.get_cache(storage_type='memcache', options={'connection':['192.168.0.191:11211']})
>>> cache.get('name', None)
>>> def set_name():
... return 'test'
>>> cache.get('name', creator=set_name)
'test'
>>> cache.get('name')
'test'
>>> cache.get('hello', 'default')
'default'
>>> cache['test'] = 'ooo'
>>> cache['test']
'ooo'
>>> del cache['test']
>>> cache.setdefault('a', set_name)
'test'
>>> cache['a']
'test'
>>> cache.inc('count')
1
>>> cache.dec('count')
0
>>> cache.inc('count')
1
>>> cache.get('count')
1
>>> cache.set('count', 2)
True
>>> cache.inc('count', 2)
4
>>> cache.set('a', 1.0)
True
>>> cache.get('a')
1.0
>>> cache.delete('name')
True
>>> cache.delete('count')
True
>>> cache.delete('a')
True
>>> teardown()
"""
# if __name__ == '__main__':
# manage.call('uliweb makeproject -y TestProject')
# os.chdir('TestProject')
# path = os.getcwd()
# app = manage.make_simple_application(project_dir=path, include_apps=['uliweb.contrib.cache'])
# cache = functions.get_cache(storage_type='memcache', options={'connection':['192.168.0.191:11211']})
# print cache.set('b', 2)
# print cache.get('b')
# print cache.get('name', None)
# def set_name():
# return 'test'
# print cache.get('name', creator=set_name)
# print cache.get('name')