Ejemplo n.º 1
0
def test_run_with_keyboard_interrupt(
        config):  # type: (ApplicationConfig) -> None
    def callback(_, io):
        raise KeyboardInterrupt()

    config.create_command("interrupted").set_handler(CallbackHandler(callback))
    app = ConsoleApplication(config)

    output = BufferedOutputStream()
    error_output = BufferedOutputStream()

    assert 1 == app.run(StringArgs("interrupted"), StringInputStream(""),
                        output, error_output)

    assert "" == output.fetch()
    assert "" == error_output.fetch()
Ejemplo n.º 2
0
def test_run_command(config, arg_string, config_callback):
    def callback(_, io):
        io.write(io.read_line())
        io.error(io.read_line())

        return 123

    config_callback(config, callback)

    args = StringArgs(arg_string)
    input = StringInputStream("line1\nline2")
    output = BufferedOutputStream()
    error_output = BufferedOutputStream()

    app = ConsoleApplication(config)

    assert 123 == app.run(args, input, output, error_output)
    assert "line1\n" == output.fetch()
    assert "line2" == error_output.fetch()