Skip to content

Commit 1bd22d5

Browse files
committed
Add test coverage for new code
1 parent b418ddb commit 1bd22d5

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/manage/install_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def print_cli_shortcuts(cmd):
351351
verbose = LOGGER.would_log_to_console(VERBOSE)
352352
for i in installs:
353353
# We need to pre-filter aliases before getting the nice names.
354-
aliases = [a for a in i["alias"] if a["name"].casefold() not in seen]
354+
aliases = [a for a in i.get("alias", ()) if a["name"].casefold() not in seen]
355355
seen.update(n["name"].casefold() for n in aliases)
356356
if not verbose:
357357
if i.get("default"):

tests/conftest.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def make_install(tag, **kwargs):
201201
run_for.append({"tag": t, "target": kwargs.get("target", "python.exe")})
202202
run_for.append({"tag": t, "target": kwargs.get("targetw", "pythonw.exe"), "windowed": 1})
203203

204-
return {
204+
i = {
205205
"company": kwargs.get("company", "PythonCore"),
206206
"id": "{}-{}".format(kwargs.get("company", "PythonCore"), tag),
207207
"sort-version": kwargs.get("sort_version", tag),
@@ -212,12 +212,17 @@ def make_install(tag, **kwargs):
212212
"prefix": PurePath(kwargs.get("prefix", rf"C:\{tag}")),
213213
"executable": kwargs.get("executable", "python.exe"),
214214
}
215+
try:
216+
i["alias"] = kwargs["alias"]
217+
except LookupError:
218+
pass
219+
return i
215220

216221

217222
def fake_get_installs(install_dir):
218223
yield make_install("1.0")
219-
yield make_install("1.0-32", sort_version="1.0")
220-
yield make_install("1.0-64", sort_version="1.0")
224+
yield make_install("1.0-32", sort_version="1.0", alias=[dict(name="py1.0.exe"), dict(name="py1.0-32.exe")])
225+
yield make_install("1.0-64", sort_version="1.0", alias=[dict(name="py1.0.exe"), dict(name="py1.0-64.exe")])
221226
yield make_install("2.0-64", sort_version="2.0")
222227
yield make_install("2.0-arm64", sort_version="2.0")
223228
yield make_install("3.0a1-32", sort_version="3.0a1")

tests/test_install_command.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import pytest
22
import secrets
3+
from pathlib import PurePath
4+
35
from manage import install_command as IC
6+
from manage import installs
47

58

69
@pytest.fixture
710
def alias_checker(tmp_path):
811
with AliasChecker(tmp_path) as checker:
912
yield checker
1013

14+
1115
class AliasChecker:
1216
class Cmd:
1317
global_dir = "out"
@@ -95,3 +99,18 @@ def test_write_alias_default_platform(alias_checker):
9599
def test_write_alias_fallback_platform(alias_checker):
96100
alias_checker.check_64(alias_checker.Cmd("-spam"), "1.0", "testA")
97101
alias_checker.check_w64(alias_checker.Cmd("-spam"), "1.0", "testB")
102+
103+
104+
def test_print_cli_shortcuts(patched_installs, assert_log):
105+
class Cmd:
106+
global_dir = None
107+
def get_installs(self):
108+
return installs.get_installs(None)
109+
110+
IC.print_cli_shortcuts(Cmd())
111+
print(assert_log)
112+
assert_log(
113+
assert_log.skip_until("Installed %s", ["Python 2.0-64", PurePath("C:\\2.0-64")]),
114+
assert_log.skip_until("%s will be launched by %s", ["Python 1.0-64", "py1.0[-64].exe"]),
115+
("%s will be launched by %s", ["Python 1.0-32", "py1.0-32.exe"]),
116+
)

0 commit comments

Comments
 (0)