Datasets:
Download experiments/t3/tests/test_evaluate.py from PV-SJTU/PV-Bench: direct link, hf CLI and curl.
- Browser
- Download file 3.73 kB
-
https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/experiments/t3/tests/test_evaluate.py
- Command line
-
hf download hf://datasets/PV-SJTU/PV-Bench/experiments/t3/tests/test_evaluate.py
-
curl -L -o test_evaluate.py https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/experiments/t3/tests/test_evaluate.py
3.73 kB
| from __future__ import annotations | |
| import json | |
| import unittest | |
| from pathlib import Path | |
| from unittest import mock | |
| from helpers import FAKE_FLAGS, RunFixture | |
| from pvbench_common.container import Outcome, Role | |
| from t3 import evaluate | |
| from t3.config import Config | |
| class EvaluateTests(RunFixture): | |
| def setUp(self) -> None: | |
| super().setUp() | |
| flags = mock.patch.object(Config, "container_coqflags", return_value=FAKE_FLAGS) | |
| flags.start() | |
| self.addCleanup(flags.stop) | |
| self.calls = [] | |
| def evaluate(self, exit_code=0, timed_out=False, oom=False, **kwargs) -> str: | |
| def fake_run(inv, *, timeout_s, stdout, stderr): | |
| self.calls.append((inv, timeout_s)) | |
| Path(stdout).write_text("build log\n") | |
| Path(stderr).write_text("") | |
| return Outcome(exit_code, timed_out, oom, 0.0, 2.0, Path(stdout), Path(stderr)) | |
| with mock.patch("pvbench_common.container.run", side_effect=fake_run): | |
| return evaluate.evaluate(self.cfg, self.case, **kwargs) | |
| def summary(self) -> dict: | |
| return json.loads((self.case.eval_dir / "summary.json").read_text()) | |
| def test_accept_and_build_invocation(self) -> None: | |
| text = self.evaluate() | |
| self.assertTrue(text.startswith("verdict: ACCEPT"), text) | |
| (inv, timeout_s), = self.calls | |
| self.assertIs(inv.role, Role.EVAL) | |
| args = list(inv.args) | |
| self.assertEqual(args[args.index("--network") + 1], "none") | |
| self.assertEqual(timeout_s, self.cfg.task.limits.eval_timeout_s) | |
| self.assertEqual([(host, at) for host, at, mode in inv.mounts if mode == "rw"], | |
| [(str(self.case.ev_build), "/work/answer")]) | |
| self.assertIn("coq_makefile -f _CoqProject", inv.command[-1]) | |
| project = (self.case.ev_build / "_CoqProject").read_text() | |
| self.assertIn("-R /work/answer/benchmarks PVbench", project) | |
| self.assertIn("/opt/qcp/Rocq/sets", project) | |
| self.assertIn(f"benchmarks/{self.problem}/rocq/groundtruth/{self.case.manual_name}", project) | |
| self.assertNotIn(str(self.root), project) | |
| self.assertEqual(self.summary()["build"]["exit_code"], 0) | |
| def test_build_timeout_is_otl(self) -> None: | |
| text = self.evaluate(exit_code=137, timed_out=True) | |
| self.assertIn("verdict: OTL", text) | |
| self.assertIn(f"evaluator build exceeded {self.cfg.task.limits.eval_timeout_s} s", text) | |
| def test_build_oom_is_failed(self) -> None: | |
| text = self.evaluate(exit_code=137, oom=True) | |
| self.assertIn("verdict: FAILED", text) | |
| self.assertIn(f"evaluator build exceeded memory limit {self.cfg.task.limits.memory}", text) | |
| def test_build_failure_is_failed(self) -> None: | |
| self.assertIn("verdict: FAILED", self.evaluate(exit_code=2)) | |
| def test_env_mismatch_is_invalid_before_building(self) -> None: | |
| self.image_id.return_value = "sha256:" + "c" * 64 | |
| text = self.evaluate() | |
| self.assertIn("verdict: INVALID", text) | |
| self.assertIn("image id mismatch", text) | |
| self.assertEqual(self.calls, []) | |
| def test_allow_env_mismatch_records_warning(self) -> None: | |
| self.image_id.return_value = "sha256:" + "c" * 64 | |
| text = self.evaluate(allow_env_mismatch=True) | |
| self.assertIn("verdict: ACCEPT", text) | |
| self.assertTrue(any("image id mismatch" in w for w in self.summary()["env_warnings"])) | |
| def test_bypass_fails_without_building(self) -> None: | |
| (self.case.out_dir / self.case.manual_name).write_text("Lemma x : False. Admitted.\n") | |
| self.assertIn("verdict: FAILED", self.evaluate()) | |
| self.assertEqual(self.calls, []) | |
| if __name__ == "__main__": | |
| unittest.main() | |