Download tools/test_task_population.py from Lexmount/LexBench-Web-Fetch: direct link, hf CLI and curl.
- Browser
- Download file 3.52 kB
-
https://huggingface.co/datasets/Lexmount/LexBench-Web-Fetch/resolve/refs%2Fpr%2F3/tools/test_task_population.py
- Command line
-
hf download hf://datasets/Lexmount/LexBench-Web-Fetch@refs/pr/3/tools/test_task_population.py
-
curl -L -o test_task_population.py https://huggingface.co/datasets/Lexmount/LexBench-Web-Fetch/resolve/refs%2Fpr%2F3/tools/test_task_population.py
3.52 kB
| """Population selection must keep intended tasks and reject ambiguous inputs.""" | |
| from copy import deepcopy | |
| from pathlib import Path | |
| import unittest | |
| from task_population import select, validate | |
| ROOT = Path(__file__).resolve().parents[1] | |
| class PopulationTests(unittest.TestCase): | |
| def setUp(self): | |
| self.spec = validate(ROOT) | |
| self.records = self.spec['cases'] + self.spec['excluded'] | |
| def test_selection_matches_report_and_retains_dynamic_suite(self): | |
| result = select(ROOT, self.records, self.spec['revision']) | |
| self.assertEqual(len(result), 530) | |
| self.assertIn({'suite': 'dynamic-content', 'id': 'dynamic-iframe'}, result) | |
| self.assertNotIn(('webfetch', 'dynamic-iframe'), {(r['suite'], r['id']) for r in result}) | |
| def test_already_selected_input(self): | |
| self.assertEqual(select(ROOT, self.spec['cases'], self.spec['revision']), self.spec['cases']) | |
| def test_duplicate_rejected(self): | |
| with self.assertRaises(ValueError): | |
| select(ROOT, self.records + [self.records[0]], self.spec['revision']) | |
| def test_missing_task_rejected(self): | |
| with self.assertRaises(ValueError): | |
| select(ROOT, self.records[1:], self.spec['revision']) | |
| def test_unknown_task_rejected(self): | |
| with self.assertRaises(ValueError): | |
| select(ROOT, self.records + [{'suite': 'webfetch', 'id': 'unknown'}], self.spec['revision']) | |
| def test_other_revision_rejected(self): | |
| with self.assertRaises(ValueError): | |
| select(ROOT, self.records, 'review-550-20261023') | |
| def test_tampered_binding_rejected(self): | |
| spec = deepcopy(self.spec) | |
| spec['frozen_task_bindings']['webfetch']['sha256'] = '0' * 64 | |
| with self.assertRaises(ValueError): | |
| validate(ROOT, spec) | |
| def test_overlap_rejected(self): | |
| spec = deepcopy(self.spec) | |
| spec['excluded'][0] = spec['cases'][0] | |
| with self.assertRaises(ValueError): | |
| validate(ROOT, spec) | |
| def test_wrong_count_rejected(self): | |
| spec = deepcopy(self.spec) | |
| spec['task_count'] = 550 | |
| with self.assertRaises(ValueError): | |
| validate(ROOT, spec) | |
| def test_wrong_revision_hash_rejected(self): | |
| spec = deepcopy(self.spec) | |
| spec['revision_sha256'] = '0' * 64 | |
| with self.assertRaisesRegex(ValueError, 'revision hash'): | |
| validate(ROOT, spec) | |
| class RunnerSelectionTests(unittest.TestCase): | |
| def test_cli_selects_exactly_the_report_population(self): | |
| import subprocess | |
| import sys | |
| spec = validate(ROOT) | |
| actual = [] | |
| for suite, count in spec['suite_counts'].items(): | |
| command = [sys.executable, str(ROOT / 'tools/task_population.py'), '--suite', suite] | |
| result = subprocess.run(command, check=True, text=True, capture_output=True) | |
| ids = result.stdout.strip().split(',') | |
| self.assertEqual(len(ids), count) | |
| actual.extend((suite, identifier) for identifier in ids) | |
| self.assertEqual(set(actual), {(r['suite'], r['id']) for r in spec['cases']}) | |
| self.assertEqual(len(actual), 530) | |
| def test_cli_rejects_unknown_suite(self): | |
| import subprocess | |
| import sys | |
| result = subprocess.run([sys.executable, str(ROOT / 'tools/task_population.py'), | |
| '--suite', 'unknown'], text=True, capture_output=True) | |
| self.assertNotEqual(result.returncode, 0) | |
| self.assertEqual(result.stdout, '') | |