def test_Command_execute(Popen, out): """ Test the Command.execute method """ from paradrop.backend.pdconfd.config.command import Command proc = MagicMock() proc.stdout = ["output"] proc.stderr = ["error"] Popen.return_value = proc command = Command(["callme"]) command.parent = MagicMock() command.execute() assert out.verbose.called_once_with("callme: output") assert out.verbose.called_once_with("callme: error") assert command.parent.executed.append.called Popen.side_effect = Exception("Boom!") command.execute() assert out.info.called
def test_command(): """ Test command execution The true and false commands should reliably succeed and fail in most Linux environments. """ cmd = ["true"] command = Command(cmd) command.execute() assert command.success() # Specifying the command as a string instead of a list. cmd = "true" command = Command(cmd) command.execute() assert command.success() cmd = ["false"] command = Command(cmd) command.execute() assert not command.success()