Skip to content

Commit

Permalink
Merge pull request #704 from DropD/fix-700
Browse files Browse the repository at this point in the history
Fix and add regression test for #700 (`verdi help` broken)
  • Loading branch information
ltalirz authored Sep 21, 2017
2 parents dfdd5c9 + bf23439 commit 84fe6c5
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
hooks:
- id: yapf
language: system
files: '^(aiida/control/)'
files: '^(aiida/control/)|(aiida/cmdline/tests)'

- repo: git://github.com/guykisel/prospector-mirror
sha: b27f281eb9398fc8504415d7fbdabf119ea8c5e1
hooks:
- id: prospector
language: system
exclude: '^(tests/)|(examples/)'
files: '^(aiida/control/)'
files: '^(aiida/control/)|(aiida/cmdline/tests)'

3 changes: 2 additions & 1 deletion aiida/cmdline/commands/devel.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class Devel(VerdiCommandWithSubcommands):
'aiida.common',
'aiida.tests.work',
'aiida.utils',
'aiida.control'
'aiida.control',
'aiida.cmdline.tests'
]

_dbrawprefix = "db"
Expand Down
Empty file added aiida/cmdline/tests/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions aiida/cmdline/tests/common.py
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions aiida/cmdline/tests/test_verdi_help.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion aiida/cmdline/verdilib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 84fe6c5

Please sign in to comment.