def test_external_with_usage(self): @runner.Clize.as_is(usages=['ua abc', 'ub abc [def]']) def ext(): raise NotImplementedError def func(): raise NotImplementedError sd = runner.SubcommandDispatcher([ ext, runner.Clize.as_is(func, usages=['uc --ab=STR', 'ud [--cd]']) ]) self._do_test( sd, [ 'sd --help [--usage]', 'sd ext ua abc', 'sd ext ub abc [def]', 'sd func uc --ab=STR', 'sd func ud [--cd]', ], """ Usage: sd command [args...] Commands: ext func """)
def _test_func(self, description, footer, sigs, docs, usage, help_str): funcs = [] for i, sig, doc in zip(count(1), sigs, docs): func = f(sig) func.__doc__ = doc func.__name__ = 'func' + str(i) funcs.append(func) sd = runner.SubcommandDispatcher(funcs, description, footer) self._do_test(sd, usage, help_str)
def test_dummy_external(self): @runner.Clize.as_is def ext(): raise NotImplementedError def func(): raise NotImplementedError sd = runner.SubcommandDispatcher([ext, runner.Clize.as_is(func)]) self._do_test(sd, [ 'sd --help [--usage]', 'sd ext [args...]', 'sd func [args...]', ], """ Usage: sd command [args...] Commands: ext func """)
def test_external_with_dummyhelp(self): @runner.Clize.as_is(description="Ext") def ext(): raise NotImplementedError def func(): raise NotImplementedError sd = runner.SubcommandDispatcher([ ext, runner.Clize.as_is(func, description="Func")]) self._do_test(sd, [ 'sd --help [--usage]', 'sd ext [args...]', 'sd func [args...]', ], """ Usage: sd command [args...] Commands: ext Ext func Func """)
def run_group(functions, args): disp = runner.SubcommandDispatcher(functions) return disp.cli(*args)