253 | 253 |
callback.assert_not_called()
|
254 | 254 |
aggregator.flush()
|
255 | 255 |
callback.assert_called_once_with("morestuff")
|
|
256 |
|
|
257 |
|
|
258 |
def test_return_object_semantics():
|
|
259 |
ro = procrunner.ReturnObject(
|
|
260 |
{
|
|
261 |
"command": mock.sentinel.command,
|
|
262 |
"exitcode": 0,
|
|
263 |
"stdout": mock.sentinel.stdout,
|
|
264 |
"stderr": mock.sentinel.stderr,
|
|
265 |
}
|
|
266 |
)
|
|
267 |
assert ro["command"] == mock.sentinel.command
|
|
268 |
assert ro.args == mock.sentinel.command
|
|
269 |
assert ro["exitcode"] == 0
|
|
270 |
assert ro.returncode == 0
|
|
271 |
assert ro["stdout"] == mock.sentinel.stdout
|
|
272 |
assert ro.stdout == mock.sentinel.stdout
|
|
273 |
assert ro["stderr"] == mock.sentinel.stderr
|
|
274 |
assert ro.stderr == mock.sentinel.stderr
|
|
275 |
|
|
276 |
with pytest.raises(KeyError):
|
|
277 |
ro["unknownkey"]
|
|
278 |
ro.update({"unknownkey": mock.sentinel.key})
|
|
279 |
assert ro["unknownkey"] == mock.sentinel.key
|
|
280 |
|
|
281 |
|
|
282 |
def test_return_object_check_function_passes_on_success():
|
|
283 |
ro = procrunner.ReturnObject(
|
|
284 |
{
|
|
285 |
"command": mock.sentinel.command,
|
|
286 |
"exitcode": 0,
|
|
287 |
"stdout": mock.sentinel.stdout,
|
|
288 |
"stderr": mock.sentinel.stderr,
|
|
289 |
}
|
|
290 |
)
|
|
291 |
ro.check_returncode()
|
|
292 |
|
|
293 |
|
|
294 |
def test_return_object_check_function_raises_on_error():
|
|
295 |
ro = procrunner.ReturnObject(
|
|
296 |
{
|
|
297 |
"command": mock.sentinel.command,
|
|
298 |
"exitcode": 1,
|
|
299 |
"stdout": mock.sentinel.stdout,
|
|
300 |
"stderr": mock.sentinel.stderr,
|
|
301 |
}
|
|
302 |
)
|
|
303 |
with pytest.raises(Exception) as e:
|
|
304 |
ro.check_returncode()
|
|
305 |
assert repr(mock.sentinel.command) in str(e.value)
|
|
306 |
assert "1" in str(e.value)
|