chore: clear typehinting errors

This commit is contained in:
aclist committed 2026-11-12 07:10:27 +09:00
1 parent 3e7b49203a
commit f7d95d5407
11 files changed
+99 -61

No files matched your search

+36 -37
View File
@@ -1,10 +1,11 @@
import pytest
import tempfile
from typing import TYPE_CHECKING
from pathlib import Path
from _pytest.monkeypatch import MonkeyPatch
from collections.abc import Iterator
from pathlib import Path
from typing import Any, cast, TYPE_CHECKING
from dzgui.api.shortcuts import Shortcuts
from tests.fixtures import fixture_path
@@ -15,12 +16,12 @@ if TYPE_CHECKING:
pytestmark = pytest.mark.apitest
def mock_find_shortcuts(self, steam_path: Path) -> Path:
def mock_find_shortcuts(self: Shortcuts, steam_path: Path) -> Path:
return Path(fixture_path("api/no_shortcuts.vdf"))
@pytest.fixture(scope="module", autouse=True)
def patch_api() -> None:
def patch_api() -> Iterator[None]:
mp = MonkeyPatch()
mp.setattr("dzgui.api.shortcuts.Shortcuts.find_shortcuts_path", mock_find_shortcuts)
yield
@@ -33,64 +34,62 @@ def test_no_shortcuts(monkeypatch: "MonkeyPatch") -> None:
@pytest.fixture
def dummy_app() -> dict[str, str]:
def dummy_app() -> dict[str, Any]:
d = {
"AppName": "TEST APP",
"StartDir": "TEST_DIR",
"Exe": "TEST_DIR/TEST_EXE.EXE",
"icon": "IMAGES_DIR/TEST_IMAGE.PNG",
"StartDir": Path("TEST_DIR"),
"Exe": Path("TEST_DIR/TEST_EXE.EXE"),
"icon": Path("IMAGES_DIR/TEST_IMAGE.PNG"),
}
return d
def test_wrap_exe(dummy_app: dict[str, str]) -> None:
@pytest.fixture
def shortcuts(dummy_app: dict[str, Any]) -> Shortcuts:
s = Shortcuts(Path(""))
s.add_shortcut(*dummy_app.values())
assert s.shortcuts["shortcuts"]["0"]["Exe"][0] == '"'
assert s.shortcuts["shortcuts"]["0"]["Exe"][-1] == '"'
args = cast(tuple[str, Path, Path, Path], dummy_app.values())
s.add_shortcut(*args)
return s
def test_add_shortcut(dummy_app: dict[str, str]) -> None:
s = Shortcuts(Path(""))
s.add_shortcut(*dummy_app.values())
new = s.shortcuts["shortcuts"]
def test_wrap_exe(shortcuts: Shortcuts) -> None:
assert shortcuts.shortcuts["shortcuts"]["0"]["Exe"][0] == '"'
assert shortcuts.shortcuts["shortcuts"]["0"]["Exe"][-1] == '"'
def test_add_shortcut(shortcuts: Shortcuts, dummy_app: dict[str, Any]) -> None:
new = shortcuts.shortcuts["shortcuts"]
ind = str(len(new) - 1)
for k, v in dummy_app.items():
if k == "Exe":
v = f'"{v}"'
assert new[ind][k] == v
assert new[ind][k] == str(v)
def test_save_shortcut(dummy_app: dict[str, str]) -> None:
s = Shortcuts(Path(""))
s.add_shortcut(*dummy_app.values())
def test_save_shortcut(shortcuts: Shortcuts) -> None:
with tempfile.NamedTemporaryFile() as f:
tmp = Path(f.name)
s.shortcuts_path = tmp
s.save_shortcuts()
s._load_shortcuts(tmp)
assert len(s.shortcuts["shortcuts"]) == 1
shortcuts.shortcuts_path = tmp
shortcuts.save_shortcuts()
shortcuts._load_shortcuts(tmp)
assert len(shortcuts.shortcuts["shortcuts"]) == 1
def test_shortcut_crc(dummy_app: dict[str, str]) -> None:
s = Shortcuts(Path(""))
s.add_shortcut(*dummy_app.values())
for key in s.shortcuts["shortcuts"].keys():
entry = s.shortcuts["shortcuts"][key]
def test_shortcut_crc(shortcuts: Shortcuts) -> None:
for key in shortcuts.shortcuts["shortcuts"].keys():
entry = shortcuts.shortcuts["shortcuts"][key]
name = entry["AppName"]
exe = entry["Exe"]
uid = name + exe
bpid = s.gen_bpid(uid)
bpid = shortcuts.gen_bpid(uid)
assert entry["appid"] & 0xFFFFFFFF == bpid
def test_reverse_crc(dummy_app: dict[str, str]) -> None:
s = Shortcuts(Path(""))
s.add_shortcut(*dummy_app.values())
for key in s.shortcuts["shortcuts"].keys():
entry = s.shortcuts["shortcuts"][key]
def test_reverse_crc(shortcuts: Shortcuts) -> None:
for key in shortcuts.shortcuts["shortcuts"].keys():
entry = shortcuts.shortcuts["shortcuts"][key]
name = entry["AppName"]
exe = entry["Exe"]
uid = name + exe
bpid = s.gen_bpid(uid)
assert s.find_appname_by_unsigned_id(bpid) == name
bpid = shortcuts.gen_bpid(uid)
assert shortcuts.find_appname_by_unsigned_id(bpid) == name