コード例 #1
0
def test_cat_to_stdout(capsys):
    command = Cat()
    command.set_args(["cat", "Bash-CLI/src/tests/data/example.txt"])
    command.execute()

    expected = "first line\nsecond\n123"
    captured = capsys.readouterr()
    assert captured.out == expected
コード例 #2
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
コード例 #3
0
    def create_executable(self, tokenized):
        normalized = [
            token.get_string_with_normalized_quotes()
            for token in tokenized.to_list()
        ]
        self.__check_args(normalized)

        command = Cat()
        command.set_args(normalized)
        return command
コード例 #4
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'
コード例 #5
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'
コード例 #6
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'
コード例 #7
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"
コード例 #8
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"
コード例 #9
0
def test_cat_from_channel():
    command = Cat()
    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 = "my input"
    assert output.read() == expected