Skip to content

Commit 2c8b20c

Browse files
committed
Improved test coverage
1 parent c339db1 commit 2c8b20c

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

src/manage/install_command.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,15 @@ def _write_alias(cmd, install, alias, target, _link=os.link):
288288
if launcher2:
289289
try:
290290
_link(launcher2, p)
291+
LOGGER.debug("Created %s as hard link to %s", p.name, launcher2.name)
292+
except FileNotFoundError:
293+
raise
291294
except OSError:
292295
LOGGER.debug("Failed to create hard link from fallback launcher")
296+
try:
297+
launcher_bytes = launcher2.read_bytes()
298+
except OSError:
299+
LOGGER.debug("Failed to read fallback launcher", exc_info=True)
293300
launcher2 = None
294301
if not launcher2:
295302
try:

tests/test_install_command.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,73 @@ def read_bytes():
151151
assert_log(
152152
"Checking for launcher.*",
153153
"Create %s linking to %s",
154-
"Failed to read launcher template at %s.",
154+
"Failed to read launcher template at %s\\.",
155155
"Failed to read %s",
156156
assert_log.end_of_log(),
157157
)
158158

159159

160+
def test_write_alias_launcher_unlinkable(fake_config, assert_log, tmp_path):
161+
def fake_link(x, y):
162+
raise OSError("Error for testing")
163+
164+
fake_config.scratch = {}
165+
fake_config.launcher_exe = tmp_path / "launcher.txt"
166+
fake_config.launcher_exe.write_bytes(b'Arbitrary contents')
167+
fake_config.default_platform = '-32'
168+
fake_config.global_dir = tmp_path / "bin"
169+
IC._write_alias(
170+
fake_config,
171+
{"tag": "test"},
172+
{"name": "test.exe"},
173+
tmp_path / "target.exe",
174+
_link=fake_link
175+
)
176+
assert_log(
177+
"Checking for launcher.*",
178+
"Create %s linking to %s",
179+
"Failed to create hard link.+",
180+
"Created %s as copy of %s",
181+
assert_log.end_of_log(),
182+
)
183+
184+
185+
def test_write_alias_launcher_unlinkable_remap(fake_config, assert_log, tmp_path):
186+
# This is for the fairly expected case of the PyManager install being on one
187+
# drive, but the global commands directory being on another. In this
188+
# situation, we can't hard link directly into the app files, and will need
189+
# to copy. But we only need to copy once, so if a launcher_remap has been
190+
# set (in the current process), then we have an available copy already and
191+
# can link to that.
192+
193+
def fake_link(x, y):
194+
if x.match("launcher.txt"):
195+
raise OSError(17, "Error for testing")
196+
197+
fake_config.scratch = {
198+
"install_command._write_alias.launcher_remap": {"launcher.txt": tmp_path / "actual_launcher.txt"},
199+
}
200+
fake_config.launcher_exe = tmp_path / "launcher.txt"
201+
fake_config.launcher_exe.write_bytes(b'Arbitrary contents')
202+
(tmp_path / "actual_launcher.txt").write_bytes(b'Arbitrary contents')
203+
fake_config.default_platform = '-32'
204+
fake_config.global_dir = tmp_path / "bin"
205+
IC._write_alias(
206+
fake_config,
207+
{"tag": "test"},
208+
{"name": "test.exe"},
209+
tmp_path / "target.exe",
210+
_link=fake_link
211+
)
212+
assert_log(
213+
"Checking for launcher.*",
214+
"Create %s linking to %s",
215+
"Failed to create hard link.+",
216+
("Created %s as hard link to %s", ("test.exe", "actual_launcher.txt")),
217+
assert_log.end_of_log(),
218+
)
219+
220+
160221
@pytest.mark.parametrize("default", [1, 0])
161222
def test_write_alias_default(alias_checker, monkeypatch, tmp_path, default):
162223
prefix = Path(tmp_path) / "runtime"

0 commit comments

Comments
 (0)