Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue where --account did not fail when it was supposed to #2231

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/ape/cli/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,13 @@ def convert(
else:
alias = value

if isinstance(alias, str) and alias.startswith("TEST::"):
idx_str = value.replace("TEST::", "")
if isinstance(alias, str) and alias.upper().startswith("TEST::"):
idx_str = alias.upper().replace("TEST::", "")
if not idx_str.isnumeric():
if alias in ManagerAccessMixin.account_manager.aliases:
# Was actually a similar-alias.
return ManagerAccessMixin.account_manager.load(alias)

self.fail(f"Cannot reference test account by '{value}'.", param=param)

account_idx = int(idx_str)
Expand All @@ -209,7 +213,7 @@ def convert(
elif alias and alias in ManagerAccessMixin.account_manager.aliases:
return ManagerAccessMixin.account_manager.load(alias)

return None
self.fail(f"Account with alias '{alias}' not found.", param=param)

def print_choices(self):
choices = dict(enumerate(self.choices, 0))
Expand Down
18 changes: 16 additions & 2 deletions tests/functional/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ def cmd(account):
assert expected in result.output


def test_account_option_can_use_test_account(runner, test_accounts):
@pytest.mark.parametrize("test_key", ("test", "TEST"))
def test_account_option_can_use_test_account(runner, test_accounts, test_key):
index = 7
test_account = test_accounts[index]

Expand All @@ -376,7 +377,20 @@ def cmd(account):
click.echo(_expected)

expected = get_expected_account_str(test_account)
result = runner.invoke(cmd, ("--account", f"TEST::{index}"))
result = runner.invoke(cmd, ("--account", f"{test_key}::{index}"))
assert expected in result.output


def test_account_option_alias_not_found(runner, keyfile_account):
@click.command()
@account_option()
def cmd(account):
pass

result = runner.invoke(cmd, ("--account", "THIS ALAS IS NOT FOUND"))
expected = (
"Invalid value for '--account': " "Account with alias 'THIS ALAS IS NOT FOUND' not found"
)
assert expected in result.output


Expand Down
Loading