fix citation_audit answer parsing: tolerate units attached to answer_given
Browse files
tests/test_analysis/test_citation_audit.py
CHANGED
|
@@ -46,6 +46,32 @@ def test_audit_separates_faithful_from_not_in_table(tmp_path):
|
|
| 46 |
assert summary["examples"][0]["nearest_table_value"] == 1.46
|
| 47 |
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
def test_audit_respects_condition_prefix(tmp_path):
|
| 50 |
code_path = tmp_path / "scene.json"
|
| 51 |
_write_code(code_path, {"chair": {"table": {"distance": "1.46 meters", "closeness rank": 1}}})
|
|
|
|
| 46 |
assert summary["examples"][0]["nearest_table_value"] == 1.46
|
| 47 |
|
| 48 |
|
| 49 |
+
def test_audit_parses_answers_with_units_attached(tmp_path):
|
| 50 |
+
"""Regression: answer_given values like "1.46 meters" (units not stripped by the
|
| 51 |
+
adapter) must still count as answered and be checked against the table -- an
|
| 52 |
+
early version used bare float() and silently misclassified every such answer as
|
| 53 |
+
unanswered, corrupting both total_answered and faithful_rate."""
|
| 54 |
+
code_path = tmp_path / "scene.json"
|
| 55 |
+
_write_code(code_path, {"chair": {"table": {"distance": "1.46 meters", "closeness rank": 1}}})
|
| 56 |
+
results_dir = tmp_path / "results"
|
| 57 |
+
(results_dir / "scene").mkdir(parents=True)
|
| 58 |
+
records = [
|
| 59 |
+
{"model": "m", "question_type": "object_abs_distance", "answer_given": "1.46 meters",
|
| 60 |
+
"spatial_code_path": str(code_path), "scene": "scene", "question_id": 1,
|
| 61 |
+
"condition": "base:x"},
|
| 62 |
+
{"model": "m", "question_type": "object_abs_distance", "answer_given": "no idea",
|
| 63 |
+
"spatial_code_path": str(code_path), "scene": "scene", "question_id": 2,
|
| 64 |
+
"condition": "base:x"},
|
| 65 |
+
]
|
| 66 |
+
for i, record in enumerate(records):
|
| 67 |
+
(results_dir / "scene" / f"{i}.json").write_text(json.dumps(record))
|
| 68 |
+
|
| 69 |
+
summary = citation_audit.audit(results_dir, "m")
|
| 70 |
+
assert summary["total_answered"] == 1
|
| 71 |
+
assert summary["faithful"] == 1
|
| 72 |
+
assert summary["unanswered"] == 1 # "no idea" has no number at all -- genuinely unanswered
|
| 73 |
+
|
| 74 |
+
|
| 75 |
def test_audit_respects_condition_prefix(tmp_path):
|
| 76 |
code_path = tmp_path / "scene.json"
|
| 77 |
_write_code(code_path, {"chair": {"table": {"distance": "1.46 meters", "closeness rank": 1}}})
|