File size: 1,665 Bytes
76b7b25 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import json
import sys
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
from prepare_cpu_smoke import prepare # noqa: E402
class PrepareCpuSmokeTest(unittest.TestCase):
def test_requires_real_benchmark_index_and_cannot_overwrite(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
video = root / "sample_0.mp4"
video.write_bytes(b"source")
table = root / "table.json"
table.write_text(json.dumps({
"columns": ["index", "prompt", "local_path"],
"data": [[0, "A prompt", str(video)]],
}))
output = root / "out"
with patch("prepare_cpu_smoke.subprocess.run") as run:
with self.assertRaisesRegex(ValueError, "not unique/present"):
prepare(table, 1, output)
self.assertFalse(output.exists())
def fake_ffmpeg(command, check):
Path(command[-1]).write_bytes(b"wav")
run.side_effect = fake_ffmpeg
manifest = prepare(table, 0, output)
self.assertEqual(manifest["prompt"], "A prompt")
self.assertEqual(manifest["source_video_sha256"],
__import__("hashlib").sha256(b"source").hexdigest())
self.assertTrue((output / "javisbench_input.csv").is_file())
with self.assertRaises(FileExistsError):
prepare(table, 0, output)
if __name__ == "__main__":
unittest.main()
|