File size: 1,720 Bytes
490f3fe | 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | from __future__ import annotations
import hashlib
import importlib.util
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[1]
def load_script():
path = ROOT / "scripts" / "fetch_assets.py"
spec = importlib.util.spec_from_file_location(path.stem, path)
module = importlib.util.module_from_spec(spec)
assert spec and spec.loader
spec.loader.exec_module(module)
return module
def test_git_lfs_checkpoint_is_verified_in_place(tmp_path: Path) -> None:
module = load_script()
payload = b"checkpoint-bytes"
checkpoint = tmp_path / "weights.pt"
checkpoint.write_bytes(payload)
module.fetch_file(
tmp_path,
{
"id": "weights",
"kind": "checkpoint",
"storage": "git_lfs",
"destination": "weights.pt",
"bytes": len(payload),
"sha256": hashlib.sha256(payload).hexdigest(),
},
)
assert checkpoint.read_bytes() == payload
def test_git_lfs_pointer_fails_with_pull_guidance(tmp_path: Path) -> None:
module = load_script()
pointer = tmp_path / "weights.pt"
pointer.write_text(
"version https://git-lfs.github.com/spec/v1\n"
"oid sha256:0000000000000000000000000000000000000000000000000000000000000000\n"
"size 10\n",
encoding="utf-8",
)
with pytest.raises(RuntimeError, match="git lfs pull"):
module.fetch_file(
tmp_path,
{
"id": "weights",
"kind": "checkpoint",
"storage": "git_lfs",
"destination": "weights.pt",
"bytes": 10,
"sha256": "0" * 64,
},
)
|