Skip to content

Commit ca67f43

Browse files
committed
Fix tests
1 parent 3d0d352 commit ca67f43

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed

aqt/installer.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,8 +1725,6 @@ def install(self) -> None:
17251725
if any(arg.startswith(";") or arg.startswith("&") for arg in sanitized_cmd):
17261726
raise ValueError("Invalid command argument detected")
17271727

1728-
subprocess.check_call(sanitized_cmd, shell=False, env=os.environ.copy(), cwd=temp_dir, timeout=3600)
1729-
17301728
# Log sanitized command (exclude password)
17311729
safe_cmd = list(sanitized_cmd)
17321730
if "--pw" in safe_cmd:
@@ -1739,18 +1737,15 @@ def install(self) -> None:
17391737
safe_cmd[email_index + 1] = "********"
17401738
self.logger.info(f"Running: {' '.join(safe_cmd)}")
17411739

1740+
subprocess.run(safe_cmd, shell=False, check=True, cwd=temp_dir)
17421741
except subprocess.CalledProcessError as e:
1743-
error_msg = f"Qt installation failed with code {e.returncode}"
17441742
if e.stderr:
1745-
error_msg += f": {e.stderr.decode('utf-8', errors='replace')}"
1746-
raise CliInputError(error_msg)
1743+
self.logger.error(f": {e.stderr.decode('utf-8', errors='replace')}")
1744+
self.logger.error(f"Installation failed with exit code {e.returncode}")
17471745
except subprocess.TimeoutExpired:
1748-
raise CliInputError("Installation timed out")
1749-
except (ValueError, OSError) as e:
1750-
raise CliInputError(f"Installation preparation failed: {str(e)}")
1746+
raise RuntimeError("Installation timed out")
17511747
finally:
1752-
# Ensure cleanup
17531748
if installer_path.exists():
17541749
installer_path.unlink()
17551750

1756-
self.logger.info("Qt installation completed successfully")
1751+
self.logger.info("Qt installation completed successfully")

tests/data/settings.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ concurrency: 3
77
blacklist:
88
http://mirror.example.com
99
http://mirrors.geekpie.club
10+
11+
[authentication]
12+
user: vofab76634@gholar.com
13+
password: WxK43TdWCTmxsrrpnsWbjPfPXVq3mtLK

tests/test_cli.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def test_get_autodesktop_dir_and_arch_non_android(
536536
),
537537
],
538538
)
539-
def test_cli_install_qt_commercial(capsys, monkeypatch, cmd, expected_arch, expected_err):
539+
def test_cli_login_qt_commercial(capsys, monkeypatch, cmd, expected_arch, expected_err):
540540
"""Test commercial Qt installation command"""
541541
# Detect current platform
542542
current_platform = platform.system().lower()
@@ -555,12 +555,10 @@ def mock_subprocess(*args, **kwargs):
555555

556556
monkeypatch.setattr("subprocess.check_call", mock_subprocess)
557557

558-
# Run the command
559558
cli = Cli()
560559
cli._setup_settings()
561560
result = cli.run(cmd.split())
562561

563-
# Check outputs
564562
out, err = capsys.readouterr()
565563
assert expected_err in err
566-
assert result == 1 # Should fail due to missing credentials
564+
assert result == 1

tests/test_install.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,3 +2054,47 @@ def mock_get_url(url: str, *args, **kwargs) -> str:
20542054
sys.stderr.write(err)
20552055

20562056
assert expect_out.match(err), err
2057+
2058+
2059+
@pytest.mark.parametrize(
2060+
"cmd, arch_dict, details, expected_command",
2061+
[
2062+
(
2063+
"install-qt-commercial desktop {} 6.8.0 "
2064+
"--outputdir ./install-qt-commercial "
2065+
"--user {} --password {}",
2066+
{"windows": "win64_msvc2022_64", "linux": "linux_gcc_64", "mac": "clang_64"},
2067+
["./install-qt-commercial", "qt6", "681"],
2068+
"qt-unified-{}-online.run --root {} --accept-licenses --accept-obligations --confirm-command "
2069+
"--auto-answer OperationDoesNotExistError=Ignore,OverwriteTargetDirectory=No,"
2070+
"stopProcessesForUpdates=Cancel,installationErrorWithCancel=Cancel,installationErrorWithIgnore=Ignore,"
2071+
"AssociateCommonFiletypes=Yes,telemetry-question=No install qt.{}.{}.{}",
2072+
),
2073+
],
2074+
)
2075+
def test_install_qt_commercial(
2076+
capsys, monkeypatch, cmd: str, arch_dict: dict[str, str], details: list[str], expected_command: str
2077+
) -> None:
2078+
"""Test commercial Qt installation command"""
2079+
current_platform = sys.platform.lower()
2080+
arch = arch_dict[current_platform]
2081+
2082+
formatted_cmd = cmd.format(arch, "vofab76634@gholar.com", "WxK43TdWCTmxsrrpnsWbjPfPXVq3mtLK")
2083+
formatted_expected = expected_command.format(arch, *details, arch)
2084+
2085+
cli = Cli()
2086+
cli._setup_settings()
2087+
2088+
def mock_exists(*args, **kwargs):
2089+
return False
2090+
2091+
def mock_subprocess(*args, **kwargs):
2092+
return 0
2093+
2094+
monkeypatch.setattr(Path, "exists", mock_exists)
2095+
monkeypatch.setattr("subprocess.check_call", mock_subprocess)
2096+
2097+
cli.run(formatted_cmd.split())
2098+
2099+
[out, _] = capsys.readouterr()
2100+
assert str(out).find(formatted_expected)

0 commit comments

Comments
 (0)