Skip to content

Commit

Permalink
Migrate verdi devel to the click infrastructure (#1765)
Browse files Browse the repository at this point in the history
Removed several commands that were outdated and no longer in use

	* verdi devel query
	* verdi devel getresults

The former was still under development and hardcoded Django queries and so was
not usable across all backends. The latter was also in development stage and
has now been replaced by the more apt `verdi calculation res` command.
  • Loading branch information
sphuber authored Jul 19, 2018
1 parent dc7cdd0 commit 46a16b8
Show file tree
Hide file tree
Showing 5 changed files with 393 additions and 836 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
.ci/test_setup.py|
#aiida/backends/tests/cmdline/commands/.*.py|
aiida/backends/tests/cmdline/params/types/workflow.py|
aiida/backends/tests/verdi_commands.py|
aiida/control/.*.py| # must match the whole path, therefore
aiida/cmdline/tests/.*.py| # the .*.py (.* matches everything)
aiida/control/.*.py|
aiida/cmdline/tests/.*.py|
aiida/cmdline/commands/calculation.py|
aiida/cmdline/commands/code.py|
aiida/cmdline/commands/comment.py|
aiida/cmdline/commands/daemon.py|
aiida/cmdline/commands/devel.py|
aiida/cmdline/commands/data/array.py|
aiida/cmdline/commands/data/bands.py|
aiida/cmdline/commands/data/cif.py|
Expand All @@ -28,7 +29,6 @@
aiida/cmdline/commands/data/structure.py|
aiida/cmdline/commands/data/trajectory.py|
aiida/cmdline/commands/data/upf.py|
aiida/cmdline/commands/code.py|
aiida/cmdline/commands/graph.py|
aiida/cmdline/commands/group.py|
aiida/cmdline/commands/profile.py|
Expand All @@ -50,7 +50,7 @@
aiida/orm/data/cif.py|
aiida/orm/implementation/sqlalchemy/node.py|
aiida/orm/user.py|
# Unfortunately scheduler plugins and datastructures need to be refactored thorougly
# Unfortunately scheduler plugins and datastructures need to be refactored thoroughly
# to pass the linters, so enable only __init__ and test_datastructures for now
# aiida/scheduler/[^/]+.py|
aiida/scheduler/__init__.py|
Expand Down
12 changes: 6 additions & 6 deletions aiida/backends/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@
'examplehelpers': ['aiida.backends.tests.example_helpers'],
'cmdline.commands.calculation': ['aiida.backends.tests.cmdline.commands.test_calculation'],
'cmdline.commands.code': ['aiida.backends.tests.cmdline.commands.test_code'],
'cmdline.commands.computer': ['aiida.backends.tests.cmdline.commands.test_computer'],
'cmdline.commands.comment': ['aiida.backends.tests.cmdline.commands.test_comment'],
'cmdline.commands.computer': ['aiida.backends.tests.cmdline.commands.test_computer'],
'cmdline.commands.data': ['aiida.backends.tests.cmdline.commands.test_data'],
'cmdline.commands.devel': ['aiida.backends.tests.cmdline.commands.test_devel'],
'cmdline.commands.export': ['aiida.backends.tests.cmdline.commands.test_export'],
'cmdline.commands.graph': ['aiida.backends.tests.cmdline.commands.test_graph'],
'cmdline.commands.group': ['aiida.backends.tests.cmdline.commands.test_group'],
'cmdline.commands.node': ['aiida.backends.tests.cmdline.commands.test_node'],
'cmdline.commands.profile': ['aiida.backends.tests.cmdline.commands.test_profile'],
'cmdline.commands.rehash': ['aiida.backends.tests.cmdline.commands.test_rehash'],
'cmdline.commands.user': ['aiida.backends.tests.cmdline.commands.test_user'],
'cmdline.commands.work': ['aiida.backends.tests.cmdline.commands.test_work'],
'cmdline.commands.group': ['aiida.backends.tests.cmdline.commands.test_group'],
'cmdline.commands.node': ['aiida.backends.tests.cmdline.commands.test_node'],
'cmdline.commands.workflow': ['aiida.backends.tests.cmdline.commands.test_workflow'],
'cmdline.commands.profile': ['aiida.backends.tests.cmdline.commands.test_profile'],
'cmdline.params.types.calculation': ['aiida.backends.tests.cmdline.params.types.test_calculation'],
'cmdline.params.types.code': ['aiida.backends.tests.cmdline.params.types.test_code'],
'cmdline.params.types.computer': ['aiida.backends.tests.cmdline.params.types.test_computer'],
Expand All @@ -71,8 +73,6 @@
'cmdline.params.types.identifier': ['aiida.backends.tests.cmdline.params.types.test_identifier'],
'cmdline.params.types.node': ['aiida.backends.tests.cmdline.params.types.test_node'],
'cmdline.params.types.plugin': ['aiida.backends.tests.cmdline.params.types.test_plugin'],
'cmdline.commands.code': ['aiida.backends.tests.cmdline.commands.test_code'],
'cmdline.commands.data': ['aiida.backends.tests.cmdline.commands.test_data'],
'cmdline.params.types.workflow': ['aiida.backends.tests.cmdline.params.types.test_workflow'],
'daemon.client': ['aiida.backends.tests.daemon.test_client'],
'orm.data.frozendict': ['aiida.backends.tests.orm.data.frozendict'],
Expand Down
137 changes: 137 additions & 0 deletions aiida/backends/tests/cmdline/commands/test_devel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# -*- coding: utf-8 -*-
"""Tests for `verdi devel`."""
import tempfile

from click.testing import CliRunner

from aiida.backends.testbase import AiidaTestCase
from aiida.cmdline.commands import devel
from aiida.common import setup as aiida_cfg
from aiida.common.setup import _property_table, exists_property, get_property, del_property


def get_result_lines(result):
return [e for e in result.output.split('\n') if e]


class TestVerdiDevel(AiidaTestCase):
"""Tests for `verdi devel`."""

@classmethod
def setUpClass(cls, *args, **kwargs):
super(TestVerdiDevel, cls).setUpClass()

cls._old_aiida_config_folder = None
cls._new_aiida_config_folder = tempfile.mkdtemp()
cls._old_aiida_config_folder = aiida_cfg.AIIDA_CONFIG_FOLDER

aiida_cfg.AIIDA_CONFIG_FOLDER = cls._new_aiida_config_folder
aiida_cfg.create_base_dirs()

cls.profile_name = 'aiida_dummy_profile_1234'
cls.dummy_profile = {}
cls.dummy_profile['backend'] = 'django'
cls.dummy_profile['db_host'] = 'localhost'
cls.dummy_profile['db_port'] = '5432'
cls.dummy_profile['email'] = 'dummy@localhost'
cls.dummy_profile['db_name'] = cls.profile_name
cls.dummy_profile['db_user'] = 'dummy_user'
cls.dummy_profile['db_pass'] = 'dummy_pass'
cls.dummy_profile['repo'] = aiida_cfg.AIIDA_CONFIG_FOLDER + '/repository_' + cls.profile_name

aiida_cfg.create_config_noninteractive(profile=cls.profile_name, **cls.dummy_profile)
aiida_cfg.set_default_profile(cls.profile_name, force_rewrite=True)

@classmethod
def tearDownClass(cls, *args, **kwargs):
"""
Remove dummy profiles created in setUpClass.
:param args: list of arguments
:param kwargs: list of keyword arguments
"""
import os
import shutil

aiida_cfg.AIIDA_CONFIG_FOLDER = cls._old_aiida_config_folder

if os.path.isdir(cls._new_aiida_config_folder):
shutil.rmtree(cls._new_aiida_config_folder)

def setUp(self):
self.runner = CliRunner()

def tearDown(self):
"""Delete any properties that were set."""
for prop in sorted(_property_table.keys()):
if exists_property(prop):
del_property(prop)

def test_describe_properties(self):
"""Test the `verdi devel describeproperties` command"""
result = self.runner.invoke(devel.devel_describeproperties, [])

self.assertIsNone(result.exception)
self.assertTrue(len(get_result_lines(result)) > 0)

for prop in _property_table:
self.assertIn(prop, result.output)

def test_list_properties(self):
"""Test the `verdi devel listproperties` command"""

# Since dummy configuration does not have explicit properties set, with default options the result is empty
options = []
result = self.runner.invoke(devel.devel_listproperties, options)
self.assertIsNone(result.exception)
self.assertTrue(len(get_result_lines(result)) == 0)

# Toggling the all flag should show all available options
for flag in ['-a', '--all']:

options = [flag]
result = self.runner.invoke(devel.devel_listproperties, options)
self.assertIsNone(result.exception)
self.assertTrue(len(get_result_lines(result)) > 0)

for prop in _property_table:
self.assertIn(prop, result.output)

def test_set_property(self):
"""Test the `verdi devel setproperty` command."""
property_name = 'daemon.timeout'
property_values = [10, 20]

for property_value in property_values:
options = [property_name, str(property_value)]
result = self.runner.invoke(devel.devel_setproperty, options)

self.assertIsNone(result.exception)
self.assertEquals(get_property(property_name), property_value)

def test_get_property(self):
"""Test the `verdi devel getproperty` command."""
property_name = 'daemon.timeout'
property_value = 30

options = [property_name, str(property_value)]
result = self.runner.invoke(devel.devel_setproperty, options)

options = [property_name]
result = self.runner.invoke(devel.devel_getproperty, options)
self.assertIsNone(result.exception)
self.assertEquals(str(property_value), result.output.strip())

def test_del_property(self):
"""Test the `verdi devel delproperty` command."""
property_name = 'daemon.timeout'
property_value = 30

options = [property_name, str(property_value)]
result = self.runner.invoke(devel.devel_setproperty, options)

options = [property_name]
result = self.runner.invoke(devel.devel_delproperty, options)
self.assertIsNone(result.exception)
self.assertIn(property_name, result.output.strip())
self.assertFalse(exists_property(property_name))
10 changes: 5 additions & 5 deletions aiida/backends/tests/cmdline/commands/test_profile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""
Test suite to test verdi profile command
"""

# -*- coding: utf-8 -*-
"""Test suite to test the `verdi profile` commands."""
from click.testing import CliRunner

from aiida.backends.testbase import AiidaTestCase
from aiida.common import setup as aiida_cfg

Expand Down Expand Up @@ -144,8 +143,9 @@ def test_delete(self):
self.assertNotIn(self.dummy_profile_list[4], result.output)
self.assertIsNone(result.exception)


def get_random_string(length):
import string
import random

return ''.join(random.choice(string.ascii_letters) for m in range(length))
return ''.join(random.choice(string.ascii_letters) for m in range(length))
Loading

0 comments on commit 46a16b8

Please sign in to comment.