Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hints for failing checks #156

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gatorgrade/output/check_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(
self.diagnostic = diagnostic
self.path = path
self.run_command = ""
self.hint = "" # Store the hint as an instance attribute

def display_result(self, show_diagnostic: bool = False) -> str:
"""Print check's passed or failed status, description, and, optionally, diagnostic message.
Expand All @@ -48,7 +49,7 @@ def display_result(self, show_diagnostic: bool = False) -> str:
return message

def __repr__(self):
return f"CheckResult(passed={self.passed}, description='{self.description}', json_info={self.json_info}, path='{self.path}', diagnostic='{self.diagnostic}', run_command='{self.run_command}')"
return f"CheckResult(passed={self.passed}, description='{self.description}', json_info={self.json_info}, path='{self.path}', diagnostic='{self.diagnostic}', run_command='{self.run_command}', hint='{self.hint}')"

def __str__(self, show_diagnostic: bool = False) -> str:
"""Print check's passed or failed status, description, and, optionally, diagnostic message.
Expand Down
18 changes: 16 additions & 2 deletions gatorgrade/output/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def create_markdown_report_file(json: dict) -> str:
if "command" == i:
val = check["options"]["command"]
markdown_contents += f"\n\t- **command** {val}"
if "hint" == i:
val = check["options"]["hint"]
markdown_contents += f"\n\t- **hint:** {val}"
if "fragment" == i:
val = check["options"]["fragment"]
markdown_contents += f"\n\t- **fragment:** {val}"
Expand Down Expand Up @@ -300,6 +303,7 @@ def run_checks(
for check in checks:
result = None
command_ran = None
hint = ""
# run a shell check; this means
# that it is going to run a command
# in the shell as a part of a check;
Expand All @@ -313,7 +317,16 @@ def run_checks(
result.run_command = command_ran
# run a check that GatorGrader implements
elif isinstance(check, GatorGraderCheck):
# Extract the hint from gg_args if present
if "--hint" in check.gg_args:
index_of_hint = check.gg_args.index("--hint")
hint = check.gg_args[index_of_hint + 1]
# Remove the hint from gg_args before passing to GatorGrader
check.gg_args = (
check.gg_args[:index_of_hint] + check.gg_args[index_of_hint + 2 :]
)
result = _run_gg_check(check)
result.hint = hint # Store the hint in the CheckResult object
# check to see if there was a command in the
# GatorGraderCheck. This code finds the index of the
# word "--command" in the check.gg_args list if it
Expand All @@ -339,8 +352,6 @@ def run_checks(
if len(failed_results) > 0:
print("\n-~- FAILURES -~-\n")
for result in failed_results:
# 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
Expand All @@ -353,6 +364,9 @@ def run_checks(
rich.print(
f"[blue] → Run this command: [green]{result.run_command}\n"
)
# display a hint set by the instructor for specific failed checks
if result.hint != "":
rich.print(f"[blue] → Hint: [green]{result.hint}\n")
# determine how many of the checks passed and then
# compute the total percentage of checks passed
passed_count = len(results) - len(failed_results)
Expand Down
Loading