From 15b92c25c37eb72287eb5cc009303072bc6286b8 Mon Sep 17 00:00:00 2001 From: Reto Trappitsch Date: Fri, 12 Apr 2024 15:54:26 +0200 Subject: [PATCH] add tests for windows cli installer and exception if no installer created --- tests/cli/test_cli_installer.py | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/cli/test_cli_installer.py b/tests/cli/test_cli_installer.py index 9ab0f13..03289ca 100644 --- a/tests/cli/test_cli_installer.py +++ b/tests/cli/test_cli_installer.py @@ -110,6 +110,57 @@ def test_installer_gui_linux(rye_project): assert installer_file.name in result.output +@pytest.mark.parametrize("verbose", [True, False]) +def test_installer_cli_windows(rye_project, mocker, verbose): + """Create an installer with NSIS for a CLI on Windows.""" + mocker.patch("sys.platform", "win32") + subp_mock = mocker.patch("subprocess.run") + sp_devnull_mock = mocker.patch("subprocess.DEVNULL") + + subp_kwargs = {} + if not verbose: + subp_kwargs["stdout"] = subp_kwargs["stderr"] = sp_devnull_mock + + conf = config.PyProjectParser() + installer_fname_exp = f"{conf.name}-v0.1.0-win.exe" + _ = setup_mock_target_binary(rye_project) + # create the installer binary + installer_binary = rye_project.joinpath(f"target/release/{installer_fname_exp}") + installer_binary.touch() + + # run the CLI + runner = CliRunner() + if verbose: + args = ["installer", "-v"] + else: + args = ["installer"] + result = runner.invoke(cli, args) + + assert result.exit_code == 0 + + make_installer_pth = rye_project.joinpath("target/release/make_installer.nsi") + release_path = rye_project.joinpath("target/release") + subp_mock.assert_called_with( + ["makensis", make_installer_pth.relative_to(release_path)], **subp_kwargs + ) + assert installer_fname_exp in result.output + + +def test_installer_cli_windows_not_created(rye_project, mocker): + """Raise ClickException if the installer was not created.""" + mocker.patch("sys.platform", "win32") + mocker.patch("subprocess.run") + + _ = setup_mock_target_binary(rye_project) + + runner = CliRunner() + result = runner.invoke(cli, ["installer"]) + + assert result.exit_code != 0 + assert result.exception + assert "Installer was not created" in result.output + + @pytest.mark.parametrize("verbose", [True, False]) def test_installer_gui_windows(rye_project, mocker, verbose): """Create an installer with NSIS on Windows."""