From 4d02e90aac74242fe520cb6434664a5ef7c24d42 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sun, 30 Jul 2023 23:56:34 +0100 Subject: [PATCH] Update run_tests.py --- run_tests.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/run_tests.py b/run_tests.py index baa903f..c8bc5bd 100755 --- a/run_tests.py +++ b/run_tests.py @@ -12,6 +12,12 @@ class TermFormat: BOLD = "\033[1m" +def print_header(header, width, padding): + print( + f"{TermFormat.BOLD}{'=' * (int(width / 3) + padding)}{header}{'=' * (int(width / 3) + padding)}{TermFormat.ENDC}" + ) + + test_dir = Path(__file__).parent / "test_files" hj_exec = Path(__file__).parent / "main" @@ -29,9 +35,20 @@ for vf in valid_files: if len(str(vf)) > name_width: name_width = len(str(vf)) + +print_header("helloJSON TEST SUITE", name_width, 9) +print() +print_header("VALID FILES", name_width, 13) + for vf in valid_files: with open(vf, "r") as infile: - original = json.load(infile) + try: + original = json.load(infile) + except json.JSONDecodeError as e: + print( + f"\n{TermFormat.BOLD}{TermFormat.FAIL}ERROR:{TermFormat.ENDC} Failed to decode {str(vf)}\n{e.msg}" + ) + continue cmd = [hj_exec, vf] @@ -41,10 +58,14 @@ for vf in valid_files: stdout, _ = proc.communicate() - parsed = json.loads(stdout) + try: + parsed = json.loads(stdout) + except: + parsed = None + pass match = original == parsed print( - f"{str(vf):<{name_width + 3}} {TermFormat.BOLD}{TermFormat.OKGREEN if match else TermFormat.FAIL}{'PASSED' if match else 'FAILED'}{TermFormat.ENDC}" + f"\n{str(vf):{name_width + 3}} {TermFormat.BOLD}{TermFormat.OKGREEN if match else TermFormat.FAIL}{'PASSED' if match else 'FAILED'}{TermFormat.ENDC}" )