Skip to content

Commit

Permalink
Add test for CLI install
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Jun 7, 2024
1 parent 40bb573 commit e8f2da7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
29 changes: 17 additions & 12 deletions aiida_hyperqueue/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
default=Path("$HOME/bin/"),
help="remote bin path hq will stored.",
)
@click.option(
"--write-bashrc/--no-write-bashrc",
default=True,
help="write the bin path to bashrc.",
)
@click.option(
"--hq-version", type=str, default="0.19.0", help="the hq version will be installed."
)
# TODO: separate the bashrc write and make it optional.
# TODO: should also support different arch binary??
def cmd_install(computer: orm.Computer, remote_bin_dir: Path, hq_version: str):
def cmd_install(computer: orm.Computer, remote_bin_dir: Path, hq_version: str, write_bashrc: bool):
"""Install the hq binary to the computer through the transport"""

# The minimal hq version we support is 0.13.0, check the minor version
Expand Down Expand Up @@ -95,15 +99,16 @@ def cmd_install(computer: orm.Computer, remote_bin_dir: Path, hq_version: str):
transport.exec_command_wait(f"chmod +x {str(remote_bin_dir / 'hq')}")

# write to bashrc
identity_str = "by aiida-hq"
retval, _, stderr = transport.exec_command_wait(
f"grep -q '# {identity_str}' ~/.bashrc || echo '# {identity_str}\nexport PATH=$HOME/bin:$PATH' >> ~/.bashrc"
)

if retval != 0:
echo.echo_critical(
f"Not able to set set the path $HOME/bin to your remote bashrc, try to do it manually.\n"
f"Info: {stderr}"
if write_bashrc:
identity_str = "by aiida-hq"
retval, _, stderr = transport.exec_command_wait(
f"grep -q '# {identity_str}' ~/.bashrc || echo '# {identity_str}\nexport PATH=$HOME/bin:$PATH' >> ~/.bashrc"
)

echo.echo_success("The hq binary installed in remote")
if retval != 0:
echo.echo_critical(
f"Not able to set set the path $HOME/bin to your remote bashrc, try to do it manually.\n"
f"Info: {stderr}"
)

echo.echo_success(f"The hq binary installed into remote {remote_bin_dir}")
13 changes: 13 additions & 0 deletions tests/test_cli_alloc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest
from click.testing import CliRunner

from aiida.transports.transport import Transport as TransportClass

@pytest.fixture
def runner():
return CliRunner()

original_exec_command_wait = TransportClass.exec_command_wait

# TODO: Not yet implemented, seems hard to just use hq_env
# If using real command, I need to handle the grace for teardown of tests
21 changes: 21 additions & 0 deletions tests/test_cli_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest
from click.testing import CliRunner

from aiida_hyperqueue.cli import cmd_install

@pytest.fixture
def runner():
return CliRunner()

def test_install(runner, tmp_path, aiida_computer_ssh):
aiida_computer_ssh(label="localhost-hq")

version = "0.19.0"
result = runner.invoke(cmd_install, ["-p", f"{str(tmp_path.resolve())}", "--hq-version", version, "--no-write-bashrc", "localhost-hq"])

assert result.exit_code == 0
assert f"hq version {version}" in result.output




1 change: 1 addition & 0 deletions tests/test_cli.py → tests/test_cli_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,4 @@ def test_server_start_info_stop_circle(runner: CliRunner, aiida_computer_ssh, mo

assert result.exit_code == 1
assert "Critical: cannot obtain HyperQueue server information" in result.output

0 comments on commit e8f2da7

Please sign in to comment.