From dd69bc88b1d39f16830cdba7586668adcf343d58 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Sat, 11 Jul 2026 20:04:45 +0900 Subject: [PATCH] chore: add shortcut tests --- tests/fixtures/api/no_shortcuts.vdf | Bin 0 -> 13 bytes tests/test_shortcuts.py | 67 ++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 tests/fixtures/api/no_shortcuts.vdf create mode 100644 tests/test_shortcuts.py diff --git a/tests/fixtures/api/no_shortcuts.vdf b/tests/fixtures/api/no_shortcuts.vdf new file mode 100644 index 0000000000000000000000000000000000000000..7ca09eb675aa0b38626e4e55558a4f94f3ae331e GIT binary patch literal 13 UcmZQ5&d4t+NiHoZX5ioe03Un=00000 literal 0 HcmV?d00001 diff --git a/tests/test_shortcuts.py b/tests/test_shortcuts.py new file mode 100644 index 0000000..60ab7b9 --- /dev/null +++ b/tests/test_shortcuts.py @@ -0,0 +1,67 @@ +import pytest +import tempfile + +from pathlib import Path +from _pytest.monkeypatch import MonkeyPatch + +from dzgui.api.shortcuts import Shortcuts +from tests.fixtures import fixture_path + +pytestmark = pytest.mark.apitest + + +def mock_find_shortcuts(self, steam_path: Path) -> Path: + return Path(fixture_path("api/no_shortcuts.vdf")) + + +@pytest.fixture(scope="module", autouse=True) +def patch_api() -> None: + mp = MonkeyPatch() + mp.setattr("dzgui.api.shortcuts.Shortcuts.find_shortcuts_path", mock_find_shortcuts) + yield + mp.undo() + + +def test_no_shortcuts(monkeypatch) -> None: + s = Shortcuts(Path("")) + assert len(s.shortcuts["shortcuts"]) == 0 + + +@pytest.fixture +def dummy_app() -> None: + d = { + "appname": "TEST APP", + "StartDir": "TEST_DIR", + "exe": "TEST_DIR/TEST_EXE.EXE", + "icon": "IMAGES_DIR/TEST_IMAGE.PNG", + } + return d + + +def test_wrap_exe(dummy_app) -> None: + s = Shortcuts(Path("")) + s.add_shortcut(*dummy_app.values()) + assert s.shortcuts["shortcuts"]["0"]["exe"][0] == '"' + assert s.shortcuts["shortcuts"]["0"]["exe"][-1] == '"' + + +def test_add_shortcut(dummy_app) -> None: + s = Shortcuts(Path("")) + s.add_shortcut(*dummy_app.values()) + new = s.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 + + +def test_save_shortcut(dummy_app) -> None: + s = Shortcuts(Path("")) + s.add_shortcut(*dummy_app.values()) + 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