-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make check outputs visually more appealing
* implement AssertResult that allows formatting of assert results * use answer_key as CheckableWidget name * handle error during check more transparent to student by catching errors during fingerprint function and asserts and embedding them into the assert message * implement input parameters for Checks - suppress_fingerprint_asserts: specifies if the assert messages that use the fingerprint function result are suppressed - stop_on_assert_error_raised: Specifies if running the asserts is stopped as soon as an error is raised in an assert * format check results more structured
- Loading branch information
1 parent
6842420
commit 9687211
Showing
8 changed files
with
386 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,56 @@ | ||
import re | ||
|
||
from termcolor import colored | ||
|
||
|
||
class Printer: | ||
# move to output | ||
# TODO rename to Formatter | ||
# remove print funcs | ||
LINE_LENGTH = 120 | ||
INFO_COLOR = "blue" | ||
ERROR_COLOR = "red" | ||
SUCCESS_COLOR = "green" | ||
|
||
@staticmethod | ||
def format_title_message(message: str) -> str: | ||
return message.center(Printer.LINE_LENGTH - len(message) // 2, "-") | ||
|
||
@staticmethod | ||
def break_lines(message: str) -> str: | ||
return "\n ".join(re.findall(r".{1," + str(Printer.LINE_LENGTH) + "}", message)) | ||
|
||
@staticmethod | ||
def color_error_message(message: str) -> str: | ||
return colored(message, Printer.ERROR_COLOR, attrs=["bold"]) | ||
|
||
@staticmethod | ||
def print_error_message(message: str): | ||
print(colored(message, "red", attrs=["bold"])) | ||
print(Printer.color_error_message(message)) | ||
|
||
@staticmethod | ||
def color_success_message(message: str) -> str: | ||
return colored(message, Printer.SUCCESS_COLOR, attrs=["bold"]) | ||
|
||
@staticmethod | ||
def print_success_message(message: str): | ||
print(colored(message, "green", attrs=["bold"])) | ||
print(Printer.color_success_message(message)) | ||
|
||
@staticmethod | ||
def color_info_message(message: str): | ||
return colored(message, Printer.INFO_COLOR, attrs=["bold"]) | ||
|
||
@staticmethod | ||
def print_info_message(message: str): | ||
print(colored(message, "blue", attrs=["bold"])) | ||
print(Printer.color_info_message(message)) | ||
|
||
@staticmethod | ||
def color_assert_failed(message: str) -> str: | ||
return colored(message, "light_" + Printer.ERROR_COLOR) | ||
|
||
@staticmethod | ||
def color_assert_info(message: str) -> str: | ||
return colored(message, "light_" + Printer.INFO_COLOR) | ||
|
||
@staticmethod | ||
def color_assert_success(message: str) -> str: | ||
return colored(message, "light_" + Printer.SUCCESS_COLOR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.