Files
troupe-standup/wizard-work/spark/verification_tests.py
T

84 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""Comprehensive test suite for json_validator.py using inline test cases."""
import json
import subprocess
import sys
from pathlib import Path
SCRIPT_PATH = "/root/.hermes/wizard-outputs/spark/json_validator.py"
OUTPUT_PATH = "/root/.hermes/wizard-outputs/spark/validation_test_results.json"
# Test cases: (json_string, should_be_valid, description)
TEST_CASES = [
('{"name": "test", "value": 42}', True, "Simple object with string and number"),
('[1, 2, 3, "four", true, null]', True, "Array with mixed types"),
('"just a string"', True, "Plain string"),
('3.14159', True, "Float number"),
('42', True, "Integer number"),
('true', True, "Boolean true"),
('false', True, "Boolean false"),
('null', True, "Null value"),
('{"nested": {"key": "value"}}', True, "Nested object"),
('{"name": "test", "broken": }', False, "Invalid syntax - trailing broken"),
('{"a": 1, "b": 2,}', False, "Invalid - trailing comma"),
('{"missing": "quote}', False, "Invalid - missing closing quote"),
('not json at all', False, "Completely invalid"),
]
def main():
results = {
"validator_script": SCRIPT_PATH,
"tests": [],
"passed": 0,
"failed": 0,
"total": len(TEST_CASES)
}
for json_str, should_be_valid, description in TEST_CASES:
# Write test file
test_file = f"/tmp/test_json_{hash(json_str) % 10000}.json"
with open(test_file, 'w') as f:
f.write(json_str)
# Run validator
cmd = ["python3", SCRIPT_PATH, test_file]
proc = subprocess.run(cmd, capture_output=True, text=True)
# Parse result from stdout
stdout = proc.stdout.strip()
is_valid = "✓ VALID" in stdout
# Check if validation result matches expectation
passed = is_valid == should_be_valid
results["tests"].append({
"json": json_str[:60] + "..." if len(json_str) > 60 else json_str,
"description": description,
"expected_valid": should_be_valid,
"actual_valid": is_valid,
"passed": passed,
"exit_code": proc.returncode
})
if passed:
results["passed"] += 1
else:
results["failed"] += 1
results["all_passed"] = results["failed"] == 0
# Write results
with open(OUTPUT_PATH, 'w') as f:
json.dump(results, f, indent=2)
print(f"\nValidation Test Results:")
print(f" Passed: {results['passed']}/{results['total']}")
print(f" Failed: {results['failed']}/{results['total']}")
print(f" Status: {'ALL PASSED' if results['all_passed'] else 'SOME FAILED'}")
print(f"\nResults saved to: {OUTPUT_PATH}")
return 0 if results["all_passed"] else 1
if __name__ == "__main__":
sys.exit(main())