def test_command_with_no_user_input(self):
        expected_command = ["cmd", "--arg"]
        command = ReactorCommand(cmd=expected_command)

        self.assertEqual(
            expected_command,
            command.resolve(ctx=test_context(mode=Mode.INTERACTIVE)))
Beispiel #2
0
def _execute_command(command: ReactorCommand, ctx: Context):
    logger = ctx.logger
    logger.command_info(command)

    try:
        for line in execute_with_streamed_output(command.resolve(ctx)):
            if not command.silent:
                ctx.logger.command_output(line)

        logger.progress("Command '{}' executed successfully".format(command))
    except subprocess.CalledProcessError as err:
        logger.debug(err)
        if not command.silent:
            logger.failure("Command '{}' returned code {}".format(
                command, err.returncode))
    except FileNotFoundError as err:
        logger.debug(err)
        if not command.silent:
            logger.failure("Failed to execute command '{}' - {}".format(
                command, err))
    def test_command_with_user_input(self, patched_input):
        command = ReactorCommand(cmd=["cmd", UserInput("x", "test: ")])

        self.assertEqual(
            ["cmd", expected_user_input],
            command.resolve(ctx=test_context(mode=Mode.INTERACTIVE)))