From 6b73d145d4c2d23fa32cb9475aadc9fc74b2b70d Mon Sep 17 00:00:00 2001 From: Chad Sharp Date: Mon, 19 Aug 2019 23:01:42 -0400 Subject: [PATCH 1/7] Convert to string if possible --- check50/_simple.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/check50/_simple.py b/check50/_simple.py index 3b2a30f5..9339b052 100644 --- a/check50/_simple.py +++ b/check50/_simple.py @@ -22,16 +22,16 @@ def _run(arg): def _stdin(arg): if isinstance(arg, list): - arg = r"\n".join(arg) + arg = r"\n".join(str(a) for a in arg) - arg = arg.replace("\n", r"\n").replace("\t", r"\t").replace('"', '\"') + arg = str(arg).replace("\n", r"\n").replace("\t", r"\t").replace('"', '\"') return f'.stdin("{arg}", prompt=False)' def _stdout(arg): if isinstance(arg, list): - arg = r"\n".join(arg) - arg = arg.replace("\n", r"\n").replace("\t", r"\t").replace('"', '\"') + arg = r"\n".join(str(a) for a in arg) + arg = str(arg).replace("\n", r"\n").replace("\t", r"\t").replace('"', '\"') return f'.stdout("{arg}", regex=False)' From 89ba925910233db65cff2ae92d00e01a8316e8c8 Mon Sep 17 00:00:00 2001 From: Chad Sharp Date: Mon, 19 Aug 2019 23:02:07 -0400 Subject: [PATCH 2/7] version++ --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index fa0d9680..a41d05c9 100644 --- a/setup.py +++ b/setup.py @@ -29,6 +29,6 @@ "console_scripts": ["check50=check50.__main__:main"] }, url="https://github.com/cs50/check50", - version="3.0.7", + version="3.0.8", include_package_data=True ) From d6708221dcecd47cb05bac6c4a6ebadcdcec451d Mon Sep 17 00:00:00 2001 From: Chad Sharp Date: Tue, 20 Aug 2019 14:51:57 -0400 Subject: [PATCH 3/7] add custom json encoder --- check50/__main__.py | 1 + check50/renderer/_renderers.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/check50/__main__.py b/check50/__main__.py index 16148b63..856bf3cf 100644 --- a/check50/__main__.py +++ b/check50/__main__.py @@ -366,6 +366,7 @@ def main(): } + breakpoint() # Render output file_manager = open(args.output_file, "w") if args.output_file else nullcontext(sys.stdout) with file_manager as output_file: diff --git a/check50/renderer/_renderers.py b/check50/renderer/_renderers.py index 71ebb26f..a4c97c66 100644 --- a/check50/renderer/_renderers.py +++ b/check50/renderer/_renderers.py @@ -12,6 +12,18 @@ TEMPLATES = pathlib.Path(pkg_resources.resource_filename("check50.renderer", "templates")) +class Encoder(json.JSONEncoder): + """Custom class for JSON encoding.""" + + def default(self, o): + if o == EOF: + return "EOF" + elif isinstance(o, CheckResult): + return attr.asdict(o) + else: + return o.__dict__ + + def to_html(slug, results, version): with open(TEMPLATES / "results.html") as f: content = f.read() From 737c0842db4254fae206711846011e380bf0f492 Mon Sep 17 00:00:00 2001 From: Chad Sharp Date: Tue, 20 Aug 2019 14:52:20 -0400 Subject: [PATCH 4/7] version++ --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a41d05c9..491c0a00 100644 --- a/setup.py +++ b/setup.py @@ -29,6 +29,6 @@ "console_scripts": ["check50=check50.__main__:main"] }, url="https://github.com/cs50/check50", - version="3.0.8", + version="3.0.9", include_package_data=True ) From 1c7d0179caf07320706ffbf0b1fb4d525bda4847 Mon Sep 17 00:00:00 2001 From: Chad Sharp Date: Tue, 20 Aug 2019 14:53:51 -0400 Subject: [PATCH 5/7] reomve breakpoint --- check50/__main__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/check50/__main__.py b/check50/__main__.py index 856bf3cf..41fc6cae 100644 --- a/check50/__main__.py +++ b/check50/__main__.py @@ -79,7 +79,7 @@ def excepthook(cls, exc, tb): if excepthook.verbose: traceback.print_exception(cls, exc, tb) if hasattr(exc, "payload"): - print("Exception payload:", exc.payload) + print("Exception payload:", json.dumps(exc.payload), sep="\n") sys.exit(1) @@ -366,7 +366,6 @@ def main(): } - breakpoint() # Render output file_manager = open(args.output_file, "w") if args.output_file else nullcontext(sys.stdout) with file_manager as output_file: From 4c3be6234b9fcb89738a37733db5d5cd71889a41 Mon Sep 17 00:00:00 2001 From: Chad Sharp Date: Tue, 20 Aug 2019 15:00:30 -0400 Subject: [PATCH 6/7] fix eof printing --- check50/_api.py | 14 ++++++++++---- check50/renderer/_renderers.py | 16 ---------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/check50/_api.py b/check50/_api.py index 9ff2b85f..de84151c 100644 --- a/check50/_api.py +++ b/check50/_api.py @@ -263,7 +263,7 @@ def stdout(self, output=None, str_output=None, regex=True, timeout=3): result += self.process.after raise Mismatch(str_output, result.replace("\r\n", "\n")) except TIMEOUT: - raise Failure(_("did not find \"{}\"").format(_raw(str_output))) + raise Failure(_("did not find {}").format(_raw(str_output))) except UnicodeDecodeError: raise Failure(_("output not valid ASCII text")) except Exception: @@ -402,7 +402,14 @@ class Mismatch(Failure): """ def __init__(self, expected, actual, help=None): - super().__init__(rationale=_("expected \"{}\", not \"{}\"").format(_raw(expected), _raw(actual)), help=help) + super().__init__(rationale=_("expected {}, not {}").format(_raw(expected), _raw(actual)), help=help) + + if expected == EOF: + expected = "EOF" + + if actual == EOF: + actual = "EOF" + self.payload.update({"expected": expected, "actual": actual}) @@ -445,8 +452,7 @@ def _raw(s): if s == EOF: return "EOF" - s = repr(s) # Get raw representation of string - s = s[1:-1] # Strip away quotation marks + s = f'"{repr(s)[1:-1]}"' if len(s) > 15: s = s[:15] + "..." # Truncate if too long return s diff --git a/check50/renderer/_renderers.py b/check50/renderer/_renderers.py index a4c97c66..53512dd2 100644 --- a/check50/renderer/_renderers.py +++ b/check50/renderer/_renderers.py @@ -1,29 +1,13 @@ import json import pathlib -import attr import jinja2 import pkg_resources -from pexpect.exceptions import EOF import termcolor -from ..runner import CheckResult - TEMPLATES = pathlib.Path(pkg_resources.resource_filename("check50.renderer", "templates")) -class Encoder(json.JSONEncoder): - """Custom class for JSON encoding.""" - - def default(self, o): - if o == EOF: - return "EOF" - elif isinstance(o, CheckResult): - return attr.asdict(o) - else: - return o.__dict__ - - def to_html(slug, results, version): with open(TEMPLATES / "results.html") as f: content = f.read() From 5e0d3a14e304e8c9d13a2d9ed767933e316ec8f3 Mon Sep 17 00:00:00 2001 From: Kareem Zidane Date: Tue, 20 Aug 2019 15:08:13 -0400 Subject: [PATCH 7/7] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 491c0a00..a41d05c9 100644 --- a/setup.py +++ b/setup.py @@ -29,6 +29,6 @@ "console_scripts": ["check50=check50.__main__:main"] }, url="https://github.com/cs50/check50", - version="3.0.9", + version="3.0.8", include_package_data=True )