70 lines
1.7 KiB
Python
70 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Verification script for json-toolkit.py"""
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def run_tool(filepath):
|
|
"""Run json-toolkit.py on a file and return (valid, exit_code)"""
|
|
proc = subprocess.run(['python3', 'json-toolkit.py', filepath],
|
|
capture_output=True, text=True)
|
|
return proc.returncode == 0
|
|
|
|
def main():
|
|
test_files = [
|
|
'test_input.json',
|
|
'test_data_valid.json',
|
|
'test_data_invalid.json',
|
|
'test_invalid.json',
|
|
]
|
|
|
|
results = []
|
|
all_pass = True
|
|
|
|
for fname in test_files:
|
|
filepath = Path(fname)
|
|
if not filepath.exists():
|
|
continue
|
|
|
|
# Check actual JSON validity
|
|
try:
|
|
with open(filepath) as f:
|
|
json.load(f)
|
|
actual_valid = True
|
|
error = None
|
|
except json.JSONDecodeError as e:
|
|
actual_valid = False
|
|
error = str(e)
|
|
|
|
# Run tool
|
|
tool_valid = run_tool(str(filepath))
|
|
|
|
# Check match
|
|
match = (tool_valid == actual_valid)
|
|
if not match:
|
|
all_pass = False
|
|
|
|
results.append({
|
|
'file': fname,
|
|
'json_valid': actual_valid,
|
|
'tool_valid': tool_valid,
|
|
'matches': match,
|
|
'error': str(error)[:60] if error else None
|
|
})
|
|
|
|
# Output
|
|
verification = {
|
|
'tests': results,
|
|
'all_pass': all_pass
|
|
}
|
|
|
|
print(json.dumps(verification, indent=2))
|
|
|
|
with open('tool_verification_results.json', 'w') as f:
|
|
json.dump(verification, f, indent=2)
|
|
|
|
return 0 if all_pass else 1
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main()) |