Skip to content

Commit 44af4d3

Browse files
committed
Better override of startfile
1 parent d42e7f2 commit 44af4d3

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/manage/firstrun.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def do_configure_long_paths(
8080
hive=winreg.HKEY_LOCAL_MACHINE,
8181
keyname=_LONG_PATH_KEY,
8282
valuename=_LONG_PATH_VALUENAME,
83+
startfile=os.startfile,
8384
):
8485
LOGGER.debug("Updating long paths setting")
8586
try:
@@ -96,7 +97,7 @@ def do_configure_long_paths(
9697
LOGGER.warn("The setting has not been updated. Please rerun '!B!py "
9798
"install --configure!W! with administrative privileges.")
9899
return
99-
os.startfile(sys.executable, "runas", "**configure-long-paths", show_cmd=0)
100+
startfile(sys.executable, "runas", "**configure-long-paths", show_cmd=0)
100101
for _ in range(5):
101102
time.sleep(0.25)
102103
if check_long_paths(cmd):

tests/test_firstrun.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,16 @@ def test_check_long_paths(registry, fake_config):
246246

247247

248248
def test_do_configure_long_paths(registry, fake_config, monkeypatch):
249-
monkeypatch.setattr(os, "startfile", _raise_oserror)
250-
firstrun.do_configure_long_paths(fake_config, hive=registry.hive, keyname=registry.root)
249+
firstrun.do_configure_long_paths(fake_config, hive=registry.hive, keyname=registry.root, startfile=_raise_oserror)
251250
assert winreg.QueryValueEx(registry.key, "LongPathsEnabled") == (1, winreg.REG_DWORD)
252251

253252

254253
def test_do_configure_long_paths_elevated(protect_reg, fake_config, monkeypatch):
255254
startfile_calls = []
256255
def startfile(*a, **kw):
257256
startfile_calls.append((a, kw))
258-
monkeypatch.setattr(os, "startfile", startfile)
259257
# Pretend we can interact, so that os.startfile gets called
260258
fake_config.confirm = True
261-
firstrun.do_configure_long_paths(fake_config)
259+
firstrun.do_configure_long_paths(fake_config, startfile=startfile)
262260
assert startfile_calls
263261
assert startfile_calls[0][0][1:] == ("runas", "**configure-long-paths")

0 commit comments

Comments
 (0)