Skip to content

Commit

Permalink
fix: formatting and extra spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
dyga01 committed Nov 22, 2024
1 parent 208874b commit 2747a1f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
10 changes: 8 additions & 2 deletions gatorgrade/input/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

from typing import List


class ShellCheck: # pylint: disable=too-few-public-methods
"""Represent a shell check."""

def __init__(self, command: str, description: str = None, json_info=None, gg_args: List[str] = None): # type: ignore
def __init__(
self,
command: str,
description: str = None,
json_info=None,
gg_args: List[str] = None,
): # type: ignore
"""Construct a ShellCheck.
Args:
Expand All @@ -26,7 +33,6 @@ def __str__(self):
return f"ShellCheck(command={self.command}, description={self.description}, json_info={self.json_info}, gg_args={self.gg_args})"



class GatorGraderCheck: # pylint: disable=too-few-public-methods
"""Represent a GatorGrader check."""

Expand Down
9 changes: 2 additions & 7 deletions gatorgrade/input/command_line_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def generate_checks(
command=check_data.check.get("command"),
description=check_data.check.get("description"),
json_info=check_data.check,
gg_args=shell_gg_args
gg_args=shell_gg_args,
)
)
# Otherwise, it is a GatorGrader check
Expand All @@ -67,11 +67,6 @@ def generate_checks(
description = check_data.check.get("description")
if description:
gg_args.extend(["--description", description])
checks.append(
GatorGraderCheck(
gg_args=gg_args,
json_info=check_data.check
)
)
checks.append(GatorGraderCheck(gg_args=gg_args, json_info=check_data.check))

return checks
6 changes: 4 additions & 2 deletions gatorgrade/output/check_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def __init__(
self.path = path
self.run_command = ""

def display_result(self, show_diagnostic: bool = False, percentage: float = None) -> str:
def display_result(
self, show_diagnostic: bool = False, percentage: float = None
) -> str:
"""Print check's passed or failed status, description, and, optionally, diagnostic message.
If no diagnostic message is available, then the output will say so.
Expand All @@ -47,7 +49,7 @@ def display_result(self, show_diagnostic: bool = False, percentage: float = None
message = f"[{icon_color}]{icon}[/]"
if percentage is not None:
message += f" [{percentage_color}]({percentage:.2f}%)[/]"
message += f" {self.description}"
message += f" {self.description}"
if not self.passed and show_diagnostic:
message += f"\n[yellow] → {self.diagnostic}"
return message
Expand Down
29 changes: 16 additions & 13 deletions gatorgrade/output/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ def write_json_or_md_file(file_name, content_type, content):
"\n[red]Can't open or write the target file, check if you provide a valid path"
) from e


def calculate_total_weight(checks: List[Union[ShellCheck, GatorGraderCheck]]) -> int:
"""Calculate the total weight of all the checks."""
total_weight = 0
Expand All @@ -302,7 +303,9 @@ def calculate_total_weight(checks: List[Union[ShellCheck, GatorGraderCheck]]) ->
return total_weight


def run_checks(checks: List[Union[ShellCheck, GatorGraderCheck]], report: Tuple[str, str, str]) -> bool:
def run_checks(
checks: List[Union[ShellCheck, GatorGraderCheck]], report: Tuple[str, str, str]
) -> 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
Expand All @@ -315,7 +318,6 @@ def run_checks(checks: List[Union[ShellCheck, GatorGraderCheck]], report: Tuple[
results = []
for check in checks:
result = None
command_ran = None
weight = 1
# run a shell check; this means
# that it is going to run a command
Expand All @@ -331,7 +333,8 @@ def run_checks(checks: List[Union[ShellCheck, GatorGraderCheck]], report: Tuple[
weight = check.gg_args[index_of_weight + 1]
# Remove the hint from gg_args before passing to GatorGrader
check.gg_args = (
check.gg_args[:index_of_weight] + check.gg_args[index_of_weight + 2 :]
check.gg_args[:index_of_weight]
+ check.gg_args[index_of_weight + 2 :]
)
result = _run_shell_check(check)
result.weight = int(weight)
Expand All @@ -343,7 +346,8 @@ def run_checks(checks: List[Union[ShellCheck, GatorGraderCheck]], report: Tuple[
weight = check.gg_args[index_of_weight + 1]
# Remove the hint from gg_args before passing to GatorGrader
check.gg_args = (
check.gg_args[:index_of_weight] + check.gg_args[index_of_weight + 2 :]
check.gg_args[:index_of_weight]
+ check.gg_args[index_of_weight + 2 :]
)
result = _run_gg_check(check)
result.weight = int(weight)
Expand All @@ -363,15 +367,15 @@ def run_checks(checks: List[Union[ShellCheck, GatorGraderCheck]], report: Tuple[
# there were results from running checks
# and thus they must be displayed
if result is not None:
check_weight = (int(weight) / total_weight)
check_weight = int(weight) / total_weight
check_percent = round(check_weight * 100, 2)
result.print(percentage=check_percent)
results.append(result)
# testing printed weights
# print(f"Weight = {weight}")
#total_weight = sum(getattr(result, 'weight', 1) for result in results)
#check_weight = (int(weight) / total_weight)
#print(check_weight * 100)
# total_weight = sum(getattr(result, 'weight', 1) for result in results)
# check_weight = (int(weight) / total_weight)
# print(check_weight * 100)

# determine if there are failures and then display them
failed_results = list(filter(lambda result: not result.passed, results))
Expand Down Expand Up @@ -403,16 +407,15 @@ def run_checks(checks: List[Union[ShellCheck, GatorGraderCheck]], report: Tuple[
passed_weight = 0
percent = 0
else:
total_weight = sum(getattr(result, 'weight', 1) for result in results)
passed_weight = sum(getattr(result, 'weight', 1) for result in results if result.passed)
total_weight = sum(getattr(result, "weight", 1) for result in results)
passed_weight = sum(
getattr(result, "weight", 1) for result in results if result.passed
)
# prevent division by zero if no results
if total_weight == 0:
percent = 0
else:
percent = round(passed_weight / total_weight * 100)
# Print check percentages for each check
for result in results:
check_weight_percentage = (result.weight / total_weight) * 100

# if the report is wanted, create output in line with their specifications
if all(report):
Expand Down

0 comments on commit 2747a1f

Please sign in to comment.