diff --git a/aqt/installer.py b/aqt/installer.py index 5a18ed5e..b0672694 100644 --- a/aqt/installer.py +++ b/aqt/installer.py @@ -1725,8 +1725,6 @@ def install(self) -> None: if any(arg.startswith(";") or arg.startswith("&") for arg in sanitized_cmd): raise ValueError("Invalid command argument detected") - subprocess.check_call(sanitized_cmd, shell=False, env=os.environ.copy(), cwd=temp_dir, timeout=3600) - # Log sanitized command (exclude password) safe_cmd = list(sanitized_cmd) if "--pw" in safe_cmd: @@ -1739,18 +1737,15 @@ def install(self) -> None: safe_cmd[email_index + 1] = "********" self.logger.info(f"Running: {' '.join(safe_cmd)}") + subprocess.run(safe_cmd, shell=False, check=True, cwd=temp_dir) except subprocess.CalledProcessError as e: - error_msg = f"Qt installation failed with code {e.returncode}" if e.stderr: - error_msg += f": {e.stderr.decode('utf-8', errors='replace')}" - raise CliInputError(error_msg) + self.logger.error(f": {e.stderr.decode('utf-8', errors='replace')}") + self.logger.error(f"Installation failed with exit code {e.returncode}") except subprocess.TimeoutExpired: - raise CliInputError("Installation timed out") - except (ValueError, OSError) as e: - raise CliInputError(f"Installation preparation failed: {str(e)}") + raise RuntimeError("Installation timed out") finally: - # Ensure cleanup if installer_path.exists(): installer_path.unlink() - self.logger.info("Qt installation completed successfully") + self.logger.info("Qt installation completed successfully") diff --git a/tests/data/settings.ini b/tests/data/settings.ini index 2308bebf..26f5a459 100644 --- a/tests/data/settings.ini +++ b/tests/data/settings.ini @@ -7,3 +7,7 @@ concurrency: 3 blacklist: http://mirror.example.com http://mirrors.geekpie.club + +[authentication] +user: vofab76634@gholar.com +password: WxK43TdWCTmxsrrpnsWbjPfPXVq3mtLK diff --git a/tests/test_cli.py b/tests/test_cli.py index f6cd21a3..bb10a73d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -536,7 +536,7 @@ def test_get_autodesktop_dir_and_arch_non_android( ), ], ) -def test_cli_install_qt_commercial(capsys, monkeypatch, cmd, expected_arch, expected_err): +def test_cli_login_qt_commercial(capsys, monkeypatch, cmd, expected_arch, expected_err): """Test commercial Qt installation command""" # Detect current platform current_platform = platform.system().lower() @@ -555,12 +555,10 @@ def mock_subprocess(*args, **kwargs): monkeypatch.setattr("subprocess.check_call", mock_subprocess) - # Run the command cli = Cli() cli._setup_settings() result = cli.run(cmd.split()) - # Check outputs out, err = capsys.readouterr() assert expected_err in err - assert result == 1 # Should fail due to missing credentials + assert result == 1 diff --git a/tests/test_install.py b/tests/test_install.py index 585e2716..17869b49 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -2054,3 +2054,47 @@ def mock_get_url(url: str, *args, **kwargs) -> str: sys.stderr.write(err) assert expect_out.match(err), err + + +@pytest.mark.parametrize( + "cmd, arch_dict, details, expected_command", + [ + ( + "install-qt-commercial desktop {} 6.8.0 " + "--outputdir ./install-qt-commercial " + "--user {} --password {}", + {"windows": "win64_msvc2022_64", "linux": "linux_gcc_64", "mac": "clang_64"}, + ["./install-qt-commercial", "qt6", "681"], + "qt-unified-{}-online.run --root {} --accept-licenses --accept-obligations --confirm-command " + "--auto-answer OperationDoesNotExistError=Ignore,OverwriteTargetDirectory=No," + "stopProcessesForUpdates=Cancel,installationErrorWithCancel=Cancel,installationErrorWithIgnore=Ignore," + "AssociateCommonFiletypes=Yes,telemetry-question=No install qt.{}.{}.{}", + ), + ], +) +def test_install_qt_commercial( + capsys, monkeypatch, cmd: str, arch_dict: dict[str, str], details: list[str], expected_command: str +) -> None: + """Test commercial Qt installation command""" + current_platform = sys.platform.lower() + arch = arch_dict[current_platform] + + formatted_cmd = cmd.format(arch, "vofab76634@gholar.com", "WxK43TdWCTmxsrrpnsWbjPfPXVq3mtLK") + formatted_expected = expected_command.format(arch, *details, arch) + + cli = Cli() + cli._setup_settings() + + def mock_exists(*args, **kwargs): + return False + + def mock_subprocess(*args, **kwargs): + return 0 + + monkeypatch.setattr(Path, "exists", mock_exists) + monkeypatch.setattr("subprocess.check_call", mock_subprocess) + + cli.run(formatted_cmd.split()) + + [out, _] = capsys.readouterr() + assert str(out).find(formatted_expected)