nextgpt-v0-source / src /tests /test_model_bundle.py
caizz's picture
Publish verified code archive and live demo links
2ad74e3 verified
Raw History Blame Contribute Delete
2.08 kB
"""Checks that a pinned model bundle cannot silently omit required weights."""
import json
import os
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]))
from model_bundle import PATH_KEYS, resolve_paths
class ModelBundleTests(unittest.TestCase):
def test_complete_bundle_resolves_all_paths(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
values = {key: key for key in PATH_KEYS}
for key, rel in values.items():
path = root / rel
if key == "delta_path":
path.touch()
else:
path.mkdir()
(root / "vicuna_dir" / "config.json").touch()
(root / "vicuna_dir" / "model-00001-of-00001.safetensors").touch()
(root / "imagebind_dir" / "imagebind_huge.pth").touch()
for key in ("image_diffusion_dir", "audio_diffusion_dir", "video_diffusion_dir"):
(root / key / "model_index.json").touch()
manifest = root / "model_manifest.json"
manifest.write_text(json.dumps({"model": "NExT-GPT 7b_tiva_v0", "paths": values}))
with patch.dict(os.environ, {"NEXTGPT_MANIFEST": str(manifest)}):
self.assertEqual(set(resolve_paths()), set(PATH_KEYS))
def test_missing_adapter_is_rejected(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
values = {key: key for key in PATH_KEYS}
for key, rel in values.items():
if key != "delta_path":
(root / rel).mkdir()
manifest = root / "model_manifest.json"
manifest.write_text(json.dumps({"model": "NExT-GPT 7b_tiva_v0", "paths": values}))
with patch.dict(os.environ, {"NEXTGPT_MANIFEST": str(manifest)}):
with self.assertRaises(FileNotFoundError):
resolve_paths()
if __name__ == "__main__":
unittest.main()