diff --git a/run_tests b/run_tests deleted file mode 100755 index c151632..0000000 --- a/run_tests +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -for JSON in $(find test_files -iregex .*json); do - ./main $JSON -done diff --git a/run_tests.py b/run_tests.py new file mode 100755 index 0000000..baa903f --- /dev/null +++ b/run_tests.py @@ -0,0 +1,50 @@ +#!/bin/env python3 + +import json +import subprocess +from pathlib import Path + + +class TermFormat: + OKGREEN = "\033[92m" + FAIL = "\033[91m" + ENDC = "\033[0m" + BOLD = "\033[1m" + + +test_dir = Path(__file__).parent / "test_files" +hj_exec = Path(__file__).parent / "main" + +valid_files = [ + json_file + for json_file in test_dir.iterdir() + if json_file.is_file() + and "json" in json_file.suffix + and "invalid" not in json_file.stem +] + +name_width = 0 + +for vf in valid_files: + if len(str(vf)) > name_width: + name_width = len(str(vf)) + +for vf in valid_files: + with open(vf, "r") as infile: + original = json.load(infile) + + cmd = [hj_exec, vf] + + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + + proc.wait() + + stdout, _ = proc.communicate() + + parsed = json.loads(stdout) + + 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}" + ) diff --git a/test_files/google_maps.json b/test_files/google_maps.json index 76fa466..8034abe 100644 --- a/test_files/google_maps.json +++ b/test_files/google_maps.json @@ -5,7 +5,7 @@ "position": [ 25.1212, 55.1535 - ], + ] }, { "name": "Shangri-La Hotel",