Datasets:
Download code/evaluation-code/v0.2-0c2690ae/tools/workspace/test_quick.py from VEHwang/cocogni4d: direct link, hf CLI and curl.
- Browser
- Download file 1.9 kB
-
https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/v0.2-0c2690ae/tools/workspace/test_quick.py
- Command line
-
hf download hf://datasets/VEHwang/cocogni4d/code/evaluation-code/v0.2-0c2690ae/tools/workspace/test_quick.py
-
curl -L -o test_quick.py https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/v0.2-0c2690ae/tools/workspace/test_quick.py
1.9 kB
| import json | |
| from pathlib import Path | |
| import subprocess | |
| import tempfile | |
| import unittest | |
| from tools.workspace.quick import select | |
| class QuickTests(unittest.TestCase): | |
| def test_selection_and_fallback(self): | |
| with tempfile.TemporaryDirectory() as folder: | |
| root = Path(folder) | |
| def git(*args): | |
| return subprocess.check_output(['git', '-C', folder, '-c', 'user.name=test', '-c', 'user.email=test@example.invalid', *args], text=True) | |
| def write(name, text): | |
| path = root / name; path.parent.mkdir(parents=True, exist_ok=True); path.write_text(text) | |
| git('init', '-q') | |
| write('tools/workspace/entrypoints.json', json.dumps({'schema': 1, 'modules': ['np.x'], 'files': []})) | |
| for name, text in {'np/x.py': 'def value(): return 1\n', 'np/y.py': 'VALUE = 1\n', | |
| 'tests/test_x.py': 'def test_pair(): pass\n', 'tests/test_literal.py': "PATH = 'np/y.py'\n", | |
| 'tests/test_static.py': 'from np.x import value\ndef test_value(): assert value() == 2\n'}.items(): write(name, text) | |
| git('add', '.'); git('commit', '-qm', 'base') | |
| write('np/x.py', 'def value(): return 2\n'); write('np/y.py', 'VALUE = 2\n') | |
| git('add', '.'); git('commit', '-qm', 'python') | |
| self.assertEqual(select(root, 'HEAD^'), ['tests/test_literal.py', 'tests/test_static.py', 'tests/test_x.py']) | |
| for name, text, error in [('np/uncovered.py', 'X = 1\n', '未找到测试'), ('np/config.json', '{}', '非 Python')]: | |
| write(name, text); git('add', '.'); git('commit', '-qm', name) | |
| with self.assertRaisesRegex(ValueError, error): select(root, 'HEAD^') | |
| write('docs/note.md', 'docs'); git('add', '.'); git('commit', '-qm', 'docs') | |
| self.assertEqual(select(root, 'HEAD^'), []) | |