Files
wehub-resource-sync 770d92cb1f
Lint / lint (push) Has been cancelled
Build Docs / Deploy Docs (push) Has been cancelled
Windows CI / Windows (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:23:58 +08:00

44 lines
1.1 KiB
Python

import json
import tempfile
from pathlib import Path
import pytest
from mlc_llm.support import logging
from mlc_llm.support.auto_config import detect_config
logging.enable_logging()
# test category "unittest"
pytestmark = [pytest.mark.unittest]
def _create_json_file(json_path, data):
with open(json_path, "w", encoding="utf-8") as i_f:
json.dump(data, i_f)
def test_detect_config():
with tempfile.TemporaryDirectory() as tmpdir:
base_path = Path(tmpdir)
config_json_path = base_path / "config.json"
_create_json_file(config_json_path, {})
assert detect_config(base_path) == config_json_path
assert detect_config(config_json_path) == config_json_path
def test_detect_config_fail():
with pytest.raises(ValueError):
detect_config(Path("do/not/exist"))
with tempfile.TemporaryDirectory() as tmpdir:
base_path = Path(tmpdir)
with pytest.raises(ValueError):
assert detect_config(base_path)
if __name__ == "__main__":
test_detect_config()
test_detect_config_fail()