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
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
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
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'
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'
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'
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"
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"
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