Esempio n. 1
0
    def __str__(self):
        if self.test_number == 0:
            when_error_happened = ' during testing'
        else:
            when_error_happened = f' in test #{self.test_number}'

        result = self.get_type() + when_error_happened

        if self.error_text:
            result += '\n\n' + self.error_text.strip()

        if self.stack_trace:
            result += '\n\n' + self.stack_trace.strip()

        full_log = OutputHandler.get_dynamic_output()
        worth_showing_log = len(
            full_log.strip()) != 0 and full_log.strip() not in result

        arguments = ''

        from hstest.stage_test import StageTest
        test_run = StageTest.curr_test_run

        if test_run is not None:
            tested_programs = test_run.tested_programs
            programs_with_args = [
                p for p in tested_programs if len(p.run_args)
            ]

            for pr in programs_with_args:
                arguments += 'Arguments'
                if len(tested_programs) > 1:
                    arguments += f' for {pr}'
                pr_args = [
                    f'"{arg}"' if ' ' in arg else arg for arg in pr.run_args
                ]
                arguments += f': {" ".join(pr_args)}\n'

            arguments = arguments.strip()

        if worth_showing_log or len(arguments):
            result += '\n\n'
            if worth_showing_log:
                result += "Please find below the output of your program during this failed test.\n"
                if test_run and test_run.input_used:
                    result += "Note that the '>' character indicates the beginning of the input line.\n"
                result += "\n---\n\n"

            if len(arguments):
                result += arguments + '\n\n'

            if worth_showing_log:
                result += full_log

        return result.strip()
Esempio n. 2
0
    def __str__(self):
        if self.test_number == 0:
            when_error_happened = ' during testing'
        elif self.test_number > 0:
            when_error_happened = f' in test #{self.test_number}'
        else:
            when_error_happened = ''

        result = self.get_type() + when_error_happened

        if self.error_text:
            result += '\n\n' + self.error_text.strip()

        if self.stack_trace:
            result += '\n\n' + self.stack_trace.strip()

        full_out = OutputHandler.get_dynamic_output()
        full_err = str_to_stacktrace(OutputHandler.get_err())
        arguments = self.__get_args()

        trimmed_out = self.__trim_lines(full_out)
        trimmed_err = self.__trim_lines(full_err)

        worth_showing_err = len(full_err.strip()) != 0 and full_err.strip() not in result
        worth_showing_out = len(full_out.strip()) != 0 and full_out.strip() not in result
        worth_showing_args = len(arguments.strip()) != 0

        from hstest.stage_test import StageTest
        test_run = StageTest.curr_test_run

        if worth_showing_out or worth_showing_err or worth_showing_args:
            result += '\n\n'
            if worth_showing_out or worth_showing_err:
                result += "Please find below the output of your program during this failed test.\n"
                if test_run and test_run.input_used:
                    result += "Note that the '>' character indicates the beginning of the input line.\n"
                result += "\n---\n\n"

            if worth_showing_args:
                result += arguments + '\n\n'

            if worth_showing_out:
                if worth_showing_err:
                    result += 'stdout:\n'
                result += trimmed_out + '\n\n'

            if worth_showing_err:
                result += "stderr:\n" + trimmed_err

        return result.strip()