mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-10-12 12:32:11 -03:00
test: fold the last Windows path and label assumptions
Second pass over the informational Windows job (91 failures -> 11 -> 0):
* `_identity`/`_fold` now wrap the assertions my first sweep skipped: the
parenthesised and multi-line ones, and the ones whose token list was
incomplete (`base_models_roots`, `embeddings_roots`).
* The reconciler's `current_name` and `active_roots` carry the drive-prefixed
label on Windows ("C: loras"), so the last direct comparison goes through
`_root_label_names` too.
* `open_settings_location` reveals the settings *file* with
`explorer /select,` on Windows instead of opening the containing folder, so
that test asserts the platform's call instead of the POSIX one.
* Three more expectations are written in the business form the code returns
(metadata payload, extracted download paths, hydrated preview URL).
This commit is contained in:
@@ -36,6 +36,12 @@ def _normalize(path) -> str:
|
||||
return os.path.normpath(str(path)).replace(os.sep, "/")
|
||||
|
||||
|
||||
def _fold(paths):
|
||||
"""Compare path lists as identities: the code may hand out either spelling."""
|
||||
|
||||
return [_normalize(path) for path in paths]
|
||||
|
||||
|
||||
class TestAppendNewPaths:
|
||||
def test_appends_without_reordering_or_duplicating(self):
|
||||
merged = config_module._append_new_paths(
|
||||
@@ -60,17 +66,17 @@ class TestAdmitConfiguredRoots:
|
||||
loras_roots=[str(primary)],
|
||||
_configured_root_paths={"lora": [str(primary), str(drive)]},
|
||||
)
|
||||
assert config.configured_roots_for("lora") == [_normalize(primary), _normalize(drive)]
|
||||
assert _fold(config.configured_roots_for("lora")) == _fold([primary, drive])
|
||||
|
||||
# Still switched off: nothing to admit.
|
||||
assert config.admit_configured_roots() == []
|
||||
assert config.loras_roots == [_normalize(primary)]
|
||||
assert _fold(config.loras_roots) == _fold([primary])
|
||||
|
||||
drive.mkdir(parents=True)
|
||||
admitted = config.admit_configured_roots()
|
||||
|
||||
assert admitted == [_normalize(drive)]
|
||||
assert config.loras_roots == [_normalize(primary), _normalize(drive)]
|
||||
assert _fold(admitted) == _fold([drive])
|
||||
assert _fold(config.loras_roots) == _fold([primary, drive])
|
||||
# Idempotent: a second call adds nothing.
|
||||
assert config.admit_configured_roots() == []
|
||||
|
||||
@@ -91,7 +97,7 @@ class TestAdmitConfiguredRoots:
|
||||
drive.rmdir()
|
||||
config.admit_configured_roots()
|
||||
|
||||
assert config.loras_roots == [_normalize(primary), _normalize(drive)]
|
||||
assert _fold(config.loras_roots) == _fold([primary, drive])
|
||||
|
||||
def test_admits_every_model_type_and_its_side_maps(self, tmp_path):
|
||||
checkpoint_dir = tmp_path / "checkpoints"
|
||||
|
||||
@@ -361,13 +361,11 @@ def test_save_paths_removes_template_default_library(monkeypatch, tmp_path):
|
||||
}
|
||||
assert _identity(payload["folder_paths"]) == _identity(expected_folder_paths)
|
||||
assert _identity(payload["default_lora_root"]) == _identity(folder_paths["loras"][0].replace("\\", "/"))
|
||||
assert (
|
||||
payload["default_checkpoint_root"]
|
||||
== folder_paths["checkpoints"][0].replace("\\", "/")
|
||||
assert _identity(payload["default_checkpoint_root"]) == _identity(
|
||||
folder_paths["checkpoints"][0].replace("\\", "/")
|
||||
)
|
||||
assert (
|
||||
payload["default_embedding_root"]
|
||||
== folder_paths["embeddings"][0].replace("\\", "/")
|
||||
assert _identity(payload["default_embedding_root"]) == _identity(
|
||||
folder_paths["embeddings"][0].replace("\\", "/")
|
||||
)
|
||||
assert _identity(payload["metadata"]) == _identity({"display_name": "ComfyUI", "source": "comfyui"})
|
||||
assert payload["activate"] is True
|
||||
@@ -419,12 +417,12 @@ def test_save_paths_keeps_default_roots_in_extra_paths(monkeypatch: pytest.Monke
|
||||
|
||||
assert fake_settings.name == "comfyui"
|
||||
assert _identity(fake_settings.payload["extra_folder_paths"]["loras"]) == _identity([str(extra_lora_dir).replace("\\", "/")])
|
||||
assert fake_settings.payload["extra_folder_paths"]["checkpoints"] == [
|
||||
assert _identity(fake_settings.payload["extra_folder_paths"]["checkpoints"]) == _identity([
|
||||
str(extra_checkpoint_dir).replace("\\", "/")
|
||||
]
|
||||
assert fake_settings.payload["extra_folder_paths"]["embeddings"] == [
|
||||
])
|
||||
assert _identity(fake_settings.payload["extra_folder_paths"]["embeddings"]) == _identity([
|
||||
str(extra_embedding_dir).replace("\\", "/")
|
||||
]
|
||||
])
|
||||
assert _identity(fake_settings.payload["default_lora_root"]) == _identity(str(extra_lora_dir).replace("\\", "/"))
|
||||
assert _identity(fake_settings.payload["default_checkpoint_root"]) == _identity(str(extra_checkpoint_dir).replace("\\", "/"))
|
||||
assert _identity(fake_settings.payload["default_embedding_root"]) == _identity(str(extra_embedding_dir).replace("\\", "/"))
|
||||
@@ -608,9 +606,9 @@ def test_apply_library_settings_merges_extra_paths(monkeypatch, tmp_path):
|
||||
|
||||
assert _identity(str(loras_dir)) in _identity(config_instance.loras_roots)
|
||||
assert _identity(str(extra_loras_dir)) in _identity(config_instance.extra_loras_roots)
|
||||
assert str(checkpoints_dir) in config_instance.base_models_roots
|
||||
assert _identity(str(checkpoints_dir)) in _identity(config_instance.base_models_roots)
|
||||
assert _identity(str(extra_checkpoints_dir)) in _identity(config_instance.extra_checkpoints_roots)
|
||||
assert str(embeddings_dir) in (config_instance.embeddings_roots or [])
|
||||
assert _identity(str(embeddings_dir)) in _identity((config_instance.embeddings_roots or []))
|
||||
assert _identity(str(extra_embeddings_dir)) in _identity(config_instance.extra_embeddings_roots)
|
||||
|
||||
|
||||
@@ -640,9 +638,9 @@ def test_apply_library_settings_without_extra_paths(monkeypatch, tmp_path):
|
||||
|
||||
assert _identity(str(loras_dir)) in _identity(config_instance.loras_roots)
|
||||
assert _identity(config_instance.extra_loras_roots) == _identity([])
|
||||
assert str(checkpoints_dir) in config_instance.base_models_roots
|
||||
assert _identity(str(checkpoints_dir)) in _identity(config_instance.base_models_roots)
|
||||
assert _identity(config_instance.extra_checkpoints_roots) == _identity([])
|
||||
assert str(embeddings_dir) in (config_instance.embeddings_roots or [])
|
||||
assert _identity(str(embeddings_dir)) in _identity((config_instance.embeddings_roots or []))
|
||||
assert _identity(config_instance.extra_embeddings_roots) == _identity([])
|
||||
|
||||
|
||||
|
||||
@@ -788,7 +788,11 @@ async def test_open_settings_location_with_display_opens_folder(tmp_path, monkey
|
||||
|
||||
assert response.status == 200
|
||||
assert payload["success"] is True
|
||||
assert calls == [[_expected_opener(), str(settings_file.parent)]]
|
||||
if os.name == "nt":
|
||||
# explorer reveals the file itself, there is no "open the folder" call.
|
||||
assert calls == [["explorer", "/select,", str(settings_file)]]
|
||||
else:
|
||||
assert calls == [[_expected_opener(), str(settings_file.parent)]]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -1237,7 +1237,7 @@ async def test_download_hydrates_the_card_from_the_site(tmp_path, monkeypatch):
|
||||
"https://resources.modelscope.cn/cover-images/b.png",
|
||||
"https://resources.modelscope.cn/cover-images/c.png",
|
||||
]
|
||||
assert saved["preview_url"] == str(tmp_path / "preview.webp")
|
||||
assert saved["preview_url"] == str(tmp_path / "preview.webp").replace(os.sep, "/")
|
||||
assert saved["usage_tips"] == (
|
||||
'{"strength_min": 0.5, "strength_max": 1.2, "strength_range": "0.5-1.2"}'
|
||||
)
|
||||
|
||||
@@ -617,10 +617,10 @@ async def test_execute_download_extracts_zip_multiple_models(monkeypatch, tmp_pa
|
||||
assert dummy_scanner.add_model_to_cache.await_count == 2
|
||||
|
||||
metadata_calls = MetadataManager.save_metadata.await_args_list
|
||||
assert metadata_calls[0].args[0] == str(extracted_one)
|
||||
assert metadata_calls[0].args[0] == str(extracted_one).replace(os.sep, "/")
|
||||
# SHA256 comes from metadata (API value), not recalculated
|
||||
assert metadata_calls[0].args[1].sha256 == "sha256"
|
||||
assert metadata_calls[1].args[0] == str(extracted_two)
|
||||
assert metadata_calls[1].args[0] == str(extracted_two).replace(os.sep, "/")
|
||||
assert metadata_calls[1].args[1].sha256 == "sha256"
|
||||
|
||||
|
||||
|
||||
@@ -2495,7 +2495,7 @@ async def test_reconcile_walk_broadcasts_per_root_progress(tmp_path: Path, monke
|
||||
assert final["roots_total"] == 1
|
||||
assert final["roots_done"] == 1
|
||||
assert final["active_roots"] == []
|
||||
assert final["current_name"] == "loras"
|
||||
assert _root_label_names([final["current_name"]]) == ["loras"]
|
||||
assert 0 < final["progress"] <= 50
|
||||
assert final["full_rebuild"] is False
|
||||
assert walk_messages[0]["progress"] <= final["progress"]
|
||||
|
||||
@@ -60,7 +60,7 @@ async def test_load_metadata_payload_restores_file_facts_when_sidecar_missing(
|
||||
payload = await MetadataManager.load_metadata_payload(str(model_path))
|
||||
|
||||
stat_result = model_path.stat()
|
||||
assert payload["file_path"] == str(model_path)
|
||||
assert payload["file_path"] == str(model_path).replace(os.sep, "/")
|
||||
assert payload["file_name"] == "MyModel"
|
||||
assert payload["size"] == stat_result.st_size
|
||||
assert payload["modified"] == stat_result.st_mtime
|
||||
|
||||
Reference in New Issue
Block a user