vox-tier2-backup / scripts /test_compiler.py
addyo07's picture
Tier-2 parking snapshot 2026-10-04
46e27b5 verified
Raw History Blame Contribute Delete
2.09 kB
"""
Unit test for deterministic compiler and slice-cut verifier.
Testing single label: 'speech disfluency' and zero target fields.
"""
from schema import RawCandidate
from compiler import compile_candidate_to_example
def run_tests():
# Test 1: Speech disfluency with filler and date retraction
c1 = RawCandidate(
category="DISFLUENCY",
raw_text="I want to do this, like, on Friday, wait no, Saturday.",
clean_text="I want to do this on Saturday.",
disfluent_spans=["like, ", "Friday, wait no, "]
)
ex1, err1 = compile_candidate_to_example(c1, "test_01")
assert err1 is None, f"Test 1 failed: {err1}"
assert ex1.clean_text == "I want to do this on Saturday."
assert len(ex1.spans) == 2
assert all(s.label == "speech disfluency" for s in ex1.spans)
print("Test 1 Passed: Disfluency Spans:", [s.model_dump() for s in ex1.spans])
# Test 2: Speech disfluency with cued retraction
c2 = RawCandidate(
category="DISFLUENCY",
raw_text="Send that to John... actually make that both John and Sarah's managers.",
clean_text="Send that to both John and Sarah's managers.",
disfluent_spans=["John... actually make that "]
)
ex2, err2 = compile_candidate_to_example(c2, "test_02")
assert err2 is None, f"Test 2 failed: {err2}"
assert ex2.clean_text == "Send that to both John and Sarah's managers."
assert ex2.spans[0].label == "speech disfluency"
print("Test 2 Passed: Cued Correction Span:", [s.model_dump() for s in ex2.spans])
# Test 3: CLEAN
c3 = RawCandidate(
category="CLEAN",
raw_text="I like this architecture because it works well.",
clean_text="I like this architecture because it works well.",
disfluent_spans=[]
)
ex3, err3 = compile_candidate_to_example(c3, "test_03")
assert err3 is None, f"Test 3 failed: {err3}"
assert len(ex3.spans) == 0
print("Test 3 Passed: CLEAN negative control passed!")
print(">>> ALL COMPILER TESTS PASSED! <<<")
if __name__ == "__main__":
run_tests()