Skip to content

Commit

Permalink
chore(quality): Improve coverage report output. (#102)
Browse files Browse the repository at this point in the history
PR: #102
  • Loading branch information
OmarAlJarrah authored May 2, 2023
1 parent e02e5e6 commit 8218bb8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ flake8-bugbear~=23.3.23
flake8-isort~=6.0.0
flake8-pep585~=0.1.7
furl~=2.1.3
prettytable~=3.7.0
23 changes: 17 additions & 6 deletions validate_test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,43 @@
import math
from textwrap import dedent

from prettytable import PrettyTable

MINIMUM_REQUIRED_COVERAGE_PERCENTAGE: int = 90
FAILURE_MESSAGE_TEMPLATE: str = dedent(
"""
> Coverage Validation Failed!
>> Minimum Required Coverage Percentage: {0}%
>> Current Coverage Percentage: {1}%
>> Minimum Required Total Coverage Percentage: {0}%
>> Current Total Coverage Percentage: {1}%
>>> Full Coverage Report:
{2}
"""
)
SUCCESS_MESSAGE_TEMPLATE: str = dedent(
"""
> Coverage Validation Succeed!
>> Current Coverage Percentage: {0}%
>> Current Total Coverage Percentage: {0}%
>>> Full Coverage Report:
{1}
"""
)


def validate_test_coverage(report: dict):
data: dict = report["totals"]
current_coverage_percentage: int = math.ceil(int(data["percent_covered"]))
current_coverage_percentage: int = int(data["percent_covered_display"])

data["covered_branches_percentage"] = f"{math.ceil(100 * (data['covered_branches'] / data['num_branches']))}%"
full_coverage_report_table = PrettyTable(field_names=["Property", "Value"])

full_coverage_report_table.add_rows([[key, value] for key, value in data.items()])

if current_coverage_percentage < MINIMUM_REQUIRED_COVERAGE_PERCENTAGE:
message: str = FAILURE_MESSAGE_TEMPLATE.format(MINIMUM_REQUIRED_COVERAGE_PERCENTAGE, int(data["percent_covered"]))
message: str = FAILURE_MESSAGE_TEMPLATE.format(MINIMUM_REQUIRED_COVERAGE_PERCENTAGE, data["percent_covered_display"], str(full_coverage_report_table))
raise Exception(message)

else:
print(SUCCESS_MESSAGE_TEMPLATE.format(current_coverage_percentage))
print(SUCCESS_MESSAGE_TEMPLATE.format(current_coverage_percentage, full_coverage_report_table))


with open("coverage.json", "r") as coverage_json_report:
Expand Down

0 comments on commit 8218bb8

Please sign in to comment.