Пример #1
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'
Пример #2
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
Пример #3
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"
Пример #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
Пример #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
Пример #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
Пример #7
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
Пример #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
Пример #9
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"
Пример #10
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'
Пример #11
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'
Пример #12
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'
Пример #13
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"
Пример #14
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'
Пример #15
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"
Пример #16
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"
Пример #17
0
def test_mixed():
    channel = IOChannel()
    channel.write("1")
    output = channel.read()
    assert output == "1"
    channel.write("2")
    output = channel.read()
    assert output == "12"
Пример #18
0
def test_multiple_write():
    channel = IOChannel()
    channel.write("1")
    channel.write("2")
    channel.write("3")
    output = channel.read()
    assert output == "123"
Пример #19
0
    def append(self, command):
        """
        Appends a command to the end of the pipe.
        Connects it with a previous one (if exists) with a new channel.
        """
        if self._commands:
            channel_from_last = IOChannel()
            command.set_input_channel(channel_from_last)
            self._commands[-1].set_output_channel(channel_from_last)

        self._commands.append(command)
Пример #20
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
Пример #21
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
Пример #22
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
Пример #23
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
Пример #24
0
def test_single_io():
    channel = IOChannel()
    channel.write("value")
    output = channel.read()
    assert output == "value"