Datasets:
Download source/tests/test_grading.py from dnakhla/terminal-desk: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/datasets/dnakhla/terminal-desk/resolve/main/source/tests/test_grading.py
- Command line
-
hf download hf://datasets/dnakhla/terminal-desk/source/tests/test_grading.py
-
curl -L -o test_grading.py https://huggingface.co/datasets/dnakhla/terminal-desk/resolve/main/source/tests/test_grading.py
1.5 kB
| """Grader behaviour on malformed agent output: a bad file scores 0, it never raises out of the server.""" | |
| import os | |
| import sys | |
| import tempfile | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from terminal_desk.core.grading import run_checks # noqa: E402 | |
| from terminal_desk.families.base import Artifact # noqa: E402 | |
| CSV_CHECKS = Artifact( | |
| path="out.csv", kind="checks", parse="csv", | |
| checks=[("test_header", lambda p: p["header"] == ["id", "value"]), ("test_one_row", lambda p: len(p["rows"]) == 1)], | |
| ) | |
| def _run(content: str) -> dict[str, bool]: | |
| with tempfile.TemporaryDirectory() as root: | |
| os.chmod(root, 0o755) | |
| with open(os.path.join(root, "out.csv"), "w") as fh: | |
| fh.write(content) | |
| return run_checks(root, CSV_CHECKS) | |
| def test_well_formed_csv_passes(): | |
| assert _run("id,value\n1,2\n") == {"test_file_exists": True, "test_header": True, "test_one_row": True} | |
| def test_row_with_extra_cells_fails_every_check(): | |
| # csv.DictReader puts the extra cells in a list under None; the grader must fail, not raise (seen in the | |
| # v3 screen: sec3_fw_verdicts-L2 answered with a third column and the episode died with EXECUTION_ERROR). | |
| assert _run("id,value\n1,2,3\n") == {"test_file_exists": True, "test_header": False, "test_one_row": False} | |
| def test_row_with_missing_cells_fails_every_check(): | |
| assert _run("id,value\n1\n") == {"test_file_exists": True, "test_header": False, "test_one_row": False} | |