Skip to content

Commit

Permalink
CLI: change profiles to profile to align with verdi (#182)
Browse files Browse the repository at this point in the history
* CLI: change profiles to profile to align with verdi

* Update tests/test_cli.py
  • Loading branch information
unkcpz committed May 30, 2023
1 parent d3c121f commit 052f354
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ aiidalab-launch status
### Profile Management

The tool allows to manage multiple profiles, e.g., with different home directories or ports.
See `aiidalab-launch profiles --help` for more information.
See `aiidalab-launch profile --help` for more information.

### Data Management

Expand Down
16 changes: 8 additions & 8 deletions aiidalab_launch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ def version():


@cli.group()
def profiles():
def profile():
"""Manage AiiDAlab profiles."""
pass


@profiles.command("list")
@profile.command("list")
@pass_app_state
def list_profiles(app_state):
"""List all configured AiiDAlab profiles.
Expand All @@ -163,15 +163,15 @@ def list_profiles(app_state):
)


@profiles.command("show")
@profile.command("show")
@click.argument("profile")
@pass_app_state
def show_profile(app_state, profile):
"""Show an AiiDAlab profile configuration."""
click.echo(app_state.config.get_profile(profile).dumps(), nl=False)


@profiles.command("add")
@profile.command("add")
@click.argument("profile")
@click.option(
"--port",
Expand Down Expand Up @@ -218,7 +218,7 @@ def add_profile(ctx, app_state, port, home_mount, profile):
ctx.invoke(edit_profile, profile=profile)


@profiles.command("remove")
@profile.command("remove")
@click.argument("profile")
@click.option("--yes", is_flag=True, help="Do not ask for confirmation.")
@click.option("-f", "--force", is_flag=True, help="Proceed, ignoring any warnings.")
Expand Down Expand Up @@ -252,7 +252,7 @@ def remove_profile(app_state, profile, yes, force):
click.echo(f"Removed profile with name '{profile.name}'.")


@profiles.command("edit")
@profile.command("edit")
@click.argument("profile")
@pass_app_state
def edit_profile(app_state, profile):
Expand All @@ -269,7 +269,7 @@ def edit_profile(app_state, profile):
click.echo("No changes.")


@profiles.command("set-default")
@profile.command("set-default")
@click.argument("profile")
@pass_app_state
def set_default_profile(app_state, profile):
Expand Down Expand Up @@ -404,7 +404,7 @@ async def _async_start(
if instance.profile.port and "port is already allocated" in str(error):
raise click.ClickException(
f"Port {instance.profile.port} is already allocated, choose another port "
f"for example, by editing the profile: aiidalab-launch profiles edit {instance.profile.name}"
f"for example, by editing the profile: aiidalab-launch profile edit {instance.profile.name}"
)
raise click.ClickException("Startup failed due to an unexpected error.")
except asyncio.TimeoutError:
Expand Down
38 changes: 19 additions & 19 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,39 @@ def test_version_verbose_logging():

def test_invalid_profile_name_throws():
"""
Arrange/Act: Run `profiles show invalid` subcommand.
Arrange/Act: Run `profile show invalid` subcommand.
Assert: The command throws an exception due to invalid profile name.
"""
runner: CliRunner = CliRunner()
with pytest.raises(ValueError):
result: Result = runner.invoke(
cli.cli, ["profiles", "show", "invalid"], catch_exceptions=False
cli.cli, ["profile", "show", "invalid"], catch_exceptions=False
)
result: Result = runner.invoke(
cli.cli,
["profiles", "show", "invalid"],
["profile", "show", "invalid"],
)
assert isinstance(result.exception, ValueError)


def test_list_profiles():
runner: CliRunner = CliRunner()
result: Result = runner.invoke(cli.cli, ["profiles", "list"])
result: Result = runner.invoke(cli.cli, ["profile", "list"])
assert "default" in result.output.strip()


def test_show_profile():
runner: CliRunner = CliRunner()
result: Result = runner.invoke(cli.cli, ["profiles", "show", "default"])
result: Result = runner.invoke(cli.cli, ["profile", "show", "default"])
assert Profile.loads("default", result.output) == Profile()


def test_change_default_profile():
runner: CliRunner = CliRunner()
result: Result = runner.invoke(cli.cli, ["profiles", "set-default", "default"])
result: Result = runner.invoke(cli.cli, ["profile", "set-default", "default"])
assert result.exit_code == 0
result: Result = runner.invoke(
cli.cli, ["profiles", "set-default", "does-not-exist"]
cli.cli, ["profile", "set-default", "does-not-exist"]
)
assert result.exit_code == 1
assert "does not exist" in result.output
Expand All @@ -96,44 +96,44 @@ def test_add_remove_profile():

# Add new-profile
result: Result = runner.invoke(
cli.cli, ["profiles", "add", "new-profile"], input="n\n"
cli.cli, ["profile", "add", "new-profile"], input="n\n"
)
assert result.exit_code == 0
assert "Added profile 'new-profile'." in result.output

# Check that new-profile exists
result: Result = runner.invoke(cli.cli, ["profiles", "list"])
result: Result = runner.invoke(cli.cli, ["profile", "list"])
assert "new-profile" in result.output
result: Result = runner.invoke(cli.cli, ["profiles", "show", "new-profile"])
result: Result = runner.invoke(cli.cli, ["profile", "show", "new-profile"])
assert result.exit_code == 0

# Try add another profile with the same name (should fail)
result: Result = runner.invoke(
cli.cli, ["profiles", "add", "new-profile"], input="n\n"
cli.cli, ["profile", "add", "new-profile"], input="n\n"
)
assert result.exit_code == 1
assert "Profile with name 'new-profile' already exists." in result.output

# Try make new profile default
result: Result = runner.invoke(cli.cli, ["profiles", "set-default", "new-profile"])
result: Result = runner.invoke(cli.cli, ["profile", "set-default", "new-profile"])
assert result.exit_code == 0
assert "Set default profile to 'new-profile'." in result.output
# Reset default profile
result: Result = runner.invoke(cli.cli, ["profiles", "set-default", "default"])
result: Result = runner.invoke(cli.cli, ["profile", "set-default", "default"])
assert result.exit_code == 0
assert "Set default profile to 'default'." in result.output

# Remove new-profile
result: Result = runner.invoke(
cli.cli, ["profiles", "remove", "new-profile"], input="y\n"
cli.cli, ["profile", "remove", "new-profile"], input="y\n"
)
assert result.exit_code == 0
result: Result = runner.invoke(cli.cli, ["profiles", "list"])
result: Result = runner.invoke(cli.cli, ["profile", "list"])
assert "new-profile" not in result.output

# Remove new-profile (again – should fail)
result: Result = runner.invoke(
cli.cli, ["profiles", "remove", "new-profile"], input="y\n"
cli.cli, ["profile", "remove", "new-profile"], input="y\n"
)
assert result.exit_code == 1
assert "Profile with name 'new-profile' does not exist." in result.output
Expand All @@ -142,7 +142,7 @@ def test_add_remove_profile():
def test_add_profile_invalid_name():
runner: CliRunner = CliRunner()
# underscores are not allowed
result: Result = runner.invoke(cli.cli, ["profiles", "add", "new_profile"])
result: Result = runner.invoke(cli.cli, ["profile", "add", "new_profile"])
assert result.exit_code == 1
assert "Invalid profile name 'new_profile'." in result.output

Expand Down Expand Up @@ -175,7 +175,7 @@ def test_logs(self):

def test_remove_running_profile(self):
runner: CliRunner = CliRunner()
result: Result = runner.invoke(cli.cli, ["profiles", "remove", "default"])
result: Result = runner.invoke(cli.cli, ["profile", "remove", "default"])
assert result.exit_code == 1
assert "is still running" in result.output

Expand Down Expand Up @@ -283,7 +283,7 @@ def test_extra_volumes(

# Check that extra volume is picked up.
runner: CliRunner = CliRunner()
result = runner.invoke(cli.cli, ["profiles", "show", profile.name])
result = runner.invoke(cli.cli, ["profile", "show", profile.name])
assert result.exit_code == 0
assert extra_volume_name in result.output

Expand Down

0 comments on commit 052f354

Please sign in to comment.