diff --git a/chasten/main.py b/chasten/main.py index 5049dcdd..23709c4f 100644 --- a/chasten/main.py +++ b/chasten/main.py @@ -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 @@ -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) diff --git a/chasten/util.py b/chasten/util.py index c8dae91a..70e94d64 100644 --- a/chasten/util.py +++ b/chasten/util.py @@ -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) diff --git a/scripts/extract_coverage.py b/scripts/extract_coverage.py index 680c65ca..53d9be36 100644 --- a/scripts/extract_coverage.py +++ b/scripts/extract_coverage.py @@ -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