c498d9b1c9
CI / Lint, Typecheck & Test (push) Successful in 2m3s
放宽 yaml_loader 校验允许有 needs 无 cmd/fn 的聚合 job, 完善 pymake.yaml 覆盖原 pymake.py 所有别名, 新增 reset_icon_cache_run fn 与 reseticoncache.yaml, 删除 pymake.py/reseticoncache.py 及对应 scripts 入口, 修复 --list 在 subcommands 模式下的可达性 bug.
59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
"""Tests for reseticoncache tool (reset_icon_cache_run 函数)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
|
|
import pytest
|
|
|
|
from pyflowx.conditions import Constants
|
|
from pyflowx.ops.system import reset_icon_cache_run
|
|
|
|
|
|
class TestResetIconCacheRun:
|
|
"""``reset_icon_cache_run`` 函数测试."""
|
|
|
|
def test_non_windows_skips(self, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
|
|
"""非 Windows 平台应打印提示并跳过."""
|
|
monkeypatch.setattr(Constants, "IS_WINDOWS", False)
|
|
reset_icon_cache_run()
|
|
captured = capsys.readouterr()
|
|
assert "仅在 Windows 上支持" in captured.out
|
|
|
|
def test_windows_no_localappdata_skips(
|
|
self, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
) -> None:
|
|
"""Windows 上 LOCALAPPDATA 未设置时应跳过."""
|
|
monkeypatch.setattr(Constants, "IS_WINDOWS", True)
|
|
monkeypatch.setattr("os.environ.get", lambda key, default="": "" if key == "LOCALAPPDATA" else default)
|
|
reset_icon_cache_run()
|
|
captured = capsys.readouterr()
|
|
assert "LOCALAPPDATA" in captured.out
|
|
|
|
def test_windows_executes_all_steps(
|
|
self, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
) -> None:
|
|
"""Windows 上应依次执行 kill/delete/delete_all/restart 四步."""
|
|
monkeypatch.setattr(Constants, "IS_WINDOWS", True)
|
|
local_app_data = "/tmp/fake_local_app_data"
|
|
monkeypatch.setattr(
|
|
"os.environ.get", lambda key, default="": local_app_data if key == "LOCALAPPDATA" else default
|
|
)
|
|
|
|
# 让 icon_cache_db 和 explorer_cache_dir 都不存在, 跳过删除分支
|
|
from pathlib import Path
|
|
|
|
monkeypatch.setattr(Path, "exists", lambda _self: False)
|
|
|
|
ran_cmds: list[list[str]] = []
|
|
monkeypatch.setattr(subprocess, "run", lambda cmd, **_: ran_cmds.append(cmd))
|
|
|
|
reset_icon_cache_run()
|
|
captured = capsys.readouterr()
|
|
|
|
# 验证执行了 kill_explorer 和 restart_explorer (delete 分支因 exists=False 被跳过)
|
|
assert any("taskkill" in str(cmd) for cmd in ran_cmds)
|
|
assert any("explorer.exe" in str(cmd) for cmd in ran_cmds)
|
|
assert any("start" in str(cmd) and "explorer.exe" in str(cmd) for cmd in ran_cmds)
|
|
assert "图标缓存已重置" in captured.out
|