SPB Git

Repository Public Research preview

test_validate_and_mock.py 1.8 KB 31 lines python

1from htr.rewrite.mock_provider import MockProvider2from htr.rewrite.prompts import PROMPT_VERSION, build_messages, prompt_fingerprint3from htr.validate.checks import ValidationConfig, validate_pair45ORIG = "We measured 12 samples at 37 °C [1]. The effect was not significant (p = 0.4), suggesting that the mechanism may differ. However, several limitations apply, and further work is required to confirm these findings in larger cohorts."678def test_mock_is_deterministic_and_preserves_numbers():9    m = MockProvider(seed=1)10    sys_, msgs = build_messages(ORIG, "A")11    r1 = m.rewrite(sys_, msgs, 500, {"variant": "A", "sample_index": 0})12    r2 = m.rewrite(sys_, msgs, 500, {"variant": "A", "sample_index": 0})13    assert r1.text == r2.text and r1.status == "ok"14    assert "12" in r1.text and "37" in r1.text and "[1]" in r1.text151617def test_validation_catches_failures():18    cfg = ValidationConfig(use_embeddings=False)19    assert validate_pair(ORIG, ORIG, "A", cfg).passed is False  # verbatim copy20    bad = ORIG.replace("12 samples", "15 samples").replace("not significant", "significant")21    v = validate_pair(ORIG, bad.replace("We measured", "They examined"), "A", cfg)22    assert v.checks["numbers_preserved"] is False23    assert validate_pair(ORIG, None, "A", cfg).passed is False24    good = "Twelve... we examined 12 samples at 37 °C [1]. No significant effect emerged (p = 0.4), which suggests the mechanism may differ. Several limitations nonetheless apply, and additional work is required to confirm these findings in larger cohorts."25    v2 = validate_pair(ORIG, good, "A", cfg)26    assert v2.checks["numbers_preserved"] and v2.checks["language"] and v2.checks["not_verbatim_copy"]272829def test_prompt_versioning():30    assert PROMPT_VERSION.startswith("rw-") and len(prompt_fingerprint()) == 1631
Files main
Menu

Theme