Skip to content

Commit

Permalink
fix up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trappitsch committed Apr 12, 2024
1 parent b7697fe commit 6340bfc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
23 changes: 12 additions & 11 deletions src/box/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,18 @@ def installer(verbose):
my_installer = CreateInstaller(verbose=verbose)
my_installer.create_installer()
inst_name = my_installer.installer_name
if Path(box.RELEASE_DIR_NAME).joinpath(inst_name).exists():
fmt.success(
f"Installer successfully created.\n"
f"You can find the installer file {inst_name} "
f"in the `target/release` folder."
)
else:
raise click.ClickException(
"Installer was not created. "
"Run with `box installer -v` to get verbose feedback."
)
if inst_name is not None:
if Path(box.RELEASE_DIR_NAME).joinpath(inst_name).exists():
fmt.success(
f"Installer successfully created.\n"
f"You can find the installer file {inst_name} "
f"in the `target/release` folder."
)
else:
raise click.ClickException(
"Installer was not created. "
"Run with `box installer -v` to get verbose feedback."
)


@cli.command(name="clean")
Expand Down
6 changes: 3 additions & 3 deletions src/box/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,18 @@ def windows_gui(self):

from box.installer_utils.windows_hlp import nsis_gui_script

name_pkg = self._config.name_pkg
name = self._config.name
version = self._config.version
icon = get_icon("ico")

installer_name = f"{name_pkg}-v{version}-win.exe"
installer_name = f"{name}-v{version}-win.exe"

with ut.set_dir(RELEASE_DIR_NAME):
nsis_script_name = Path("make_installer.nsi")
with open(nsis_script_name, "w") as f:
f.write(
nsis_gui_script(
name_pkg,
name,
installer_name,
self._config.author,
self._config.version,
Expand Down
9 changes: 7 additions & 2 deletions tests/cli/test_cli_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def test_installer_cli_linux(rye_project):
@pytest.mark.skipif("sys.platform == 'win32'", reason="Not supported on Windows")
def test_installer_gui_linux(rye_project):
"""Create installer for linux GUI."""
installer_fname_exp = f"{rye_project.name}-v0.1.0-linux.sh"
conf = config.PyProjectParser()
installer_fname_exp = f"{conf.name}-v0.1.0-linux.sh"
target_file_content = setup_mock_target_binary(rye_project)
icon_file_content = setup_mock_icon(rye_project)

Expand Down Expand Up @@ -120,9 +121,13 @@ def test_installer_gui_windows(rye_project, mocker, verbose):
if not verbose:
subp_kwargs["stdout"] = subp_kwargs["stderr"] = sp_devnull_mock

installer_fname_exp = f"{rye_project.name.lower()}-v0.1.0-win.exe"
conf = config.PyProjectParser()
installer_fname_exp = f"{conf.name}-v0.1.0-win.exe"
_ = setup_mock_target_binary(rye_project)
_ = setup_mock_icon(rye_project, ico=True)
# create the installer binary
installer_binary = rye_project.joinpath(f"target/release/{installer_fname_exp}")
installer_binary.touch()

# make it a GUI project
config.pyproject_writer("is_gui", True)
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ def test_cmd_python(mocker, os_python):
"""Get python on mulitple operating systems."""
# mock os.name
mocker.patch("os.name", os_python[0])
mocker.patch("subprocess.run")
assert ut.cmd_python() == os_python[1]


def test_cmd_python_py_not_found(mocker):
"""Default to python on windows if py not found."""
mocker.patch("os.name", "nt")
mocker.patch("subprocess.run", side_effect=FileNotFoundError)
assert ut.cmd_python() == "python"


def test_check_boxproject(rye_project):
"""Check if the box project is already initialized."""
ut.check_boxproject()
Expand Down

0 comments on commit 6340bfc

Please sign in to comment.