59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
import os
|
|
import tempfile
|
|
import unittest
|
|
|
|
from faugus.shortcut_utils import build_desktop_entry, get_shortcut_icon_path
|
|
|
|
|
|
class ShortcutUtilsTest(unittest.TestCase):
|
|
def test_get_shortcut_icon_path_prefers_png(self):
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
png = os.path.join(tmpdir, "battlenet.png")
|
|
ico = os.path.join(tmpdir, "battlenet.ico")
|
|
with open(png, "wb") as f:
|
|
f.write(b"png")
|
|
with open(ico, "wb") as f:
|
|
f.write(b"ico")
|
|
|
|
path = get_shortcut_icon_path("battlenet", tmpdir, "/fallback.png")
|
|
self.assertEqual(path, png)
|
|
|
|
def test_get_shortcut_icon_path_falls_back_to_ico(self):
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
ico = os.path.join(tmpdir, "battlenet.ico")
|
|
with open(ico, "wb") as f:
|
|
f.write(b"ico")
|
|
|
|
path = get_shortcut_icon_path("battlenet", tmpdir, "/fallback.png")
|
|
self.assertEqual(path, ico)
|
|
|
|
def test_get_shortcut_icon_path_uses_fallback(self):
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
path = get_shortcut_icon_path("battlenet", tmpdir, "/fallback.png")
|
|
self.assertEqual(path, "/fallback.png")
|
|
|
|
def test_build_desktop_entry_includes_startup_wm_class(self):
|
|
entry = build_desktop_entry(
|
|
"Battle.net",
|
|
"faugus-run --game battlenet",
|
|
"/icons/battlenet.png",
|
|
"/games",
|
|
"battle.net.exe",
|
|
)
|
|
self.assertIn("StartupWMClass=battle.net.exe\n", entry)
|
|
self.assertIn("Icon=/icons/battlenet.png\n", entry)
|
|
|
|
def test_build_desktop_entry_omits_empty_startup_wm_class(self):
|
|
entry = build_desktop_entry(
|
|
"Game",
|
|
"faugus-run --game game",
|
|
"/icons/game.png",
|
|
"/games",
|
|
"",
|
|
)
|
|
self.assertNotIn("StartupWMClass=", entry)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|