Files

49 lines
1.7 KiB
Python

#!/usr/bin/env python3
# Test script for json_diff.py
import subprocess
import sys
# Test 1: Compare identical files
result = subprocess.run(
[sys.executable, '/root/.hermes/wizard-outputs/spark/json_diff.py', 'sample_valid.json', 'sample_valid.json'],
capture_output=True,
text=True,
cwd='/root/.hermes/wizard-outputs/spark'
)
print(f"Test 1 (identical files): Exit code = {result.returncode}")
print(f" stdout: {result.stdout.strip()}")
print(f" stderr: {result.stderr.strip()}")
# Test 2: Compare different files
result2 = subprocess.run(
[sys.executable, '/root/.hermes/wizard-outputs/spark/json_diff.py', 'sample_valid.json', 'sample_invalid.json'],
capture_output=True,
text=True,
cwd='/root/.hermes/wizard-outputs/spark'
)
print(f"Test 2 (different files): Exit code = {result2.returncode}")
print(f" stdout: {result2.stdout.strip()}")
print(f" stderr: {result2.stderr.strip()}")
# Test 3: JSON key order test (create temp files)
import json
import tempfile
import os
with tempfile.TemporaryDirectory() as tmp:
# File 1: keys in order a, b, c
with open(os.path.join(tmp, 'f1.json'), 'w') as f:
json.dump({'c': 3, 'a': 1, 'b': 2}, f)
# File 2: keys in order c, b, a (but same values)
with open(os.path.join(tmp, 'f2.json'), 'w') as f:
json.dump({'a': 1, 'b': 2, 'c': 3}, f)
result3 = subprocess.run(
[sys.executable, '/root/.hermes/wizard-outputs/spark/json_diff.py',
os.path.join(tmp, 'f1.json'), os.path.join(tmp, 'f2.json')],
capture_output=True,
text=True
)
print(f"Test 3 (same content, different key order): Exit code = {result3.returncode}")
print(f" stdout: {result3.stdout.strip()}")
print(f" stderr: {result3.stderr.strip()}")