Skip to content

Commit

Permalink
Merge pull request #104 from AstuteSource/93-addtotalcheck
Browse files Browse the repository at this point in the history
feat: Add total count for checks
  • Loading branch information
laurennevill authored Nov 8, 2023
2 parents 88f36f3 + 67a4611 commit 90c4f81
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
10 changes: 9 additions & 1 deletion chasten/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,14 @@ def analyze( # noqa: PLR0912, PLR0913, PLR0915
) # type: ignore
# add the current source to main object that contains a list of source
chasten_results_save.sources.append(current_result_source)
# add the amount of total matches in each check to the end of each checks output
output.console.print(f" = {len(match_generator_list)} total matches\n")
# calculate the final count of matches found
total_result = util.total_amount_passed(chasten_results_save, len(check_list))
# display checks passed, total amount of checks, and percentage of checks passed
output.console.print(
f":computer: {total_result[0]} / {total_result[1]} checks passed ({total_result[2]}%)\n"
)
# display all of the analysis results if verbose output is requested
output.print_analysis_details(chasten_results_save, verbose=verbose)
# save all of the results from this analysis
Expand All @@ -743,7 +751,7 @@ def analyze( # noqa: PLR0912, PLR0913, PLR0915
)
# output the name of the saved file if saving successfully took place
if saved_file_name:
output.console.print(f"\n:sparkles: Saved the file '{saved_file_name}'")
output.console.print(f":sparkles: Saved the file '{saved_file_name}'")
# confirm whether or not all of the checks passed
# and then display the appropriate diagnostic message
all_checks_passed = all(check_status_list)
Expand Down
14 changes: 14 additions & 0 deletions chasten/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@ def get_chasten_version() -> str:
def join_and_preserve(data, start, end):
"""Join and preserve lines inside of a list."""
return constants.markers.Newline.join(data[start:end])


def total_amount_passed(analyze_result, count_total) -> tuple[int, int, float]:
"""Calculate amount of checks passed in analyze"""
try:
# iterate through check sources to find checks passed
list_passed = [x.check.passed for x in analyze_result.sources]
# set variables to count true checks and total counts
count_true = list_passed.count(True)
# return tuple of checks passed, total checks, percentage of checks passed
return (count_true, count_total, (count_true / count_total) * 100)
# return exception when dividing by zero
except ZeroDivisionError:
return (0, 0, 0.0)
2 changes: 1 addition & 1 deletion scripts/extract_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
filename = "chasten/util.py"
covered_lines = set(data.lines(filename)) # type: ignore

print(f"Covered lines in {filename}:") # noqa
print(f"Covered lines in {filename}:") # noqa
print(covered_lines) # noqa

0 comments on commit 90c4f81

Please sign in to comment.