Source code for varats.data.reports.szz_report
"""Module for SZZReport."""
import typing as tp
from enum import Enum
from pathlib import Path
import yaml
from varats.base.version_header import VersionHeader
from varats.provider.bug.bug import RawBug
from varats.report.report import BaseReport
from varats.utils.git_util import FullCommitHash
[docs]
class SZZReport(BaseReport, shorthand="SZZ", file_type="yaml"):
"""
Base class for reports created by several SZZ tools.
Subclasses of this report only differ in the tool used and the shorthand.
"""
def __init__(self, path: Path, szz_tool: str):
super().__init__(path)
with open(path, 'r') as stream:
documents = yaml.load_all(stream, Loader=yaml.CLoader)
version_header = VersionHeader(next(documents))
version_header.raise_if_not_type("SZZReport")
version_header.raise_if_version_is_less_than(1)
raw_report = next(documents)
if not raw_report["szz_tool"] == szz_tool:
raise AssertionError(
"Report was not created with the correct tool."
)
self.__bugs: tp.Dict[FullCommitHash, RawBug] = {}
for fix, introducers in raw_report["bugs"].items():
fix_hash = FullCommitHash(fix)
introducer_hashes = {FullCommitHash(c) for c in introducers}
self.__bugs[fix_hash] = RawBug(
fix_hash, introducer_hashes, None
)
[docs]
@classmethod
def shorthand(cls) -> str:
"""Shorthand for this report."""
return cls.SHORTHAND
[docs]
def get_all_raw_bugs(self) -> tp.FrozenSet[RawBug]:
"""
Get the set of all bugs in this report.
Returns:
A set of `RawBug` s.
"""
return frozenset(self.__bugs.values())
[docs]
def get_raw_bug_by_fix(
self, fixing_commit: FullCommitHash
) -> tp.Optional[RawBug]:
"""
Get a bug by the id of the fixing commit.
Returns:
A `RawBug` if avilable, else `None`.
"""
return self.__bugs.get(fixing_commit, None)
[docs]
class SZZUnleashedReport(
SZZReport, shorthand=SZZTool.SZZ_UNLEASHED.shorthand, file_type="yaml"
):
"""SZZReport as generated by the
:class:`~varats.experiments.szz.szz_unleashed.SZZUnleashedExperiment`."""
def __init__(self, path: Path):
super().__init__(path, SZZTool.SZZ_UNLEASHED.tool_name)
[docs]
class PyDrillerSZZReport(
SZZReport, shorthand=SZZTool.PYDRILLER_SZZ.shorthand, file_type="yaml"
):
"""SZZReport as generated by the
:class:`~varats.experiments.szz.pydriller_szz.PyDrillerSZZExperiment`."""
def __init__(self, path: Path):
super().__init__(path, SZZTool.PYDRILLER_SZZ.tool_name)