Add basic test suite to validate that the parser works
This commit is contained in:
parent
ec6df32839
commit
bf958056bd
@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
for JSON in $(find test_files -iregex .*json); do
|
||||
./main $JSON
|
||||
done
|
50
run_tests.py
Executable file
50
run_tests.py
Executable file
@ -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}"
|
||||
)
|
@ -5,7 +5,7 @@
|
||||
"position": [
|
||||
25.1212,
|
||||
55.1535
|
||||
],
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Shangri-La Hotel",
|
||||
|
Loading…
Reference in New Issue
Block a user