Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and add regression test for #700 (verdi help broken) #704

Merged
merged 4 commits into from
Sep 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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