Revision b8f45292 test/py/cmdlib/testsupport/cmdlib_testcase.py
b/test/py/cmdlib/testsupport/cmdlib_testcase.py | ||
---|---|---|
220 | 220 |
""" |
221 | 221 |
self.ExecOpCodeExpectException(opcode, errors.OpExecError, expected_regex) |
222 | 222 |
|
223 |
def RunWithLockedLU(self, opcode, test_func): |
|
224 |
"""Takes the given opcode, creates a LU and runs func on it. |
|
225 |
|
|
226 |
The passed LU did already perform locking, but no methods which actually |
|
227 |
require locking are executed on the LU. |
|
228 |
|
|
229 |
@param opcode: the opcode to get the LU for. |
|
230 |
@param test_func: the function to execute with the LU as parameter. |
|
231 |
@return: the result of test_func |
|
232 |
|
|
233 |
""" |
|
234 |
self.glm.AddLocksFromConfig(self.cfg) |
|
235 |
|
|
236 |
return self.mcpu.RunWithLockedLU(opcode, test_func) |
|
237 |
|
|
223 | 238 |
def assertLogContainsMessage(self, expected_msg): |
224 | 239 |
"""Shortcut for L{ProcessorMock.assertLogContainsMessage} |
225 | 240 |
|
... | ... | |
292 | 307 |
state[key] = value |
293 | 308 |
|
294 | 309 |
return opcodes.OpCode.LoadOpCode(state) |
310 |
|
|
311 |
|
|
312 |
# pylint: disable=C0103 |
|
313 |
def withLockedLU(func): |
|
314 |
"""Convenience decorator which runs the decorated method with the LU. |
|
315 |
|
|
316 |
This uses L{CmdlibTestCase.RunWithLockedLU} to run the decorated method. |
|
317 |
For this to work, the opcode to run has to be an instance field named "op", |
|
318 |
"_op", "opcode" or "_opcode". |
|
319 |
|
|
320 |
""" |
|
321 |
def wrapper(*args, **kwargs): |
|
322 |
test = args[0] |
|
323 |
assert isinstance(test, CmdlibTestCase) |
|
324 |
|
|
325 |
op = None |
|
326 |
for attr_name in ["op", "_op", "opcode", "_opcode"]: |
|
327 |
if hasattr(test, attr_name): |
|
328 |
op = getattr(test, attr_name) |
|
329 |
break |
|
330 |
assert op is not None |
|
331 |
|
|
332 |
# pylint: disable=W0142 |
|
333 |
def callWithLU(lu): |
|
334 |
new_args = list(args) |
|
335 |
new_args.append(lu) |
|
336 |
func(*new_args, **kwargs) |
|
337 |
|
|
338 |
return test.RunWithLockedLU(op, callWithLU) |
|
339 |
return wrapper |
Also available in: Unified diff