def test_pos_2(): @annotations(test_code=Pos("Test code (default {default})", 't')) def func(test_code='1234'): for i in (1, 2, 3): yield test_code call(func, arg_list=[])
def test_output_3(): @annotations(test2_arg=Pos("test2 help message", choices=('test_1', 'test_2', 'test_3')), test2_code=Opt("Test code (default {default})", 't')) def func(test2_arg, test2_code='1234'): return test2_arg, test2_code call(func, arg_list=[])
def test_output_2(): @annotations(test_pos=Pos("test2 help message"), test_opt_1=Opt("Test help (default {default})", 't'), test_opt_2=Flag("Test help 2")) def func(test_pos, test_opt_1='1234', test_opt_2=False): pass call(func, arg_list=['-h'])
class Interface(object): commands = ['search'] def __init__(self): self.result = ' 5555 ' @annotations(regex=Pos("Regular Expression")) def search(self, regex): return self.result + regex
class Interface(object): commands = ['search'] def __init__(self): self.result = ' 5555 ' @annotations(regex=Pos("Regular Expression"), test_flag=Flag("Flag", "f")) def search(self, regex, test_flag=False): return self.result + regex, test_flag
def test_pos_1(): @annotations(test_code=Pos("Test code (default {default})")) def func(test_code='1234'): for i in (1, 2, 3): yield test_code ns, output = call(func, arg_list=[]) eq_(ns['test_code'], '1234') eq_(output, ['1234', '1234', '1234']) ns, output = call(func, arg_list=['4321']) eq_(ns['test_code'], '4321') eq_(output, ['4321', '4321', '4321'])
def test_wizard_1(): @annotations(test2_arg=Pos("test2 help message"), test2_code=Opt("Test code (default {default})", 't', choices=('test_1', 'test_2', 'test_3'))) def func(test2_arg, test2_code='1234'): return test2_arg, test2_code def wizard_callback(name, annotation, default): if name == 'test2_arg': return '7890' elif name == 'test2_code': return 'test_2' ns, output = wizard_call(func, wizard_callback, arg_list=[]) eq_(ns['test2_arg'], '7890') eq_(ns['test2_code'], 'test_2')
def test_output_5(): @annotations(test_pos=Pos(), test_opt_1=Opt(abbrev='t'), test_opt_2=Flag()) def func(test_pos, test_opt_1='1234', test_opt_2=False): pass call(func, arg_list=['-h'])
from pyclap import annotations, call, Positional as Pos, Option as Opt, Flag, wizard_call import sys from nose_tools import exits, outputs from nose.tools import * commands = ['command1', 'command2'] @annotations(positional_arg=Pos("Positional argument"), optional_arg=Opt("Optional argument {default}")) def command1(positional_arg, optional_arg='test'): """ test command 1 """ return positional_arg, optional_arg @annotations(positional_arg=Pos("Positional argument"), optional_arg=Opt("Optional argument {default}"), flag_arg=Flag("Flag argument")) def command2(positional_arg, optional_arg='test', flag_arg=False): """ test command 2 """ return positional_arg, optional_arg, flag_arg ###################################################################################################### @outputs(stderr="""usage: noserunner.py [-h] {command1,command2} ... noserunner.py: error: too few arguments """)