Skip to content

Commit

Permalink
chore: reverted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chezka109 committed Oct 31, 2024
1 parent eb6ea38 commit ef5cf43
Showing 1 changed file with 59 additions and 58 deletions.
117 changes: 59 additions & 58 deletions gatorgrade/output/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,13 @@ def run_checks(
) -> bool:
"""Run shell and GatorGrader checks and display whether each has passed or failed.
Also, print a list of all failed checks with their diagnostics and a summary message that
shows the overall fraction of passed checks.
Args:
checks: The list of shell and GatorGrader checks to run.
output_limit: The maximum number of lines to display in the output.
report: The details of what the user wants the report to look like.
show_failures: Only show failing checks if True.
check_include: Description of the checks to include.
check_exclude: Description of the checks to exclude.
"""
results = []

# run each of the checks
for check in checks:
result = None
Expand Down Expand Up @@ -379,78 +376,82 @@ def run_checks(
result.print()
results.append(result)
else:
results.append(result) # Only append results but don't print here

# Filter based on show_failures
results.append(result)
# determine if there are failures and then display them
# print failures list if there are failures to print
# and print what ShellCheck command that Gatorgrade ran
if show_failures:
failed_results = list(filter(lambda result: not result.passed, results))
if len(failed_results) > 0:
print("\n-~- FAILURES -~-\n")
for result in failed_results:
result.print(show_diagnostic=True) # Show diagnostics for failures
else:
for result in results: # Print all results if show_failures is False
result.print()
# Check for included and excluded checks
if check_include or check_exclude:
filtered_results = results

if check_include:
filtered_results = [r for r in results if check_include in r.description]

if check_exclude:
filtered_results = [
r for r in filtered_results if check_exclude not in r.description
]

if len(filtered_results) > 0:
print("\n-~- INCLUDED / EXCLUDED CHECKS -~-\n")
for result in filtered_results:
if not result.passed:
result.print(
show_diagnostic=True
) # Show diagnostics for failing included/excluded checks
else:
result.print() # Print normally for passing checks

# main.console.print("This is a result")
# main.console.print(result)
result.print(show_diagnostic=True)
# this result is an instance of CheckResult
# that has a run_command field that is some
# value that is not the default of an empty
# string and thus it should be displayed;
# the idea is that displaying this run_command
# will give the person using Gatorgrade a way
# to quickly run the command that failed
if result.run_command != "":
rich.print(
f"[blue] → Run this command: [green]{result.run_command}\n"
)
else:
for result in results: # Print all results if show_failures is False
result.print()
# Check for included and excluded checks
if check_include or check_exclude:
filtered_results = results

if check_include:
filtered_results = [
r for r in results if check_include in r.description
]

if check_exclude:
filtered_results = [
r for r in filtered_results if check_exclude not in r.description
]

if len(filtered_results) > 0:
print("\n-~- INCLUDED / EXCLUDED CHECKS -~-\n")
for result in filtered_results:
if not result.passed:
result.print(
show_diagnostic=True
) # Show diagnostics for failing included/excluded checks
else:
result.print() # Print normally for passing checks
# Append results (from the other branch)
results.append(result)

# Determine if there are failures and then display them
failed_results = list(filter(lambda result: not result.passed, results))

# Print failures list if there are failures to print
# and print what ShellCheck command that Gatorgrade ran
if len(failed_results) > 0:
print("\n-~- FAILURES -~-\n")
for result in failed_results:
result.print(show_diagnostic=True)
if result.run_command != "":
rich.print(
f"[blue] → Run this command: [green]{result.run_command}\n"
)

# Summary logic (passing checks percentage calculation can be added here)

# determine how many of the checks passed and then
# compute the total percentage of checks passed
passed_count = len(results) - len(failed_results)

# prevent division by zero if no results
if len(results) == 0:
percent = 0
else:
percent = round(passed_count / len(results) * 100)
# if the report is wanted, create output in line with their specifications
if all(report):
report_output_data = create_report_json(passed_count, results, percent)
configure_report(report, report_output_data, output_limit)
configure_report(report, report_output_data)
# compute summary results and display them in the console
summary = f"Passed {passed_count}/{len(results)} ({percent}%) of checks for {Path.cwd().name}!"
summary_color = "green" if passed_count == len(results) else "bright white"

# Print summary only if not showing failures
if not show_failures:
print_with_border(summary, summary_color)
rich.print(f"[{summary_color}]{summary}[/{summary_color}]")

return len(failed_results) == 0
print_with_border(summary, summary_color)
# determine whether or not the run was a success or not:
# if all of the tests pass then the function returns True;
# otherwise the function must return False
summary_status = True if passed_count == len(results) else False
return summary_status


def print_with_border(text: str, rich_color: str):
Expand Down

0 comments on commit ef5cf43

Please sign in to comment.