Ejemplo n.º 1
0
def test_mixed():
    channel = IOChannel()
    channel.write("1")
    output = channel.read()
    assert output == "1"
    channel.write("2")
    output = channel.read()
    assert output == "12"
Ejemplo n.º 2
0
def test_multiple_read():
    channel = IOChannel()
    channel.write("1")
    output = channel.read()
    assert output == "1"

    output = channel.read()
    assert output == "1"
Ejemplo n.º 3
0
def test_correct_directory():
    command = Pwd()
    command.set_args(["pwd"])
    output = IOChannel()
    command.set_output_channel(output)
    command.execute()

    assert output.read() == os.getcwd() + '\n'
Ejemplo n.º 4
0
def test_echo_empty():
    command = Echo()
    output = IOChannel()
    command.set_args(["echo"])
    command.set_output_channel(output)
    command.execute()

    expected = "\n"
    assert output.read() == expected
Ejemplo n.º 5
0
def test_echo_several():
    command = Echo()
    output = IOChannel()
    command.set_args(["echo", "my", "input"])
    command.set_output_channel(output)
    command.execute()

    expected = "my input\n"
    assert output.read() == expected
Ejemplo n.º 6
0
def test_wc_from_argument():
    command = Wc()
    output = IOChannel()
    command.set_args(["wc", "Bash-CLI/src/tests/data/example.txt"])
    command.set_output_channel(output)
    command.execute()

    expected = "3 4 21\n"
    assert output.read() == expected
Ejemplo n.º 7
0
def test_external_to_channel():
    command = CallExternal()
    command.set_args(["git", "--help"])
    output = IOChannel()
    command.set_output_channel(output)
    command.execute()

    actual = output.read()
    assert actual[:5] == "usage"
Ejemplo n.º 8
0
def test_cat_from_argument():
    command = Cat()
    output = IOChannel()
    command.set_args(["cat", "Bash-CLI/src/tests/data/example.txt"])
    command.set_output_channel(output)
    command.execute()

    expected = "first line\nsecond\n123"
    assert output.read() == expected
Ejemplo n.º 9
0
def test_external_with_no_args():
    command = CallExternal()
    command.set_args(["sort"])
    output = IOChannel()
    command.set_output_channel(output)
    command.execute()

    expected = ""
    assert output.read() == expected
Ejemplo n.º 10
0
def test_external_with_many_args():
    command = CallExternal()
    command.set_args(["echo", "1", "2", "3"])
    output = IOChannel()
    command.set_output_channel(output)
    command.execute()

    expected = "1 2 3\n"
    assert output.read() == expected
Ejemplo n.º 11
0
def test_pipe_single_command():
    pipe = Pipe()
    command = Echo()
    command.set_args(["echo", "1"])
    output = IOChannel()
    command.set_output_channel(output)
    pipe.append(command)

    pipe.execute()
    assert output.read() == "1\n"
Ejemplo n.º 12
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
Ejemplo n.º 13
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
Ejemplo n.º 14
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
Ejemplo n.º 15
0
def test_pwd_not_read_from_pipe():
    pipe = Pipe()
    first_command = Echo()
    first_command.set_args(["echo", "1"])
    pipe.append(first_command)

    second_command = Pwd()
    second_command.set_args(["pwd"])
    output = IOChannel()
    second_command.set_output_channel(output)
    pipe.append(second_command)

    pipe.execute()
    assert output.read() == os.getcwd() + '\n'
Ejemplo n.º 16
0
def test_pwd_to_pipe():
    pipe = Pipe()
    first_command = Pwd()
    first_command.set_args(["pwd"])
    pipe.append(first_command)

    second_command = Cat()
    second_command.set_args(["cat"])
    output = IOChannel()
    second_command.set_output_channel(output)
    pipe.append(second_command)

    pipe.execute()
    assert output.read() == os.getcwd() + '\n'
Ejemplo n.º 17
0
def test_cat_pass_to_pipe():
    pipe = Pipe()
    first_command = Cat()
    first_command.set_args(["cat", "Bash-CLI/src/tests/data/numbers.txt"])
    pipe.append(first_command)

    second_command = Cat()
    second_command.set_args(["cat"])
    output = IOChannel()
    second_command.set_output_channel(output)
    pipe.append(second_command)

    pipe.execute()
    assert output.read() == '3\n2\n1'
Ejemplo n.º 18
0
def test_echo_not_read_arguments():
    pipe = Pipe()
    first_command = Cat()
    first_command.set_args(["cat", "Bash-CLI/src/tests/data/numbers.txt"])
    pipe.append(first_command)

    second_command = Echo()
    second_command.set_args(["echo"])
    output = IOChannel()
    second_command.set_output_channel(output)
    pipe.append(second_command)

    pipe.execute()
    assert output.read() == '\n'
Ejemplo n.º 19
0
def test_echo_pass_arguments():
    pipe = Pipe()
    first_command = Echo()
    first_command.set_args(["echo", "123"])
    pipe.append(first_command)

    second_command = Cat()
    second_command.set_args(["cat"])
    output = IOChannel()
    second_command.set_output_channel(output)
    pipe.append(second_command)

    pipe.execute()
    assert output.read() == "123\n"
Ejemplo n.º 20
0
def test_external_from_pipe():
    pipe = Pipe()
    first_command = Cat()
    first_command.set_args(["cat", "Bash-CLI/src/tests/data/numbers.txt"])
    pipe.append(first_command)

    second_command = CallExternal()
    second_command.set_args(["sort"])
    output = IOChannel()
    second_command.set_output_channel(output)
    pipe.append(second_command)

    pipe.execute()
    assert output.read() == "1\n2\n3\n"
Ejemplo n.º 21
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
Ejemplo n.º 22
0
def test_wc_from_pipe():
    pipe = Pipe()
    first_command = Echo()
    first_command.set_args(["echo", "1", "23"])
    pipe.append(first_command)

    second_command = Wc()
    second_command.set_args(["wc"])
    output = IOChannel()
    second_command.set_output_channel(output)
    pipe.append(second_command)

    pipe.execute()
    assert output.read() == "1 2 5\n"
Ejemplo n.º 23
0
def test_single_io():
    channel = IOChannel()
    channel.write("value")
    output = channel.read()
    assert output == "value"