コード例 #1
0
ファイル: tests.py プロジェクト: jhance/changes
    def get_test_stats(cls, project_slug):
        response = api_client.get('/projects/{project}/'.format(
            project=project_slug))
        last_build = response['lastPassingBuild']

        if not last_build:
            # use a failing build if no build has passed yet
            last_build = response['lastBuild']

        if not last_build:
            return {}, 0

        # XXX(dcramer): ideally this would be abstracted via an API
        job_list = db.session.query(Job.id).filter(
            Job.build_id == last_build['id'],
        )

        if job_list:
            test_durations = dict(db.session.query(
                TestCase.name, TestCase.duration
            ).filter(
                TestCase.job_id.in_(job_list),
            ))
        else:
            test_durations = dict()

        test_names = []
        total_count, total_duration = 0, 0
        for test in test_durations:
            test_names.append(test)
            total_duration += test_durations[test]
            total_count += 1

        test_stats = {}
        if test_names:
            sep = TestCase(name=test_names[0]).sep
            tree = build_flat_tree(test_names, sep=sep)
            for group_name, group_tests in tree.iteritems():
                segments = cls._normalize_test_segments(group_name)
                test_stats[segments] = sum(test_durations[t] for t in group_tests)

        # the build report can contain different test suites so this isnt the
        # most accurate
        if total_duration > 0:
            avg_test_time = int(total_duration / total_count)
        else:
            avg_test_time = 0

        return test_stats, avg_test_time
コード例 #2
0
ファイル: tests.py プロジェクト: websiteinspiration/changes
    def get_test_stats(cls, project_slug):
        response = api_client.get(
            '/projects/{project}/'.format(project=project_slug))
        last_build = response['lastPassingBuild']

        if not last_build:
            # use a failing build if no build has passed yet
            last_build = response['lastBuild']

        if not last_build:
            return {}, 0

        # XXX(dcramer): ideally this would be abstracted via an API
        job_list = db.session.query(Job.id).filter(
            Job.build_id == last_build['id'], )

        if job_list:
            test_durations = dict(
                db.session.query(TestCase.name, TestCase.duration).filter(
                    TestCase.job_id.in_(job_list), ))
        else:
            test_durations = dict()

        test_names = []
        total_count, total_duration = 0, 0
        for test in test_durations:
            test_names.append(test)
            total_duration += test_durations[test]
            total_count += 1

        test_stats = {}
        if test_names:
            sep = TestCase(name=test_names[0]).sep
            tree = build_flat_tree(test_names, sep=sep)
            for group_name, group_tests in tree.iteritems():
                segments = cls._normalize_test_segments(group_name)
                test_stats[segments] = sum(test_durations[t]
                                           for t in group_tests)

        # the build report can contain different test suites so this isnt the
        # most accurate
        if total_duration > 0:
            avg_test_time = int(total_duration / total_count)
        else:
            avg_test_time = 0

        return test_stats, avg_test_time