Compare commits
2 Commits
state-tabl
...
main
Author | SHA1 | Date | |
---|---|---|---|
4d02e90aac | |||
da69ad6d43 |
@ -1,5 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
for JSON in $(find test_files -iregex .*json); do
|
|
||||||
./main $JSON
|
|
||||||
done
|
|
71
run_tests.py
Executable file
71
run_tests.py
Executable file
@ -0,0 +1,71 @@
|
|||||||
|
#!/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"
|
||||||
|
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
|
||||||
|
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:
|
||||||
|
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]
|
||||||
|
|
||||||
|
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
|
proc.wait()
|
||||||
|
|
||||||
|
stdout, _ = proc.communicate()
|
||||||
|
|
||||||
|
try:
|
||||||
|
parsed = json.loads(stdout)
|
||||||
|
except:
|
||||||
|
parsed = None
|
||||||
|
pass
|
||||||
|
|
||||||
|
match = original == parsed
|
||||||
|
|
||||||
|
print(
|
||||||
|
f"\n{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": [
|
"position": [
|
||||||
25.1212,
|
25.1212,
|
||||||
55.1535
|
55.1535
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Shangri-La Hotel",
|
"name": "Shangri-La Hotel",
|
||||||
|
Loading…
Reference in New Issue
Block a user