Skip to content

Commit

Permalink
Unused code removal and test coverage improvements in clize.help
Browse files Browse the repository at this point in the history
  • Loading branch information
epsy committed Apr 26, 2015
1 parent 741e810 commit 41aac53
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
6 changes: 2 additions & 4 deletions clize/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ def get_param_type(cls, param):
param.aliases
except AttributeError:
return LABEL_POS
if getattr(param, 'func', None) is None:
else:
return LABEL_OPT
return LABEL_ALT


def prepare(self):
Expand Down Expand Up @@ -290,8 +289,7 @@ def show_usage(self, name):
yield 'Usage: {0} command [args...]'.format(name)

def usages(self):
if self.subject.help_aliases:
yield self.subject.help_aliases[0] + ' ' + str(self.cli.signature)
yield self.subject.help_aliases[0] + ' ' + str(self.cli.signature)
for names, subcommand in self.owner.cmds.items():
try:
get_usages = subcommand.helper.usages
Expand Down
50 changes: 46 additions & 4 deletions clize/tests/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sigtools.support import f
from sigtools.wrappers import wrapper_decorator

from clize import runner, help
from clize import runner, help, parser
from clize.tests.util import repeated_test

USAGE_HELP = 'func --help [--usage]'
Expand All @@ -23,10 +23,14 @@ def _test_func(self, sig, doc, usage, help_str):
def _do_test(self, runner, usage, help_str):
h = help.ClizeHelp(runner, None)
h.prepare()
p_usage = list(h.show_full_usage('func'))
pc_usage = h.cli('func --help', '--usage')
p_usage = [l.rstrip() for l in h.show_full_usage('func')]
pc_help_str = h.cli('func --help')
p_help_str = str(h.show('func'))
self.assertEqual(usage, p_usage)
self.assertEqual('\n'.join(usage), pc_usage)
self.assertEqual(help_str.split(), p_help_str.split())
self.assertEqual(help_str.split(), pc_help_str.split())

simple = "one, *args, two", """
Description
Expand Down Expand Up @@ -353,7 +357,7 @@ def _do_test(self, runner, usage, help_str):
beta: unseen
Footer
""", ['func ', USAGE_HELP], """
""", ['func', USAGE_HELP], """
Usage: func [OPTIONS]
Description
Expand Down Expand Up @@ -385,14 +389,15 @@ def _do_test(self, runner, usage, help_str):
Footer
"""


def test_nonclize_alt(self):
@runner.Clize.as_is
def alt(script):
raise NotImplementedError
def func():
raise NotImplementedError
r = runner.Clize(func, alt=alt)
self._do_test(r, ['func ', USAGE_HELP, 'func --alt [args...]'], """
self._do_test(r, ['func', USAGE_HELP, 'func --alt [args...]'], """
Usage: func
Other actions:
Expand All @@ -401,6 +406,43 @@ def func():
""")


def test_custom_param_help(self):
class CustParam(parser.OptionParameter):
def show_help(self, desc, after, f, cols):
cols.append('I am', 'a custom parameter!')
f.append("There is stuff after me.")
f.append(desc)
f.extend(after)
func = f(
"*, param: a",
locals={'a': parser.use_class(named=CustParam)})
func.__doc__ = """
param: Param desc
After param
_:_
"""
r = runner.Clize(func)
self._do_test(r, ['func --param=STR', USAGE_HELP], """
Usage: func [OPTIONS]
Options:
I am a custom parameter!
There is stuff after me.
Param desc
After param
Other actions:
-h, --help Show the help
""")



@repeated_test
class WrappedFuncTests(object):
def _test_func(self, sig, wrapper_sigs, doc, wrapper_docs, help_str):
Expand Down

0 comments on commit 41aac53

Please sign in to comment.