Skip to content

Commit

Permalink
Generalize the get_info method.
Browse files Browse the repository at this point in the history
  • Loading branch information
ramirezfranciscof committed Feb 23, 2022
1 parent 98f6bc4 commit d98e301
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 2 additions & 4 deletions aiida/cmdline/commands/cmd_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ def storage_info(statistics):
storage = manager.get_profile_storage()

with spinner():
data = {
'database': get_database_summary(QueryBuilder, statistics),
'repository': storage.get_info(statistics=statistics),
}
data = storage.get_info(statistics=statistics)
data['database']['summary'] = get_database_summary(QueryBuilder, statistics)

echo.echo_dictionary(data, sort_keys=False, fmt='yaml')

Expand Down
3 changes: 2 additions & 1 deletion aiida/orm/implementation/storage_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def get_info(self, statistics: bool = False) -> dict:
flag to request more detailed information about the content of the storage.
:returns:
a nested dict with the relevant information.
a nested dict with the relevant information (with at least one key for `database`
and one for `repository`).
"""
6 changes: 5 additions & 1 deletion aiida/storage/psql_dos/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,8 @@ def get_unreferenced_keyset(self, check_consistency: bool = True) -> Set[str]:

def get_info(self, statistics: bool = False) -> dict:
repository = self.get_repository()
return repository.get_info(statistics)
output_dict = {
'database': {},
'repository': repository.get_info(statistics),
}
return output_dict
9 changes: 7 additions & 2 deletions tests/storage/psql_dos/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,17 @@ def mock_get_info(self, statistics=False, **kwargs): # pylint: disable=unused-a
RepoBackendClass = get_manager().get_profile_storage().get_repository().__class__ # pylint: disable=invalid-name
monkeypatch.setattr(RepoBackendClass, 'get_info', mock_get_info)

repository_info_out = storage_backend.get_info()
storage_info_out = storage_backend.get_info()
assert 'database' in storage_info_out
assert 'repository' in storage_info_out

repository_info_out = storage_info_out['repository']
assert 'value' in repository_info_out
assert 'extra_value' not in repository_info_out
assert repository_info_out['value'] == 42

repository_info_out = storage_backend.get_info(statistics=True)
storage_info_out = storage_backend.get_info(statistics=True)
repository_info_out = storage_info_out['repository']
assert 'value' in repository_info_out
assert 'extra_value' in repository_info_out
assert repository_info_out['value'] == 42
Expand Down

0 comments on commit d98e301

Please sign in to comment.