Beispiel #1
0
    def run(self):
        report = Report(ReportScreen())

        if self._configuration_path is not None:
            print("Configuration read from %s\n" % self._configuration_path)

        remaining_test_case_files = find_test_case_files(self._test_cases_path, self._test_suffix)
        processes = set()
        while remaining_test_case_files or processes:
            if remaining_test_case_files and len(processes) < self._max_concurrency:
                test_case_file_path = remaining_test_case_files.pop()

                command = [self._phpunit_bin]
                if self._configuration_path:
                    command += ['-c', self._configuration_path]
                command.append(test_case_file_path)

                process = subprocess.Popen(command, stdout=subprocess.PIPE)
                process.test_case = test_case_file_path
                processes.add(process)

            finished_processes = []
            for process in processes:
                if process.poll() is not None:
                    finished_processes.append(process)
                    output = process.stdout.read()
                    output_data = output.split('\n')[4:]
                    if output_data:
                        test_case_dots = output_data[0]

                        uncolored_dots = self.ANSI_ESCAPE.sub('', test_case_dots)
                        for dot_type in uncolored_dots:
                            if dot_type == '.':
                                report.add_passed()
                            if dot_type == 'F':
                                report.add_failure()
                            elif dot_type == 'S':
                                report.add_skipped()
                            elif dot_type == 'I':
                                report.add_incomplete()
                            elif dot_type == 'E':
                                report.add_error()

                        if process.returncode != 0:
                            errors_info = output_data[4:-3]
                            report.add_test_failed_details(process.test_case, errors_info)
                    else:
                        report.add_failure()
                        report.add_test_failed_details(process.test_case, [output])

            processes.difference_update(finished_processes)

        report.display_result()

        return not report.has_failed_tests()
class ReportTestCase(OutputTestCase):
    def setUp(self):
        report_screen = Mock()
        self._report = Report(report_screen)

    def test_passed(self):
        expected_output = "Time: 0 seconds\n\nPassed: 1 / 1"
        self._report.add_passed()
        with self.assertOutput(expected_output):
            self._report.display_result()

    def test_failures(self):
        expected_output = "Time: 0 seconds\n\nFails: 1 / 1"
        self._report.add_failure()
        with self.assertOutput(expected_output):
            self._report.display_result()

    def test_skipped(self):
        expected_output = "Time: 0 seconds\n\nSkipped: 1 / 1"
        self._report.add_skipped()
        with self.assertOutput(expected_output):
            self._report.display_result()

    def test_incomplete(self):
        expected_output = "Time: 0 seconds\n\nIncomplete: 1 / 1"
        self._report.add_incomplete()
        with self.assertOutput(expected_output):
            self._report.display_result()

    def test_error(self):
        expected_output = "Time: 0 seconds\n\nErrors: 1 / 1"
        self._report.add_error()
        with self.assertOutput(expected_output):
            self._report.display_result()

    def test_add_failed_details(self):
        self._report.add_failure()
        expected_file_path = '/tmp/foo/BarTest.php'
        expected_lines = ['foo', 'bar', 'hello', 'world']
        self._report.add_test_failed_details(expected_file_path, expected_lines)
        expected_output = "Time: 0 seconds\n\nFails: 1 / 1\n" \
                          "\n---------------------------------------------------------------\n\n"
        expected_output = "%s\033[41m%s\033[m\n%s" % (expected_output, expected_file_path, "\n".join(expected_lines))
        with self.assertOutput(expected_output):
            self._report.display_result()