示例#1
0
def test_multiple_write():
    channel = IOChannel()
    channel.write("1")
    channel.write("2")
    channel.write("3")
    output = channel.read()
    assert output == "123"
示例#2
0
def test_mixed():
    channel = IOChannel()
    channel.write("1")
    output = channel.read()
    assert output == "1"
    channel.write("2")
    output = channel.read()
    assert output == "12"
示例#3
0
def test_external_ignores_stdin():
    command = CallExternal()
    command.set_args(["echo", "1"])
    output = IOChannel()
    input = IOChannel()
    input.write("input")

    command.set_input_channel(input)
    command.set_output_channel(output)
    command.execute()

    expected = "1\n"
    assert output.read() == expected
示例#4
0
def test_external_from_channel():
    command = CallExternal()
    command.set_args(["sort"])
    output = IOChannel()
    input = IOChannel()
    input.write("3\n2\n1\n")

    command.set_input_channel(input)
    command.set_output_channel(output)
    command.execute()

    expected = "1\n2\n3\n"
    assert output.read() == expected
示例#5
0
def test_echo_ignores_input_channel():
    command = Echo()
    input = IOChannel()
    input.write("my input")

    output = IOChannel()

    command.set_args(["echo"])
    command.set_output_channel(output)
    command.set_input_channel(input)
    command.execute()

    expected = "\n"
    assert output.read() == expected
示例#6
0
def test_wc_from_channel():
    command = Wc()
    input = IOChannel()
    input.write("my input")

    output = IOChannel()

    command.set_args(["cat"])
    command.set_output_channel(output)
    command.set_input_channel(input)
    command.execute()

    expected = "1 2 8\n"
    assert output.read() == expected
示例#7
0
def test_single_io():
    channel = IOChannel()
    channel.write("value")
    output = channel.read()
    assert output == "value"