Download tests/test_structured.py from NoiwaDEX/SvaraSetu: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/spaces/NoiwaDEX/SvaraSetu/resolve/main/tests/test_structured.py
- Command line
-
hf download hf://spaces/NoiwaDEX/SvaraSetu/tests/test_structured.py
-
curl -L -o test_structured.py https://huggingface.co/spaces/NoiwaDEX/SvaraSetu/resolve/main/tests/test_structured.py
1.75 kB
| """Gemini structured-output validation (no network).""" | |
| from svarasetu.compose.polish import _validate_structured | |
| from svarasetu.shield.outbound import unsupported_claims | |
| def test_validate_structured_happy_path(): | |
| parsed = { | |
| "answer": "The heart has four chambers.", | |
| "language": "en-IN", | |
| "grounded": True, | |
| "confidence": 0.8, | |
| "refused": False, | |
| "citations": [ | |
| {"chunk_id": "c1", "claim": "four chambers", "supported": True}, | |
| {"chunk_id": "drop-me", "claim": "ignored", "supported": True}, | |
| ], | |
| } | |
| out = _validate_structured(parsed, "en", ["c1", "c2"]) | |
| assert out is not None | |
| assert out["language"] == "en" | |
| assert out["grounded"] is True | |
| assert out["citations"] == [ | |
| {"chunk_id": "c1", "claim": "four chambers", "supported": True} | |
| ] | |
| def test_validate_structured_refuse_on_insufficient(): | |
| parsed = { | |
| "answer": "I don't have enough grounded information to answer that.", | |
| "language": "hi", | |
| "grounded": True, | |
| "confidence": 0.1, | |
| "refused": False, | |
| "citations": [], | |
| } | |
| out = _validate_structured(parsed, "hi", []) | |
| assert out["refused"] is True | |
| assert out["grounded"] is False | |
| def test_validate_structured_rejects_empty(): | |
| assert _validate_structured({"answer": " "}, "en", []) is None | |
| assert _validate_structured({}, "en", []) is None | |
| def test_unsupported_claims_flags_alien_sentence(): | |
| bad = unsupported_claims( | |
| "The heart has four chambers. Alien spacecraft landed on Mars in 1845.", | |
| [{"text": "The human heart has four muscular chambers that pump blood."}], | |
| min_overlap=0.25, | |
| ) | |
| assert any("Alien" in s for s in bad) | |