예제 #1
0
def test_process(mocker, default_job):
    get_coverage = mocker.patch.object(CoverageHandler, 'get_coverage')
    process_diff = mocker.patch.object(CoverageHandler, 'process_diff')

    handler = CoverageHandler(default_job)

    process_diff.return_value = {
        'setup.py': set([1, 2, 3, 4, 5]),
    }

    # now try with some duplicate coverage
    get_coverage.return_value = [
        FileCoverage(
            job_id=default_job.id,
            project_id=default_job.project_id,
            organization_id=default_job.organization_id,
            filename='setup.py',
            data='CUNNNNCCNNNUNNNUUUUUU',
            lines_covered=2,
            lines_uncovered=7,
            diff_lines_covered=2,
            diff_lines_uncovered=7,
        )
    ]

    fp = BytesIO()
    handler.process(fp)
    get_coverage.assert_called_once_with(fp)

    get_coverage.reset_mock()

    get_coverage.return_value = [
        FileCoverage(
            job_id=default_job.id,
            project_id=default_job.project_id,
            organization_id=default_job.organization_id,
            filename='setup.py',
            data='NUUNNNNNNNNUCCNU',
            lines_covered=2,
            lines_uncovered=4,
            diff_lines_covered=2,
            diff_lines_uncovered=4,
        )
    ]

    fp = BytesIO()
    handler.process(fp)
    get_coverage.assert_called_once_with(fp)

    file_cov = list(FileCoverage.query.unrestricted_unsafe().filter(
        FileCoverage.job_id == default_job.id, ))
    assert len(file_cov) == 1
    assert file_cov[0].filename == 'setup.py'
    assert file_cov[0].data == 'CUUNNNCCNNNUCCNUUUUUU'
    assert file_cov[0].lines_covered == 5
    assert file_cov[0].lines_uncovered == 9
    assert file_cov[0].diff_lines_covered == 1
    assert file_cov[0].diff_lines_uncovered == 2
예제 #2
0
def test_process(mocker, default_build, default_job):
    get_coverage = mocker.patch.object(CoverageHandler, "get_coverage")
    process_diff = mocker.patch.object(CoverageHandler, "process_diff")

    handler = CoverageHandler(default_job)

    process_diff.return_value = {"setup.py": set([1, 2, 3, 4, 5])}

    # now try with some duplicate coverage
    get_coverage.return_value = [
        FileCoverage(
            build_id=default_build.id,
            repository_id=default_build.repository_id,
            filename="setup.py",
            data="CUNNNNCCNNNUNNNUUUUUU",
            lines_covered=2,
            lines_uncovered=7,
            diff_lines_covered=2,
            diff_lines_uncovered=7,
        )
    ]

    fp = BytesIO()
    handler.process(fp)
    get_coverage.assert_called_once_with(fp)

    get_coverage.reset_mock()

    get_coverage.return_value = [
        FileCoverage(
            build_id=default_build.id,
            repository_id=default_build.repository_id,
            filename="setup.py",
            data="NUUNNNNNNNNUCCNU",
            lines_covered=2,
            lines_uncovered=4,
            diff_lines_covered=2,
            diff_lines_uncovered=4,
        )
    ]

    fp = BytesIO()
    handler.process(fp)
    get_coverage.assert_called_once_with(fp)

    file_cov = list(FileCoverage.query.unrestricted_unsafe().filter(
        FileCoverage.build_id == default_build.id))
    assert len(file_cov) == 1
    assert file_cov[0].filename == "setup.py"
    assert file_cov[0].data == "CUUNNNCCNNNUCCNUUUUUU"
    assert file_cov[0].lines_covered == 5
    assert file_cov[0].lines_uncovered == 9
    assert file_cov[0].diff_lines_covered == 1
    assert file_cov[0].diff_lines_uncovered == 2
예제 #3
0
    def get_cobertura_coverage(self, root):
        job = self.job

        results = []
        for node in root.iter("class"):
            filename = node.get("filename")
            if not filename:
                self.logger.warn("Unable to determine filename for node: %s", node)
                continue

            file_coverage = []
            for lineset in node.iterchildren("lines"):
                lineno = 0
                for line in lineset.iterchildren("line"):
                    number, hits = int(line.get("number")), int(line.get("hits"))
                    if lineno < number - 1:
                        for lineno in range(lineno, number - 1):
                            file_coverage.append("N")
                    if hits > 0:
                        file_coverage.append("C")
                    else:
                        file_coverage.append("U")
                    lineno = number

            result = FileCoverage(
                build_id=job.build_id,
                repository_id=job.repository_id,
                filename=filename,
                data="".join(file_coverage),
            )
            self.add_file_stats(result)

            results.append(result)

        return results
예제 #4
0
파일: coverage.py 프로젝트: robopsi/zeus
    def get_jacoco_coverage(self, root):
        job = self.job

        results = []
        for package in root.iter("package"):
            package_path = "src/main/java/{}".format(package.get("name"))
            for sourcefile in package.iter("sourcefile"):
                # node name resembles 'com/example/foo/bar/Resource'
                filename = "{filepath}/{filename}".format(
                    filepath=package_path, filename=sourcefile.get("name"))

                file_coverage = []
                lineno = 0
                for line in sourcefile.iterchildren("line"):
                    number, hits = int(line.get("nr")), int(line.get("ci"))
                    if lineno < number - 1:
                        for lineno in range(lineno, number - 1):
                            file_coverage.append("N")
                    if hits > 0:
                        file_coverage.append("C")
                    else:
                        file_coverage.append("U")
                    lineno = number

                result = FileCoverage(
                    build_id=job.build_id,
                    repository_id=job.repository_id,
                    filename=filename,
                    data="".join(file_coverage),
                )
                self.add_file_stats(result)

                results.append(result)

        return results
예제 #5
0
파일: coverage.py 프로젝트: robopsi/zeus
    def get_clover_coverage(self, root):
        job = self.job

        results = []
        for node in root.iter("file"):
            filename = node.get("name")
            if not filename:
                self.logger.warn("Unable to determine filename for node: %s",
                                 node)
                continue

            file_coverage = []
            lineno = 0
            for line in node.iterchildren("line"):
                type_ = line.get("type")
                if type_ == "cond":
                    hits = int(line.get("falsecount")) + int(
                        line.get("truecount"))
                elif type_ in ("method", "stmt"):
                    hits = int(line.get("count"))
                else:
                    raise NotImplementedError(
                        "Unknown line type: {}".format(type_))

                number = int(line.get("num"))
                if lineno < number - 1:
                    for lineno in range(lineno, number - 1):
                        file_coverage.append("N")
                if hits > 0:
                    file_coverage.append("C")
                else:
                    file_coverage.append("U")
                lineno = number

            result = FileCoverage(
                build_id=job.build_id,
                repository_id=job.repository_id,
                filename=filename,
                data="".join(file_coverage),
            )
            self.add_file_stats(result)

            results.append(result)

        return results
예제 #6
0
파일: coverage.py 프로젝트: sfermigier/zeus
    def get_jacoco_coverage(self, root):
        job = self.job

        results = []
        for package in root.iter('package'):
            package_path = 'src/main/java/{}'.format(package.get('name'))
            for sourcefile in package.iter('sourcefile'):
                # node name resembles 'com/example/foo/bar/Resource'
                filename = '{filepath}/{filename}'.format(
                    filepath=package_path,
                    filename=sourcefile.get('name'),
                )

                file_coverage = []
                lineno = 0
                for line in sourcefile.iterchildren('line'):
                    number, hits = int(line.get('nr')), int(line.get('ci'))
                    if lineno < number - 1:
                        for lineno in range(lineno, number - 1):
                            file_coverage.append('N')
                    if hits > 0:
                        file_coverage.append('C')
                    else:
                        file_coverage.append('U')
                    lineno = number

                result = FileCoverage(
                    job_id=job.id,
                    project_id=job.project_id,
                    organization_id=job.organization_id,
                    filename=filename,
                    data=''.join(file_coverage),
                )
                self.add_file_stats(result)

                results.append(result)

        return results
예제 #7
0
파일: coverage.py 프로젝트: sfermigier/zeus
    def get_cobertura_coverage(self, root):
        job = self.job

        results = []
        for node in root.iter('class'):
            filename = node.get('filename')
            if not filename:
                self.logger.warn('Unable to determine filename for node: %s',
                                 node)
                continue

            file_coverage = []
            for lineset in node.iterchildren('lines'):
                lineno = 0
                for line in lineset.iterchildren('line'):
                    number, hits = int(line.get('number')), int(
                        line.get('hits'))
                    if lineno < number - 1:
                        for lineno in range(lineno, number - 1):
                            file_coverage.append('N')
                    if hits > 0:
                        file_coverage.append('C')
                    else:
                        file_coverage.append('U')
                    lineno = number

            result = FileCoverage(
                job_id=job.id,
                project_id=job.project_id,
                organization_id=job.organization_id,
                filename=filename,
                data=''.join(file_coverage),
            )
            self.add_file_stats(result)

            results.append(result)

        return results