Update run_tests.py
This commit is contained in:
		
							
								
								
									
										27
									
								
								run_tests.py
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								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}" | ||||
|     ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user