4 from breakdancer
import Condition, Effect, Action, Driver
14 def __call__(self, state):
15 return TESTKEY
in state
19 def __call__(self, state):
28 def __call__(self, state):
29 return TESTKEY
not in state
or ExistsAsNumber.__call__(self, state)
33 def __call__(self, state):
34 return TESTKEY
not in state
38 def __call__(self, state):
39 return not bool(state)
47 def __init__(self, v='0'):
50 def __call__(self, state):
51 state[TESTKEY] = self.
v
55 def __call__(self, state):
60 def __call__(self, state):
67 def __call__(self, state):
68 state[TESTKEY] = state[TESTKEY] + self.
suffix
74 def __call__(self, state):
75 state[TESTKEY] = self.
prefix + state[TESTKEY]
81 def __init__(self, by=1):
84 def __call__(self, state):
86 state[TESTKEY] = str(max(0, int(state[TESTKEY]) + self.
by))
119 class Append(Action):
121 preconditions = [ExistsCondition()]
122 effect = AppendEffect()
123 postconditions = [ExistsCondition()]
162 print '#include "suite_stubs.h"'
165 def testName(self, seq):
166 return 'test_' +
'_'.join(a.name
for a
in seq)
169 f =
"static enum test_result %s" % self.
testName(seq)
170 print (
"%s(ENGINE_HANDLE *h,\n%sENGINE_HANDLE_V1 *h1) {"
171 % (f,
" " * (len(f) + 1)))
174 if isinstance(action, Delay):
175 s =
" delay(expiry+1);"
176 elif isinstance(action, Flush):
178 elif isinstance(action, Delete):
181 s =
' %s(h, h1);' % (action.name)
185 print """MEMCACHED_PUBLIC_API
186 engine_test_t* get_tests(void) {
188 static engine_test_t tests[] = {
190 for seq
in sorted(seq):
191 print ' {"%s",\n %s,\n test_setup, teardown, NULL},' % (
192 ', '.join(a.name
for a
in seq),
195 print """ {NULL, NULL, NULL, NULL, NULL}
201 val = state.get(TESTKEY)
203 print ' checkValue(h, h1, "%s");' % val
205 print ' assertNotExists(h, h1);'
206 print " return SUCCESS;"
211 value = state.get(TESTKEY)
213 vs =
' // value is "%s"' % value
215 vs =
' // value is not defined'
218 print " assertHasError();" + vs
220 print " assertHasNoError();" + vs
222 if __name__ ==
'__main__':