Skip to content

Commit 0ce2ebd

Browse files
committed
Add tests
1 parent 05ab3de commit 0ce2ebd

File tree

2 files changed

+99
-2
lines changed

2 files changed

+99
-2
lines changed

src/manage/install_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def _calc(prefix, filename, calculate_dest=calculate_dest):
216216

217217

218218
def _if_exists(launcher, plat):
219-
plat_launcher = launcher.parent / f"{launcher.stem}{plat}.exe"
219+
plat_launcher = launcher.parent / f"{launcher.stem}{plat}{launcher.suffix}"
220220
if plat_launcher.is_file():
221221
return plat_launcher
222222
return launcher
@@ -238,7 +238,7 @@ def _write_alias(cmd, install, alias, target):
238238
launcher = _if_exists(launcher, cmd.default_platform)
239239
if not launcher.is_file():
240240
LOGGER.debug("Checking for launcher for -64")
241-
launcher = _if_exists(launcher, "64")
241+
launcher = _if_exists(launcher, "-64")
242242
LOGGER.debug("Create %s linking to %s using %s", alias["name"], target, launcher)
243243
if not launcher or not launcher.is_file():
244244
LOGGER.warn("Skipping %s alias because the launcher template was not found.", alias["name"])

tests/test_install_command.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import pytest
2+
import secrets
3+
from manage import install_command as IC
4+
5+
6+
@pytest.fixture
7+
def alias_checker(tmp_path):
8+
with AliasChecker(tmp_path) as checker:
9+
yield checker
10+
11+
class AliasChecker:
12+
class Cmd:
13+
global_dir = "out"
14+
launcher_exe = "launcher.txt"
15+
launcherw_exe = "launcherw.txt"
16+
default_platform = "-64"
17+
18+
def __init__(self, platform=None):
19+
if platform:
20+
self.default_platform = platform
21+
22+
23+
def __init__(self, tmp_path):
24+
self.Cmd.global_dir = tmp_path / "out"
25+
self.Cmd.launcher_exe = tmp_path / "launcher.txt"
26+
self.Cmd.launcherw_exe = tmp_path / "launcherw.txt"
27+
self._expect_target = "target-" + secrets.token_hex(32)
28+
self._expect = {
29+
"-32": "-32-" + secrets.token_hex(32),
30+
"-64": "-64-" + secrets.token_hex(32),
31+
"-arm64": "-arm64-" + secrets.token_hex(32),
32+
"w-32": "w-32-" + secrets.token_hex(32),
33+
"w-64": "w-64-" + secrets.token_hex(32),
34+
"w-arm64": "w-arm64-" + secrets.token_hex(32),
35+
}
36+
for k, v in self._expect.items():
37+
(tmp_path / f"launcher{k}.txt").write_text(v)
38+
39+
def __enter__(self):
40+
return self
41+
42+
def __exit__(self, *exc_info):
43+
pass
44+
45+
def check(self, cmd, tag, name, expect, windowed=0):
46+
IC._write_alias(
47+
cmd,
48+
{"tag": tag},
49+
{"name": f"{name}.txt", "windowed": windowed},
50+
self._expect_target,
51+
)
52+
print(*cmd.global_dir.glob("*"), sep="\n")
53+
assert (cmd.global_dir / f"{name}.txt").is_file()
54+
assert (cmd.global_dir / f"{name}.txt.__target__").is_file()
55+
assert (cmd.global_dir / f"{name}.txt").read_text() == expect
56+
assert (cmd.global_dir / f"{name}.txt.__target__").read_text() == self._expect_target
57+
58+
def check_32(self, cmd, tag, name):
59+
self.check(cmd, tag, name, self._expect["-32"])
60+
61+
def check_w32(self, cmd, tag, name):
62+
self.check(cmd, tag, name, self._expect["w-32"], windowed=1)
63+
64+
def check_64(self, cmd, tag, name):
65+
self.check(cmd, tag, name, self._expect["-64"])
66+
67+
def check_w64(self, cmd, tag, name):
68+
self.check(cmd, tag, name, self._expect["w-64"], windowed=1)
69+
70+
def check_arm64(self, cmd, tag, name):
71+
self.check(cmd, tag, name, self._expect["-arm64"])
72+
73+
def check_warm64(self, cmd, tag, name):
74+
self.check(cmd, tag, name, self._expect["w-arm64"], windowed=1)
75+
76+
77+
def test_write_alias_tag_with_platform(alias_checker):
78+
alias_checker.check_32(alias_checker.Cmd, "1.0-32", "testA")
79+
alias_checker.check_w32(alias_checker.Cmd, "1.0-32", "testB")
80+
alias_checker.check_64(alias_checker.Cmd, "1.0-64", "testC")
81+
alias_checker.check_w64(alias_checker.Cmd, "1.0-64", "testD")
82+
alias_checker.check_arm64(alias_checker.Cmd, "1.0-arm64", "testE")
83+
alias_checker.check_warm64(alias_checker.Cmd, "1.0-arm64", "testF")
84+
85+
86+
def test_write_alias_default_platform(alias_checker):
87+
alias_checker.check_32(alias_checker.Cmd("-32"), "1.0", "testA")
88+
alias_checker.check_w32(alias_checker.Cmd("-32"), "1.0", "testB")
89+
alias_checker.check_64(alias_checker.Cmd, "1.0", "testC")
90+
alias_checker.check_w64(alias_checker.Cmd, "1.0", "testD")
91+
alias_checker.check_arm64(alias_checker.Cmd("-arm64"), "1.0", "testE")
92+
alias_checker.check_warm64(alias_checker.Cmd("-arm64"), "1.0", "testF")
93+
94+
95+
def test_write_alias_fallback_platform(alias_checker):
96+
alias_checker.check_64(alias_checker.Cmd("-spam"), "1.0", "testA")
97+
alias_checker.check_w64(alias_checker.Cmd("-spam"), "1.0", "testB")

0 commit comments

Comments
 (0)