def test_print_environment_vars(capsys): env = { "ANSIBLE_FOO": "foo", "ANSIBLE_BAR": "bar", "ANSIBLE": None, "MOLECULE_FOO": "foo", "MOLECULE_BAR": "bar", "MOLECULE": None, } expected = """DEBUG: ANSIBLE ENVIRONMENT: ANSIBLE_BAR: bar ANSIBLE_FOO: foo DEBUG: MOLECULE ENVIRONMENT: MOLECULE_BAR: bar MOLECULE_FOO: foo DEBUG: SHELL REPLAY: ANSIBLE_BAR=bar ANSIBLE_FOO=foo MOLECULE_BAR=bar MOLECULE_FOO=foo """ with console.capture() as capture: util.print_environment_vars(env) result = strip_ansi_escape(capture.get()) assert result == expected
def test_print_matrix(capsys, _instance): with console.capture() as capture: _instance.print_matrix() result = chomp(strip_ansi_escape(capture.get())) matrix_out = """--- default: - dependency - lint - cleanup - destroy - syntax - create - prepare - converge - idempotence - side_effect - verify - cleanup - destroy foo: - dependency - lint - cleanup - destroy - syntax - create - prepare - converge - idempotence - side_effect - verify - cleanup - destroy""" assert matrix_out in result
def _non_idempotent_tasks(self, output): """ Parse the output to identify the non idempotent tasks. :param (str) output: A string containing the output of the ansible run. :return: A list containing the names of the non idempotent tasks. """ # Remove blank lines to make regex matches easier. output = re.sub(r"\n\s*\n*", "\n", output) # Remove ansi escape sequences. output = strip_ansi_escape(output) # Split the output into a list and go through it. output_lines = output.split("\n") res = [] task_line = "" for _, line in enumerate(output_lines): if line.startswith("TASK"): task_line = line elif line.startswith("changed"): host_name = re.search(r"\[(.*)\]", line).groups()[0] task_name = re.search(r"\[(.*)\]", task_line).groups()[0] res.append(u"* [{}] => {}".format(host_name, task_name)) return res
def test_print_debug(): expected = "DEBUG: test_title:\ntest_data\n" with console.capture() as capture: util.print_debug("test_title", "test_data") result = strip_ansi_escape(capture.get()) assert result == expected
def test_strip_ansi_escape(): string = "ls\r\n\x1b[00m\x1b[01;31mfoo\x1b[00m\r\n\x1b[01;31m" assert "ls\r\nfoo\r\n" == strip_ansi_escape(string)