diff --git a/gates/profiles.py b/gates/profiles.py index 3f57ee2..17d4051 100644 --- a/gates/profiles.py +++ b/gates/profiles.py @@ -70,3 +70,13 @@ def rename_profile(base, pid, name): entry["name"] = name write_registry(base, reg) return entry + + +def delete_profile(base, pid): + reg = read_registry(base) + reg["profiles"] = [p for p in reg["profiles"] if p["id"] != pid] + write_registry(base, reg) + d = Path(base) / pid + if d.exists(): + shutil.rmtree(d) + return reg diff --git a/tests/test_profiles.py b/tests/test_profiles.py index 8e15314..62f9a6f 100644 --- a/tests/test_profiles.py +++ b/tests/test_profiles.py @@ -47,3 +47,10 @@ def test_rename_to_existing_name_raises(tmp_path): pr.create_profile(str(tmp_path), "b", "id2") with pytest.raises(ValueError): pr.rename_profile(str(tmp_path), "id2", "a") + +def test_delete_profile_removes_dir_and_entry(tmp_path): + pr.create_profile(str(tmp_path), "a", "id1") + (tmp_path / "id1" / "img_0001.png").write_bytes(b"x") + pr.delete_profile(str(tmp_path), "id1") + assert not (tmp_path / "id1").exists() + assert pr.find_by_id(pr.read_registry(str(tmp_path)), "id1") is None