Пример #1
0
    def get_coverage(self, report, path):
        """
        Load a report and its coverage for a specific path
        and build a serializable representation
        """
        assert isinstance(report, Report)
        data = covdir.open_report(report.path)
        if data is None:
            # Try to download the report if it's missing locally
            assert self.download_report(report), "Missing report {}".format(report)

            data = covdir.open_report(report.path)
            assert data

        out = covdir.get_path_coverage(data, path)
        out["changeset"] = report.changeset
        return out
Пример #2
0
    def get_coverage(self, report: Report, path: str) -> dict:
        """
        Load a report and its coverage for a specific path
        and build a serializable representation
        """
        data = covdir.open_report(report.path)
        if data is None:
            # Try to download the report if it's missing locally
            assert download_report(
                self.reports_dir, self.bucket,
                report.name), "Missing report {}".format(report)

            data = covdir.open_report(report.path)
            assert data

        out = covdir.get_path_coverage(data, path)
        out["changeset"] = report.changeset
        return out
Пример #3
0
    def get_coverage(self, repository, changeset, path):
        """
        Load a report and its coverage for a specific path
        and build a serializable representation
        """
        report_path = os.path.join(self.reports_dir,
                                   "{}/{}.json".format(repository, changeset))

        report = covdir.open_report(report_path)
        if report is None:
            # Try to download the report if it's missing locally
            report_path = self.download_report(repository, changeset)
            assert report_path is not False, "Missing report for {} at {}".format(
                repository, changeset)

            report = covdir.open_report(report_path)
            assert report

        out = covdir.get_path_coverage(report, path)
        out["changeset"] = changeset
        return out
Пример #4
0
def test_get_path_coverage(mock_covdir_report):
    """
    Test covdir report parsing to obtain coverage for a specific path
    """
    from code_coverage_backend import covdir

    # Full coverage
    report = covdir.open_report(mock_covdir_report)
    assert report is not None
    out = covdir.get_path_coverage(report, "")
    assert isinstance(out, dict)
    assert out["coveragePercent"] == 85.11
    assert out["linesCovered"] == 267432
    assert out["linesMissed"] == 46779
    assert out["linesTotal"] == 314211
    assert out["name"] == "src"
    assert out["path"] == ""
    assert out["type"] == "directory"
    assert len(out["children"]) == 12
    assert [c["name"] for c in out["children"]] == [
        "builtin",
        "ctypes",
        "frontend",
        "jsapi.cpp",
        "jsdate.cpp",
        "jsexn.cpp",
        "jsexn.h",
        "jsmath.cpp",
        "perf",
        "shell",
        "threading",
        "util",
    ]

    # Subfolder
    report = covdir.open_report(mock_covdir_report)
    assert report is not None
    out = covdir.get_path_coverage(report, "perf")
    assert isinstance(out, dict)
    assert out["coveragePercent"] == 65.45
    assert out["linesCovered"] == 125
    assert out["linesMissed"] == 66
    assert out["linesTotal"] == 191
    assert out["name"] == "perf"
    assert out["path"] == "perf"
    assert out["type"] == "directory"
    assert len(out["children"]) == 2
    assert [c["name"]
            for c in out["children"]] == ["pm_linux.cpp", "pm_stub.cpp"]

    # File
    report = covdir.open_report(mock_covdir_report)
    assert report is not None
    out = covdir.get_path_coverage(report, "perf/pm_linux.cpp")
    assert isinstance(out, dict)
    assert out == {
        "children": None,
        "coverage": [66, 138, 6, -1, -1],
        "coveragePercent": 81.69,
        "linesCovered": 58,
        "linesMissed": 13,
        "linesTotal": 71,
        "name": "pm_linux.cpp",
        "path": "perf/pm_linux.cpp",
        "type": "file",
    }

    # Missing file
    with pytest.raises(Exception) as e:
        report = covdir.open_report(mock_covdir_report)
        assert report is not None
        covdir.get_path_coverage(report, "nope.py")
    assert str(e.value) == "Path nope.py not found in report"