31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
"""验证 Nano 启动前的模型包校验,无需 GPU。"""
|
|
import importlib.util
|
|
import json
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
|
|
SCRIPT = Path(__file__).resolve().parents[2] / "tools/start_d3_lite_local.py"
|
|
spec = importlib.util.spec_from_file_location("djev_launcher", SCRIPT)
|
|
launcher = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(launcher)
|
|
|
|
|
|
class NanoPackageChecks(unittest.TestCase):
|
|
def test_accepts_only_nano_in_the_given_root(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory) / "D3Nano"
|
|
(root / "model").mkdir(parents=True)
|
|
# 存量档位配置不能重定向模型路径。
|
|
(root / "djev.json").write_text('{"tier":"lite","lite_root":"../D3Lite"}', encoding="utf-8")
|
|
manifest = root / "model" / "MODEL_MANIFEST.json"
|
|
manifest.write_text(json.dumps({"model_name": "d3-nano"}), encoding="utf-8")
|
|
launcher.verify_nano_package(root)
|
|
manifest.write_text(json.dumps({"model_name": "d3-lite"}), encoding="utf-8")
|
|
with self.assertRaisesRegex(ValueError, "Expected d3-nano"):
|
|
launcher.verify_nano_package(root)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|