Spaces:
Running on T4
Running on T4
File size: 1,277 Bytes
326d3cc | 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 | import io
import zipfile
import hashlib
import yaml
from baseball_batting.resources import fetch_artifact
def test_download_flattens_archive_removes_duplicate_and_reuses_verified_model(tmp_path,monkeypatch):
buffer = io.BytesIO()
with zipfile.ZipFile(buffer,"w") as z:
z.writestr("../../nested/model.onnx",b"synthetic-artifact-not-inference-qualified")
payload = buffer.getvalue()
registry = tmp_path/"resources.yaml"
registry.write_text(yaml.safe_dump({"resources":{"body_pose":{
"type":"checkpoint", "source_url":"https://example.invalid/model.zip",
"archive_sha256":hashlib.sha256(payload).hexdigest()}}}))
monkeypatch.setattr("urllib.request.urlopen",lambda *args,**kwargs:io.BytesIO(payload))
record = fetch_artifact("body_pose",registry,tmp_path/"cache")
assert record["technical_test_status"] == "candidate"
assert not (tmp_path/"cache/body_pose/model.zip").exists()
assert not (tmp_path/"model.onnx").exists()
def reject_network(*args,**kwargs):
raise AssertionError("Verified model reuse must not redownload a duplicate archive")
monkeypatch.setattr("urllib.request.urlopen",reject_network)
assert fetch_artifact("body_pose",registry,tmp_path/"cache")["sha256"] == record["sha256"]
|