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

verdi config list: Do not except if no profiles are defined #5921

Merged

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Mar 8, 2023

Fixes #5920

The command should work if no profiles exist, in which case it should
simply list the global values, however, it was excepting since it
assumed that ctx.obj.profile would be set. This is set by the
ProfileParamType which is used by the --profile option, but this is
not called if no profiles are defined.

To create a regression test, the empty_config fixture is used.
However, since this fixture works in memory, the use_subprocess=False
switch has to be used for run_cli_command. This by default would
populate the ctx.obj.profile object. This is normally done by the
--profile option, but this is not hit when using click.CliRunner.
This would nullify the test, as it would always pass, even without the
fix.

To solve this issue, a new argument initialize_ctx_obj is added to the
run_cli_command fixture. If set to False, the ctx.obj is not
initialized. By using this new argument, the regression test properly
failed before the test, but passes after the fix.

@sphuber sphuber force-pushed the fix/5920/verdi-config-list-no-profiles branch 2 times, most recently from 907a7f5 to 8f6eadd Compare March 12, 2023 15:22
@sphuber sphuber requested a review from ltalirz March 12, 2023 18:42
@sphuber
Copy link
Contributor Author

sphuber commented Mar 12, 2023

With #5846 merged, this is now ready for review

Copy link
Member

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @sphuber !

Comment on lines 518 to 519
``use_subprocess == False``. Normally this is done by the ``VerdiContext`` of the ``verdi`` command when
invoked normally from the command line, but when using the test runner in this interpreter, the object has
Copy link
Member

@ltalirz ltalirz Mar 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional

Suggested change
``use_subprocess == False``. Normally this is done by the ``VerdiContext`` of the ``verdi`` command when
invoked normally from the command line, but when using the test runner in this interpreter, the object has
``use_subprocess == False``. When invoking ``verdi`` from the command line (and when running tests with ``use_subprocess == True``),
this is done by the ``VerdiContext``, but when using the test runner in this interpreter, the object has

The command should work if no profiles exist, in which case it should
simply list the global values, however, it was excepting since it
assumed that `ctx.obj.profile` would be set. This is set by the
`ProfileParamType` which is used by the `--profile` option, but this is
not called if no profiles are defined.

To create a regression test, the `empty_config` fixture is used.
However, since this fixture works in memory, the `use_subprocess=False`
switch has to be used for `run_cli_command`. This by default would
populate the `ctx.obj.profile` object. This is normally done by the
`--profile` option, but this is not hit when using `click.CliRunner`.
This would nullify the test, as it would always pass, even without the
fix.

To solve this issue, a new argument `initialize_ctx_obj` is added to the
`run_cli_command` fixture. If set to `False`, the `ctx.obj` is not
initialized. By using this new argument, the regression test properly
failed before the test, but passes after the fix.
@sphuber sphuber force-pushed the fix/5920/verdi-config-list-no-profiles branch from 8f6eadd to 5bfc060 Compare March 13, 2023 07:58
@sphuber sphuber merged commit 4819210 into aiidateam:main Mar 13, 2023
@sphuber sphuber deleted the fix/5920/verdi-config-list-no-profiles branch March 13, 2023 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

verdi config list errors when no profile is configured
2 participants