Skip to content

Commit

Permalink
fix: issue where --account did not fail when it was supposed to (#2231
Browse files Browse the repository at this point in the history
)
  • Loading branch information
antazoey authored Aug 22, 2024
1 parent 04934de commit d933b00
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
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

0 comments on commit d933b00

Please sign in to comment.