Skip to content

Commit

Permalink
Refactored code and separated directives to create legends.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels committed Jan 28, 2024
1 parent 46edf0e commit 5cf27e6
Show file tree
Hide file tree
Showing 11 changed files with 654 additions and 271 deletions.
17 changes: 13 additions & 4 deletions doc/CodeCov/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,23 @@ Directives
An identifier referencing a dictionary entry in the configuration variable ``report_codecov_packages`` defined in
:file:`conf.py`.
.. rst:directive:option:: legend
Describes if and where to add a legend. Possible values: ``no_legend``, ``top``, ``bottom``, ``both``.
.. rst:directive:option:: no-branch-coverage
If flag is present, no branch coverage columns are shown. Only statement coverage columns are present.
.. rst:directive:: code-coverage-legend
.. rst:directive:option:: style
Specifies the legend style. Default is ``horizontal-table``.
Possible values:
* ``default``
* ``horizontal-table``
* ``vertical-table``
.. _CODECOV/Roles:

Expand Down
14 changes: 13 additions & 1 deletion doc/DocCov/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bar.
Directives
**********

.. rst:directive:: doc-coverage
.. rst:directive:: report:doc-coverage
Add a table summarizing the documentation coverage per Python source code file (packages and/or modules).

Expand All @@ -130,6 +130,18 @@ Directives
Describes if and where to add a legend. Possible values: ``no_legend``, ``top``, ``bottom``, ``both``.
.. rst:directive:: report:doc-coverage-legend
.. rst:directive:option:: style
Specifies the legend style. Default is ``horizontal-table``.
Possible values:
* ``default``
* ``horizontal-table``
* ``vertical-table``
.. _DOCCOV/Roles:

Expand Down
10 changes: 5 additions & 5 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
"name": "sphinx_reports",
"json_report": "../report/coverage/coverage.json",
"fail_below": 80,
"levels": _codeCovLevels
"levels": "default"
}
}

Expand All @@ -295,25 +295,25 @@
"name": "sphinx_reports",
"directory": "../sphinx_reports",
"fail_below": 80,
"levels": _docCovLevels
"levels": "default"
},
"undocumented": {
"name": "MyPackage",
"directory": "../tests/packages/undocumented",
"fail_below": 80,
"levels": _docCovLevels
"levels": "default"
},
"partially": {
"name": "MyPackage",
"directory": "../tests/packages/partially",
"fail_below": 80,
"levels": _docCovLevels
"levels": "default"
},
"documented": {
"name": "MyPackage",
"directory": "../tests/packages/documented",
"fail_below": 80,
"levels": _docCovLevels
"levels": "default"
}
}

Expand Down
25 changes: 24 additions & 1 deletion sphinx_reports/Adapter/Coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"""
from pathlib import Path

from coverage.results import Numbers
from pyTooling.Configuration.JSON import Configuration
from pyTooling.Decorators import export, readonly

Expand All @@ -48,10 +47,24 @@ class CodeCoverageError(ReportExtensionError):

@export
class Analyzer:
"""
An analyzer to read and transform code coverage data from JSON format to a generic data model.
Coverage.py can provide collected statement and branch coverage metrics as JSON data, which can be converted to a
generic code coverage model.
"""

_packageName: str
_coverageReport: Configuration

def __init__(self, packageName: str, jsonCoverageFile: Path) -> None:
"""
Read a JSON file containing code coverage metrics generated by Coverage.py.
:param packageName: Name of the Python package that was analyzed.
:param jsonCoverageFile: JSON file containing statement and/or branch coverage.
:raises CodeCoverageError: If JSON file doesn't exist.
"""
if not jsonCoverageFile.exists():
raise CodeCoverageError(f"JSON coverage report '{jsonCoverageFile}' not found.") from FileNotFoundError(jsonCoverageFile)

Expand All @@ -63,10 +76,20 @@ def __init__(self, packageName: str, jsonCoverageFile: Path) -> None:

@readonly
def PackageName(self) -> str:
"""
Read-only property to access the analyzed package's name.
:return: Name of the analyzed package.
"""
return self._packageName

@readonly
def JSONCoverageFile(self) -> Path:
"""
Read-only property to access the parsed JSON file.
:return: Path to the parsed JSON file.
"""
return self._coverageReport.ConfigFile

@readonly
Expand Down
Loading

0 comments on commit 5cf27e6

Please sign in to comment.