Example #1
0
def test_get_overall_coverage(mock_covdir_report):
    """
    Test covdir report overall coverage extraction
    """
    from code_coverage_backend import covdir

    report = covdir.open_report(mock_covdir_report)
    assert report is not None
    out = covdir.get_overall_coverage(report, max_depth=1)
    assert out == {
        "": 85.11,
        "builtin": 84.4,
        "ctypes": 80.83,
        "frontend": 78.51,
        "perf": 65.45,
        "shell": 69.95,
        "threading": 90.54,
        "util": 73.29,
    }

    report = covdir.open_report(mock_covdir_report)
    assert report is not None
    out = covdir.get_overall_coverage(report, max_depth=2)
    assert out == {
        "": 85.11,
        "builtin": 84.4,
        "builtin/intl": 78.62,
        "ctypes": 80.83,
        "ctypes/libffi": 49.59,
        "frontend": 78.51,
        "perf": 65.45,
        "shell": 69.95,
        "threading": 90.54,
        "util": 73.29,
    }
Example #2
0
    def ingest_report(self, repository, push_id, changeset, date):
        """
        When a report exist for a changeset, download it and update redis data
        """
        assert isinstance(push_id, int)
        assert isinstance(date, int)

        # Download the report
        report_path = self.download_report(repository, changeset)
        if not report_path:
            return False

        # Read overall coverage for history
        key = KEY_OVERALL_COVERAGE.format(repository=repository,
                                          changeset=changeset)
        report = covdir.open_report(report_path)
        assert report is not None, "No report to ingest"
        overall_coverage = covdir.get_overall_coverage(report)
        assert len(overall_coverage) > 0, "No overall coverage"
        self.redis.hmset(key, overall_coverage)

        # Add the changeset to the sorted sets of known reports
        # The numeric push_id is used as a score to keep the ingested
        # changesets ordered
        self.redis.zadd(KEY_REPORTS.format(repository=repository),
                        {changeset: push_id})

        # Add the changeset to the sorted sets of known reports by date
        self.redis.zadd(KEY_HISTORY.format(repository=repository),
                        {changeset: date})

        logger.info("Ingested report", changeset=changeset)
        return True
Example #3
0
    def ingest_report(self, report):
        """
        When a report exist for a changeset, download it and update redis data
        """
        assert isinstance(report, Report)

        # Download the report
        if not self.download_report(report):
            logger.info("Report not available", report=str(report))
            return False

        # Read overall coverage for history
        data = covdir.open_report(report.path)
        assert data is not None, "No report to ingest"
        overall_coverage = covdir.get_overall_coverage(data)
        assert len(overall_coverage) > 0, "No overall coverage"
        self.redis.hmset(report.key_overall, overall_coverage)

        # Apply expiry for overall report
        if report.ttl is not None:
            self.redis.expire(report.key_overall, report.ttl)

        # Add the changeset to the sorted sets of known reports
        # The numeric push_id is used as a score to keep the ingested
        # changesets ordered
        self.redis.zadd(
            KEY_REPORTS.format(
                repository=report.repository,
                platform=report.platform,
                suite=report.suite,
            ),
            {report.changeset: report.push_id},
        )

        # Add the changeset to the sorted sets of known reports by date
        self.redis.zadd(
            KEY_HISTORY.format(repository=report.repository),
            {report.changeset: report.date},
        )

        # Store the filters
        if report.platform != DEFAULT_FILTER:
            self.redis.sadd(KEY_PLATFORMS.format(repository=report.repository),
                            report.platform)
        if report.suite != DEFAULT_FILTER:
            self.redis.sadd(KEY_SUITES.format(repository=report.repository),
                            report.suite)

        logger.info("Ingested report", report=str(report))
        return True