Files

41 lines
1.2 KiB
Python

#!/usr/bin/env python3
# Verification script for json_formatter.py
import subprocess
import sys
def test_formatter():
# Test 1: Valid JSON with key reordering
result = subprocess.run(
['python3', '/root/.hermes/wizard-outputs/spark/json_formatter.py'],
input='{"z": 1, "a": 2}',
capture_output=True,
text=True
)
if result.returncode != 0:
print("FAIL: Expected exit code 0, got", result.returncode, file=sys.stderr)
return 1
expected_lines = ['{', ' "a": 2,', ' "z": 1', '}']
output_lines = result.stdout.strip().split('\n')
if output_lines != expected_lines:
print("FAIL: Output mismatch", file=sys.stderr)
print("Expected:", expected_lines, file=sys.stderr)
print("Got:", output_lines, file=sys.stderr)
return 1
# Test 2: Invalid JSON should fail
result = subprocess.run(
['python3', '/root/.hermes/wizard-outputs/spark/json_formatter.py'],
input='not json',
capture_output=True,
text=True
)
if result.returncode == 0:
print("FAIL: Invalid JSON should return non-zero", file=sys.stderr)
return 1
print("PASS")
return 0
if __name__ == "__main__":
sys.exit(test_formatter())