mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 07:05:43 -03:00
fix(portable): use project root for settings storage
This commit is contained in:
@@ -74,9 +74,17 @@ sys.modules['nodes'] = nodes_mock
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _isolate_settings_dir(tmp_path_factory, monkeypatch):
|
||||
def _isolate_settings_dir(tmp_path_factory, monkeypatch, request):
|
||||
"""Redirect settings.json into a temporary directory for each test."""
|
||||
|
||||
if request.node.get_closest_marker("no_settings_dir_isolation"):
|
||||
from py.services import settings_manager as settings_manager_module
|
||||
|
||||
settings_manager_module.reset_settings_manager()
|
||||
yield
|
||||
settings_manager_module.reset_settings_manager()
|
||||
return
|
||||
|
||||
settings_dir = tmp_path_factory.mktemp("settings_dir")
|
||||
|
||||
def fake_get_settings_dir(create: bool = True) -> str:
|
||||
|
||||
@@ -11,6 +11,37 @@ from py.services.settings_manager import SettingsManager
|
||||
from py.utils import settings_paths
|
||||
|
||||
|
||||
@pytest.mark.no_settings_dir_isolation
|
||||
def test_portable_settings_use_project_root(tmp_path, monkeypatch):
|
||||
from importlib import reload
|
||||
|
||||
settings_paths_module = reload(settings_paths)
|
||||
monkeypatch.setattr(settings_paths_module, "get_project_root", lambda: str(tmp_path))
|
||||
monkeypatch.setattr(
|
||||
settings_paths_module,
|
||||
"user_config_dir",
|
||||
lambda *_args, **_kwargs: str(tmp_path / "user_config"),
|
||||
)
|
||||
|
||||
portable_settings = {"use_portable_settings": True}
|
||||
(tmp_path / "settings.json").write_text(json.dumps(portable_settings), encoding="utf-8")
|
||||
|
||||
config_dir = settings_paths_module.get_settings_dir(create=True)
|
||||
assert config_dir == str(tmp_path)
|
||||
|
||||
from py.services import persistent_model_cache as persistent_model_cache_module
|
||||
|
||||
cache_module = reload(persistent_model_cache_module)
|
||||
monkeypatch.setattr(cache_module.PersistentModelCache, "_instances", {})
|
||||
monkeypatch.delenv("LORA_MANAGER_CACHE_DB", raising=False)
|
||||
|
||||
cache = cache_module.PersistentModelCache(library_name="portable_lib")
|
||||
expected_cache_path = tmp_path / "model_cache" / "portable_lib.sqlite"
|
||||
|
||||
assert cache.get_database_path() == str(expected_cache_path)
|
||||
assert expected_cache_path.parent.is_dir()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def manager(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(SettingsManager, "_save_settings", lambda self: None)
|
||||
|
||||
Reference in New Issue
Block a user