diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 97c346ec5a..806f18776f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ hooks: - id: yapf language: system - files: '^(aiida/control/)' + files: '^(aiida/control/)|(aiida/cmdline/tests)' - repo: git://github.com/guykisel/prospector-mirror sha: b27f281eb9398fc8504415d7fbdabf119ea8c5e1 @@ -11,5 +11,5 @@ - id: prospector language: system exclude: '^(tests/)|(examples/)' - files: '^(aiida/control/)' + files: '^(aiida/control/)|(aiida/cmdline/tests)' diff --git a/aiida/cmdline/commands/devel.py b/aiida/cmdline/commands/devel.py index 3c6bd2881e..158fa0aa36 100644 --- a/aiida/cmdline/commands/devel.py +++ b/aiida/cmdline/commands/devel.py @@ -87,7 +87,8 @@ class Devel(VerdiCommandWithSubcommands): 'aiida.common', 'aiida.tests.work', 'aiida.utils', - 'aiida.control' + 'aiida.control', + 'aiida.cmdline.tests' ] _dbrawprefix = "db" diff --git a/aiida/cmdline/tests/__init__.py b/aiida/cmdline/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/aiida/cmdline/tests/common.py b/aiida/cmdline/tests/common.py new file mode 100644 index 0000000000..647094f9af --- /dev/null +++ b/aiida/cmdline/tests/common.py @@ -0,0 +1,15 @@ +"""Common code to be used in cli testing""" +import sys +from contextlib import contextmanager +from StringIO import StringIO + + +@contextmanager +def captured_output(): + new_out, new_err = StringIO(), StringIO() + old_out, old_err = sys.stdout, sys.stderr + try: + sys.stdout, sys.stderr = new_out, new_err + yield sys.stdout, sys.stderr + finally: + sys.stdout, sys.stderr = old_out, old_err diff --git a/aiida/cmdline/tests/test_verdi_help.py b/aiida/cmdline/tests/test_verdi_help.py new file mode 100644 index 0000000000..b46ec95a99 --- /dev/null +++ b/aiida/cmdline/tests/test_verdi_help.py @@ -0,0 +1,35 @@ +"""Bug regression tests for ``verdi help``""" +import unittest + +from aiida.cmdline.verdilib import Help, Import + +from .common import captured_output + + +class VerdiHelpTest(unittest.TestCase): + """Make sure fixed bugs stay fixed""" + + def setUp(self): + self.help_cmd = Help() + + def test_verdi_help_full_string(self): + """ + Prevent regression of bug #700 + + ``verdi help`` was printing only the first letter of the docstring + of non-click commands + """ + self.assertFalse( + hasattr(Import, '_ctx'), + 'This test must use a non-click verdi subcommand') + fail_msg = ('Has the docstring for ``verdi import`` changed? ' + 'If not, this is a regression of #700') + with captured_output() as (out, _): + try: + self.help_cmd.run() + except SystemExit: + pass + finally: + output = [l.strip() for l in out.getvalue().split('\n')] + self.assertIn('* import Import nodes and group of nodes', + output, fail_msg) diff --git a/aiida/cmdline/verdilib.py b/aiida/cmdline/verdilib.py index b1af3d6082..2351d29292 100644 --- a/aiida/cmdline/verdilib.py +++ b/aiida/cmdline/verdilib.py @@ -982,7 +982,7 @@ def exec_from_cmdline(argv): help_msg += "\n" # resilient_parsing suppresses interactive prompts help_msg += cmd._ctx(args=[], resilient_parsing=True).get_help() - help_msg = help_msg.split('\n') # need list of lines + help_msg = help_msg.split('\n') # need list of lines lines = [l.strip() for l in help_msg] empty_lines = [bool(l) for l in lines]