Skip to content

Commit

Permalink
CLI: add --test-profile flag to verdi setup/quicksetup
Browse files Browse the repository at this point in the history
This new flag allows to designate a new profile that is created to be a
test profile, which means it can be used to run the test suite.
  • Loading branch information
sphuber committed Feb 25, 2022
1 parent 6195fce commit c8104da
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/config/profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ broker_host: 127.0.0.1
broker_port: 5672
broker_virtual_host: ''
repository: /tmp/test_repository_test_aiida/
test_profile: true
8 changes: 6 additions & 2 deletions aiida/cmdline/commands/cmd_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@
@options_setup.SETUP_BROKER_PORT()
@options_setup.SETUP_BROKER_VIRTUAL_HOST()
@options_setup.SETUP_REPOSITORY_URI()
@options_setup.SETUP_TEST_PROFILE()
@options.CONFIG_FILE()
def setup(
non_interactive, profile: Profile, email, first_name, last_name, institution, db_engine, db_backend, db_host,
db_port, db_name, db_username, db_password, broker_protocol, broker_username, broker_password, broker_host,
broker_port, broker_virtual_host, repository
broker_port, broker_virtual_host, repository, test_profile
):
"""Setup a new profile.
Expand Down Expand Up @@ -74,6 +75,7 @@ def setup(
'broker_virtual_host': broker_virtual_host,
}
)
profile.is_test_profile = test_profile

config = get_config()

Expand Down Expand Up @@ -142,12 +144,13 @@ def setup(
@options_setup.QUICKSETUP_BROKER_PORT()
@options_setup.QUICKSETUP_BROKER_VIRTUAL_HOST()
@options_setup.QUICKSETUP_REPOSITORY_URI()
@options_setup.QUICKSETUP_TEST_PROFILE()
@options.CONFIG_FILE()
@click.pass_context
def quicksetup(
ctx, non_interactive, profile, email, first_name, last_name, institution, db_engine, db_backend, db_host, db_port,
db_name, db_username, db_password, su_db_name, su_db_username, su_db_password, broker_protocol, broker_username,
broker_password, broker_host, broker_port, broker_virtual_host, repository
broker_password, broker_host, broker_port, broker_virtual_host, repository, test_profile
):
"""Setup a new profile in a fully automated fashion."""
# pylint: disable=too-many-arguments,too-many-locals
Expand Down Expand Up @@ -202,5 +205,6 @@ def quicksetup(
'broker_port': broker_port,
'broker_virtual_host': broker_virtual_host,
'repository': repository,
'test_profile': test_profile,
}
ctx.invoke(setup, **setup_parameters)
6 changes: 6 additions & 0 deletions aiida/cmdline/params/options/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,9 @@ def get_quicksetup_password(ctx, param, value): # pylint: disable=unused-argume
contextual_default=get_repository_uri_default,
cls=options.interactive.InteractiveOption
)

SETUP_TEST_PROFILE = options.OverridableOption(
'--test-profile', is_flag=True, help='Designate the profile to be used for running the test suite only.'
)

QUICKSETUP_TEST_PROFILE = SETUP_TEST_PROFILE.clone()
8 changes: 8 additions & 0 deletions aiida/manage/configuration/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ def is_test_profile(self) -> bool:
# a test profile as that can unintentionally clear the database.
return self._attributes.get(self.KEY_TEST_PROFILE, False) is True

@is_test_profile.setter
def is_test_profile(self, value: bool) -> None:
"""Set whether the profile is a test profile.
:param value: boolean indicating whether this profile is a test profile.
"""
self._attributes[self.KEY_TEST_PROFILE] = value

@property
def repository_path(self) -> pathlib.Path:
"""Return the absolute path of the repository configured for this profile.
Expand Down
4 changes: 3 additions & 1 deletion aiida/manage/tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
'broker_password': 'guest',
'broker_host': '127.0.0.1',
'broker_port': 5672,
'broker_virtual_host': ''
'broker_virtual_host': '',
'test_profile': True,
}


Expand Down Expand Up @@ -251,6 +252,7 @@ def profile_dictionary(self):
Used to set up AiiDA profile from self.profile_info dictionary.
"""
dictionary = {
'test_profile': True,
'storage': {
'backend': self.profile_info.get('storage_backend'),
'config': {
Expand Down
4 changes: 4 additions & 0 deletions docs/source/reference/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ Below is a list with all available subcommands.
--broker-virtual-host TEXT Name of the virtual host for the message broker without
leading forward slash.
--repository DIRECTORY Absolute path to the file repository.
--test-profile Designate the profile to be used for running the test
suite only.
--config FILEORURL Load option values from configuration file in yaml
format (local path or URL).
--help Show this message and exit.
Expand Down Expand Up @@ -497,6 +499,8 @@ Below is a list with all available subcommands.
--broker-virtual-host TEXT Name of the virtual host for the message broker without
leading forward slash. [required]
--repository DIRECTORY Absolute path to the file repository.
--test-profile Designate the profile to be used for running the test
suite only.
--config FILEORURL Load option values from configuration file in yaml
format (local path or URL).
--help Show this message and exit.
Expand Down

0 comments on commit c8104da

Please sign in to comment.