27 lines
953 B
Python
27 lines
953 B
Python
import json
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from localpilot.config import AppConfig, ModelConfig, infer_kind, load_config
|
|
|
|
|
|
class ConfigTests(unittest.TestCase):
|
|
def test_infer_extensions(self) -> None:
|
|
self.assertEqual(infer_kind(ModelConfig(id="x", path="E:/x/model.gguf")), "gguf")
|
|
self.assertEqual(infer_kind(ModelConfig(id="x", path="E:/x/model.onnx")), "onnx")
|
|
self.assertEqual(infer_kind(ModelConfig(id="x", kind="cloud")), "cloud")
|
|
|
|
def test_load_config(self) -> None:
|
|
with tempfile.TemporaryDirectory() as folder:
|
|
path = Path(folder) / "config.json"
|
|
path.write_text(json.dumps({"models": [{"id": "x", "kind": "gguf", "path": "x.gguf"}]}), encoding="utf-8")
|
|
config = load_config(path)
|
|
self.assertIsInstance(config, AppConfig)
|
|
self.assertEqual(config.models[0].id, "x")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|
|
|