Files
troupe-standup/wizard-work/spark/test_validator.py
T
ledger c0d9b37eb6 q98: bind the last 8 host-locked test files to their own directory; import_resolve_check 9 faults -> 0
The eight test files Q98 leaves open (plus test_bfs.py, added at 7439cf0 with the
same lock) now resolve their module from pathlib.Path(__file__).resolve().parent
instead of /root/.hermes/wizard-outputs/<lane>.

  tools/import_resolve_check.py --repo .  at 7439cf0: 95 files, 9 faults, rc 1
                                          after:      95 files, 0 faults, rc 0

Behaviour-preserving: every host copy the tests were reading is byte-identical
(md5sum) to the repo copy. Three absolute literals in spark/test_validator.py
that the static leg does not grade (load_json(...) argument strings at pre-fix
lines 12/16/25) are re-pointed too.

ledger/test_scratch_manifest.py was red before any edit (str ROOT vs
gen_manifest ROOT.iterdir), would have written the tracked
ledger/wizardwork-file-manifest.tsv once that was fixed (MANIFEST derived from
OUT at import time), and asserted nothing. It now re-points ROOT/OUT/MANIFEST,
guards MANIFEST inside a tempfile.mkdtemp(), and asserts the exact manifest row.

Non-vacuity: scratch/q98b/poison_probe.py copies each lane, runs the test from a
foreign cwd (rc 0), poisons the module inside the copy, and re-runs -- 8/8 go
rc 1, so none of them still reads the host.

Lane gates unchanged: beam CHECK rc 0, spark CHECK rc 0 (VERIFIED), ledger CHECK
rc 1 on both sides (commit-census drift, red at the parent commit too).
2026-10-27 19:45:56 +00:00

44 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""Test runner for json_schema_cli.py"""
import pathlib
import sys
HERE = pathlib.Path(__file__).resolve().parent
sys.path.insert(0, str(HERE))
from json_schema_cli import validate_data, load_json
print("=" * 50)
print("JSON Schema Validator Tests")
print("=" * 50)
# Load test schema
schema = load_json(str(HERE / 'test_schema.json'))
# Test 1: Valid data
print("\nTest 1: Valid data")
valid_data = load_json(str(HERE / 'valid_test_data.json'))
errors = validate_data(valid_data, schema)
print(f" Data: {valid_data}")
print(f" Errors: {errors}")
print(f" Valid: {len(errors) == 0}")
assert len(errors) == 0, "Valid data should pass"
# Test 2: Invalid data (age is string)
print("\nTest 2: Invalid data")
invalid_data = load_json(str(HERE / 'invalid_test_data.json'))
errors = validate_data(invalid_data, schema)
print(f" Data: {invalid_data}")
print(f" Errors: {errors}")
print(f" Valid: {len(errors) == 0}")
assert len(errors) > 0, "Invalid data should fail"
# Test 3: Missing required field
print("\nTest 3: Missing required field")
missing_field = {"name": "Charlie"} # Missing age
errors = validate_data(missing_field, schema)
print(f" Data: {missing_field}")
print(f" Errors: {errors}")
assert len(errors) > 0, "Missing required field should fail"
print("\n" + "=" * 50)
print("All tests PASSED!")
print("=" * 50)