コード例 #1
0
ファイル: test_trees.py プロジェクト: robopsi/zeus
def test_build_tree():
    test_names = [
        "foo.bar.bar", "foo.bar.biz", "foo.biz", "blah.brah", "blah.blah.blah"
    ]

    result = build_tree(test_names, min_children=2)

    assert sorted(result) == ["blah", "foo"]

    result = build_tree(test_names, min_children=2, parent="foo")

    assert sorted(result) == ["foo.bar", "foo.biz"]

    result = build_tree(test_names, min_children=2, parent="foo.biz")

    assert result == set()
コード例 #2
0
ファイル: test_trees.py プロジェクト: sfermigier/zeus
def test_build_tree():
    test_names = [
        'foo.bar.bar',
        'foo.bar.biz',
        'foo.biz',
        'blah.brah',
        'blah.blah.blah',
    ]

    result = build_tree(test_names, min_children=2)

    assert sorted(result) == ['blah', 'foo']

    result = build_tree(test_names, min_children=2, parent='foo')

    assert sorted(result) == ['foo.bar', 'foo.biz']

    result = build_tree(test_names, min_children=2, parent='foo.biz')

    assert result == set()
コード例 #3
0
    def get(self, repo: Repository):
        """
        Return a tree of testcases for the given repository.
        """
        parent = request.args.get('parent')

        latest_build = Build.query.join(
            Source,
            Source.id == Build.source_id,
        ).filter(
            Source.patch_id == None,  # NOQA
            Build.repository_id == repo.id,
            Build.result == Result.passed,
            Build.status == Status.finished,
        ).order_by(Build.date_created.desc(), ).first()

        if not latest_build:
            current_app.logger.info(
                'no successful builds found for repository')
            return self.respond({'groups': [], 'trail': []})

        job_list = db.session.query(Job.id).filter(
            Job.build_id == latest_build.id, )

        # use the most completed build to fetch test results
        test_list = db.session.query(TestCase.name, TestCase.duration).filter(
            TestCase.job_id.in_(job_list), )
        if parent:
            test_list = test_list.filter(TestCase.name.startswith(parent), )
        test_list = list(test_list)

        if test_list:
            sep = TestCase(name=test_list[0][0]).sep

            groups = build_tree(
                [t[0] for t in test_list],
                sep=sep,
                min_children=2,
                parent=parent,
            )

            results = []
            for group in groups:
                num_tests = 0
                total_duration = 0
                for name, duration in test_list:
                    if name == group or name.startswith(group + sep):
                        num_tests += 1
                        total_duration += duration

                if parent:
                    name = group[len(parent) + len(sep):]
                else:
                    name = group
                data = {
                    'name': name,
                    'path': group,
                    'totalDuration': total_duration,
                    'numTests': num_tests,
                }
                results.append(data)
            results.sort(key=lambda x: x['totalDuration'], reverse=True)

            trail = []
            context = []
            if parent:
                for chunk in parent.split(sep):
                    context.append(chunk)
                    trail.append({
                        'path': sep.join(context),
                        'name': chunk,
                    })
        else:
            results = []
            trail = []

        return {
            'entries': results,
            'trail': trail,
        }
コード例 #4
0
    def get(self, revision: Revision):
        """
        Return a tree of file coverage for the given revision.
        """
        build = fetch_build_for_revision(revision)
        if not build:
            return self.respond(status=404)

        parent = request.args.get("parent")

        build_ids = [original.id for original in build.original]

        query = FileCoverage.query.filter(
            FileCoverage.build_id.in_(build_ids)
        ).order_by(FileCoverage.filename.asc())

        if parent:
            query = query.filter(FileCoverage.filename.startswith(parent))

        coverage_list = list(query)

        is_leaf = all(c.filename == parent for c in coverage_list)

        if is_leaf:
            response = self._get_leaf(revision, coverage_list)
        elif coverage_list:
            groups = build_tree(
                list(set([f.filename for f in coverage_list])),
                sep=SEPERATOR,
                min_children=2,
                parent=parent,
            )

            results = []
            for group in groups:
                lines_covered, lines_uncovered = 0, 0
                diff_lines_covered, diff_lines_uncovered = 0, 0
                is_leaf = len(coverage_list) == 1 and coverage_list[0].filename == group
                for coverage in coverage_list:
                    if coverage.filename == group or coverage.filename.startswith(
                        group + SEPERATOR
                    ):
                        lines_covered += coverage.lines_covered
                        lines_uncovered += coverage.lines_uncovered
                        diff_lines_covered += coverage.diff_lines_covered
                        diff_lines_uncovered += coverage.diff_lines_uncovered

                if parent:
                    name = group[len(parent) + len(SEPERATOR) :]
                else:
                    name = group
                data = {
                    "name": name,
                    "path": group,
                    "lines_covered": lines_covered,
                    "lines_uncovered": lines_uncovered,
                    "diff_lines_covered": diff_lines_covered,
                    "diff_lines_uncovered": diff_lines_uncovered,
                    "is_leaf": is_leaf,
                }
                results.append(data)

            results.sort(key=lambda x: x["name"])
            response = {"is_leaf": False, "entries": results}
        else:
            response = {"is_leaf": False, "entries": []}

        trail = []
        context = []
        if parent:
            for chunk in parent.split(SEPERATOR):
                context.append(chunk)
                trail.append({"path": SEPERATOR.join(context), "name": chunk})

        response.update({"trail": trail})
        return response
コード例 #5
0
    def get(self, build: Build):
        """
        Return a tree of coverage for the given build.
        """
        parent = request.args.get('parent')

        query = FileCoverage.query.filter(
            FileCoverage.build_id == build.id,
        ).order_by(
            FileCoverage.filename.asc()
        )
        if parent:
            query = query.filter(
                FileCoverage.filename.startswith(parent),
            )

        coverage_list = list(query)

        is_leaf = len(
            coverage_list) == 1 and coverage_list[0].filename == parent

        if is_leaf:
            response = self._get_leaf(build, coverage_list[0])
        elif coverage_list:
            groups = build_tree(
                [f.filename for f in coverage_list],
                sep=SEPERATOR,
                min_children=2,
                parent=parent,
            )

            results = []
            for group in groups:
                lines_covered, lines_uncovered = 0, 0
                is_leaf = len(
                    coverage_list) == 1 and coverage_list[0].filename == group
                for coverage in coverage_list:
                    if coverage.filename == group or coverage.filename.startswith(
                            group + SEPERATOR):
                        lines_covered += coverage.lines_covered
                        lines_uncovered += coverage.lines_uncovered

                if parent:
                    name = group[len(parent) + len(SEPERATOR):]
                else:
                    name = group
                data = {
                    'name': name,
                    'path': group,
                    'lines_covered': lines_covered,
                    'lines_uncovered': lines_uncovered,
                    'is_leaf': is_leaf
                }
                results.append(data)

            results.sort(key=lambda x: x['name'])
            response = {
                'is_leaf': False,
                'entries': results,
            }
        else:
            response = {
                'is_leaf': False,
                'entries': [],
            }

        trail = []
        context = []
        if parent:
            for chunk in parent.split(SEPERATOR):
                context.append(chunk)
                trail.append({
                    'path': SEPERATOR.join(context),
                    'name': chunk,
                })

        response.update({
            'trail': trail,
        })
        return response
コード例 #6
0
    def get(self, build: Build):
        """
        Return a tree of coverage for the given build.
        """
        parent = request.args.get("parent")

        query = FileCoverage.query.filter(
            FileCoverage.build_id == build.id).order_by(
                FileCoverage.filename.asc())
        if parent:
            query = query.filter(FileCoverage.filename.startswith(parent))

        coverage_list = list(query)

        is_leaf = len(
            coverage_list) == 1 and coverage_list[0].filename == parent

        if is_leaf:
            response = self._get_leaf(build, coverage_list[0])
        elif coverage_list:
            groups = build_tree(
                [f.filename for f in coverage_list],
                sep=SEPERATOR,
                min_children=2,
                parent=parent,
            )

            results = []
            for group in groups:
                lines_covered, lines_uncovered = 0, 0
                is_leaf = len(
                    coverage_list) == 1 and coverage_list[0].filename == group
                for coverage in coverage_list:
                    if (coverage.filename == group or
                            coverage.filename.startswith(group + SEPERATOR)):
                        lines_covered += coverage.lines_covered
                        lines_uncovered += coverage.lines_uncovered

                if parent:
                    name = group[len(parent) + len(SEPERATOR):]
                else:
                    name = group
                data = {
                    "name": name,
                    "path": group,
                    "lines_covered": lines_covered,
                    "lines_uncovered": lines_uncovered,
                    "is_leaf": is_leaf,
                }
                results.append(data)

            results.sort(key=lambda x: x["name"])
            response = {"is_leaf": False, "entries": results}
        else:
            response = {"is_leaf": False, "entries": []}

        trail = []
        context = []
        if parent:
            for chunk in parent.split(SEPERATOR):
                context.append(chunk)
                trail.append({"path": SEPERATOR.join(context), "name": chunk})

        response.update({"trail": trail})
        return response
コード例 #7
0
    def get(self, repo: Repository):
        """
        Return a tree of testcases for the given repository.
        """
        parent = request.args.get("parent")

        latest_build = (Build.query.filter(
            Build.repository_id == repo.id,
            Build.result == Result.passed,
            Build.status == Status.finished,
        ).order_by(Build.date_created.desc()).first())

        if not latest_build:
            current_app.logger.info(
                "no successful builds found for repository")
            return self.respond({"entries": [], "trail": []})

        job_list = db.session.query(
            Job.id).filter(Job.build_id == latest_build.id)

        # use the most completed build to fetch test results
        test_list = db.session.query(TestCase.name, TestCase.duration).filter(
            TestCase.job_id.in_(job_list))
        if parent:
            test_list = test_list.filter(TestCase.name.startswith(parent))
        test_list = list(test_list)

        if test_list:
            sep = TestCase(name=test_list[0][0]).sep

            groups = build_tree([t[0] for t in test_list],
                                sep=sep,
                                min_children=2,
                                parent=parent)

            results = []
            for group in groups:
                num_tests = 0
                total_duration = 0
                for name, duration in test_list:
                    if name == group or name.startswith(group + sep):
                        num_tests += 1
                        total_duration += duration

                if parent:
                    name = group[len(parent) + len(sep):]
                else:
                    name = group
                data = {
                    "name": name,
                    "path": group,
                    "totalDuration": total_duration,
                    "numTests": num_tests,
                }
                results.append(data)
            results.sort(key=lambda x: x["totalDuration"], reverse=True)

            trail = []
            context = []
            if parent:
                for chunk in parent.split(sep):
                    context.append(chunk)
                    trail.append({"path": sep.join(context), "name": chunk})
        else:
            results = []
            trail = []

        return {
            "build": build_schema.dump(latest_build),
            "entries": results,
            "trail": trail,
        }