Exemplo n.º 1
0
    def __get_health_of_features(self):

        data = []
        for feature, components in self.features.items():
            data.append({"full": 100, "category": feature if feature is not None else "Not Defined",
                         "value": Aggregator.percentage(components["_totals_"]["total"],
                                                        components["_totals_"][TestCategory.SUCCESS])})
        return data
Exemplo n.º 2
0
    def get_data_by_tags(self):

        data = {"_totals_": Aggregator.get_template()}
        for test in self.get_test_objects():
            test_metrics = test.metrics.get_metrics()
            if test.get_tags():
                for tag in test.get_tags():
                    if tag not in data:
                        data.update({tag: Aggregator.get_template()})
                    Aggregator._update_report(data, test_metrics, tag)
            else:
                if None not in data:
                    data.update({None: Aggregator.get_template()})
                Aggregator._update_report(data, test_metrics, None)
        return data
Exemplo n.º 3
0
    def run(self, **kwargs):
        """
        Initiates the execution process that runs tests
        :return: None
        """
        self.__settings = Settings(runner_kwargs=self.__kwargs,
                                   run_kwargs=kwargs)
        initial_start_time = time.time()
        resource_monitor = None
        try:
            if self.__settings.monitor_resources:
                resource_monitor = ResourceMonitor()
                resource_monitor.start()
            self.__processor = ParallelProcessor(self.__settings)

            with suppressed_stdout(self.__settings.quiet):
                while self.__suites:
                    for suite in list(self.__suites):
                        suite_object = Builder.get_execution_roster().get(
                            suite, None)
                        if suite_object is not None:
                            if self.__processor.suite_multithreading(
                            ) and suite_object.is_parallelized():
                                while True:
                                    if self.__processor.suite_qualifies(
                                            suite_object):
                                        time.sleep(
                                            Limiter.get_suite_throttling())
                                        self.__executed_suites.append(
                                            suite_object)
                                        ParallelProcessor.run_suite_in_a_thread(
                                            self.__run_suite, suite_object)
                                        self.__suites.remove(suite)
                                        break
                                    elif suite_object.get_priority() is None:
                                        break
                                    else:
                                        time.sleep(1)
                            else:
                                if not suite_object.is_parallelized():
                                    LogJunkie.debug(
                                        "Cant run suite: {} in parallel with any other suites. Waiting for "
                                        "parallel suites to finish so I can run it by itself."
                                        .format(
                                            suite_object.get_class_object()))
                                    ParallelProcessor.wait_currently_active_suites_to_finish(
                                    )
                                self.__executed_suites.append(suite_object)
                                self.__run_suite(suite_object)
                                self.__suites.remove(suite)
                        else:
                            LogJunkie.warn(
                                "Suite: {} not found! Make sure that your input is correct. "
                                "If it is, make sure the use of Test Junkie's decorators "
                                "is correct.".format(suite))
                            self.__suites.remove(suite)
                    LogJunkie.debug("{} Suite(s) left in queue.".format(
                        len(self.__suites)))
                    time.sleep(0.2)

                ParallelProcessor.wait_currently_active_suites_to_finish()
        finally:
            if self.__settings.monitor_resources:
                resource_monitor.shutdown()

        runtime = time.time() - initial_start_time
        print("========== Test Junkie finished in {:0.2f} seconds ==========".
              format(runtime))
        aggregator = Aggregator(self.get_executed_suites())
        Aggregator.present_console_output(aggregator)
        if self.__settings.html_report:
            reporter = Reporter(
                monitoring_file=resource_monitor.get_file_path()
                if resource_monitor is not None else None,
                runtime=runtime,
                aggregator=aggregator,
                multi_threading_enabled=self.__processor.test_multithreading()
                or self.__processor.suite_multithreading())
            reporter.generate_html_report(self.__settings.html_report)
        XmlReporter.create_xml_report(write_file=self.__settings.xml_report,
                                      suites=self.get_executed_suites())
        if self.__settings.monitor_resources:
            resource_monitor.cleanup()
        return aggregator
Exemplo n.º 4
0
    def print_results(self):

        from test_junkie.cli.cli import CliUtils
        match_found = False
        output = []
        for data_context in CliAudit.__SECTIONS:
            if data_context == self.args.command:
                data = self.aggregated_data["context_by_{context}".format(
                    context=data_context)]
                if data:
                    section = []
                    _sorted_data = sorted(data.items(),
                                          key=lambda x: x[1]["total_tests"])
                    _sorted_data.reverse()
                    _sorted_data = collections.OrderedDict(_sorted_data)
                    for primary_key, context in _sorted_data.items():
                        details = []
                        if data_context == "suites":
                            details.append(
                                "\nSuite: {value} Feature: {feature}".format(
                                    value=CliUtils.format_bold_string(
                                        primary_key),
                                    feature=CliUtils.format_bold_string(
                                        context["feature"])))
                        else:
                            parent = "".join(
                                list(data_context)
                                [:-1]).capitalize()  # exp: features > Feature
                            if primary_key is None:
                                primary_key = CliUtils.format_color_string(
                                    primary_key, "red")
                            else:
                                primary_key = CliUtils.format_bold_string(
                                    primary_key)
                            details.append("\n{parent}: {value}".format(
                                parent=parent, value=primary_key))

                        from test_junkie.metrics import Aggregator
                        details.append(
                            "\t- Tests:\t{total} of {absolute} total tests ({percentage}%)"
                            .format(total=context["total_tests"],
                                    absolute=self.
                                    aggregated_data["absolute_test_count"],
                                    percentage=Aggregator.percentage(
                                        self.
                                        aggregated_data["absolute_test_count"],
                                        context["total_tests"])))

                        for i in CliAudit.__SECTIONS:
                            if i in context:
                                msg = "\t"
                                counter = 0
                                _sorted_context = sorted(context[i].items(),
                                                         key=lambda x: x[1])
                                _sorted_context.reverse()
                                _sorted_context = collections.OrderedDict(
                                    _sorted_context)
                                for key, count in _sorted_context.items():
                                    if counter > 0:
                                        msg += "\n\t\t\t"
                                    if key is None:
                                        key = CliUtils.format_color_string(
                                            key, "red")
                                    msg += "{} ({})".format(key, count)
                                    counter += 1
                                if len(msg) > 0:
                                    details.append("\t- {i}: {msg}".format(
                                        i=i.capitalize(), msg=msg))
                        if len(details) >= 5:
                            section += details
                    if len(section) > 1:
                        output.append(section)
                    break

        for section in output:
            if len(section) >= 5:
                match_found = True
                for msg in section:
                    print(msg)

        if not match_found:
            print("[{status}] Nothing matches your search criteria!".format(
                status=CliUtils.format_color_string("INFO", "blue")))