Datasets:
Download source/tests/test_output_structure.py from Syndicate604/skills-desk: direct link, hf CLI and curl.
- Browser
- Download file 2.55 kB
-
https://huggingface.co/datasets/Syndicate604/skills-desk/resolve/main/source/tests/test_output_structure.py
- Command line
-
hf download hf://datasets/Syndicate604/skills-desk/source/tests/test_output_structure.py
-
curl -L -o test_output_structure.py https://huggingface.co/datasets/Syndicate604/skills-desk/resolve/main/source/tests/test_output_structure.py
2.55 kB
| """Structure is part of the grade: malformed CSV fails even when the values are right, while | |
| harmless representation differences (quoting, a trailing blank line, CRLF) still pass.""" | |
| import csv | |
| import io | |
| import os | |
| import tempfile | |
| import pytest | |
| os.environ.setdefault("TERMINAL_DESK_APP", tempfile.mkdtemp(prefix="td-struct-")) | |
| from terminal_desk.core.grading import render_artifact # noqa: E402 | |
| from terminal_desk.families import all_task_ids, reserved_task_ids # noqa: E402 | |
| from terminal_desk.models import Tbench2Action # noqa: E402 | |
| from terminal_desk.server.environment import TerminalDeskEnvironment # noqa: E402 | |
| def csv_tasks(): | |
| out = [] | |
| for t in all_task_ids() + reserved_task_ids(): | |
| env = TerminalDeskEnvironment() | |
| env.reset(task_id=t) | |
| if env._ep["built"].artifact.path.endswith(".csv"): | |
| out.append(t) | |
| return out | |
| CSV_TASKS = csv_tasks() | |
| def grade(task_id: str, mutate) -> float: | |
| env = TerminalDeskEnvironment() | |
| env.reset(task_id=task_id) | |
| built = env._ep["built"] | |
| art = built.artifact | |
| for path, text in built.notes.get("oracle_files", {}).items(): | |
| env.step(Tbench2Action(action_type="write_file", file_path=path, content=text)) | |
| content = mutate(render_artifact(art)) | |
| env.step(Tbench2Action(action_type="write_file", file_path=art.path, content=content)) | |
| return env.step(Tbench2Action(action_type="evaluate")).reward | |
| def extra_field_every_row(text): | |
| head, *rows = text.rstrip("\n").split("\n") | |
| return "\n".join([head] + [r + ",extra" for r in rows]) + "\n" | |
| def extra_field_one_row(text): | |
| head, first, *rest = text.rstrip("\n").split("\n") | |
| return "\n".join([head, first + ",extra"] + rest) + "\n" | |
| def missing_field_one_row(text): | |
| head, first, *rest = text.rstrip("\n").split("\n") | |
| return "\n".join([head, first.rsplit(",", 1)[0]] + rest) + "\n" | |
| def requote_all(text): | |
| out = io.StringIO() | |
| csv.writer(out, quoting=csv.QUOTE_ALL, lineterminator="\r\n").writerows(csv.reader(io.StringIO(text))) | |
| return out.getvalue() + "\r\n" | |
| def test_csv_tasks_found(): | |
| assert len(CSV_TASKS) >= 4, CSV_TASKS | |
| def test_malformed_csv_scores_zero(task_id, mutate): | |
| assert grade(task_id, mutate) == 0.0 | |
| def test_harmless_csv_representation_still_scores_one(task_id): | |
| assert grade(task_id, requote_all) == 1.0 | |