def dataProvider_testPutValue(self): ps = Parameters() yield ps, 'noSuchArgname', None, None, None, 'auto' ps.a.type = 'list' yield ps, 'a', 'auto', 1, 1, 'auto' yield ps, 'a', 'auto', '2', 2, 'auto' yield ps, 'a', 'auto', '', '', 'auto' yield ps, 'a', 'list', 3, ['3'], 'str' ps.b.type = 'bool' yield ps, 'b', 'auto', 'F', False, 'auto' ps.c.type = 'list' yield ps, 'c', 'list', 1, [[1]], 'one' yield ps, 'd', 'auto', '1', 1, 'auto', True ps.e.type = 'list' ps.e = [1, 2, 3] yield ps, 'e', 'list', '4', [1, 2, 3, 4], 'auto', True ps.f = [1, 2, 3] yield ps, 'f', 'list', '4', [], None, True
def dataProvider_testHelp(self): ps = Parameters() yield ps, [ 'USAGE:', ' testParameters.py', '', 'OPTIONAL OPTIONS:', ' -h, --help, -H - Print this help information', '' ] ps1 = Parameters() ps1('hopts', '-h') yield ps1, [ 'USAGE:', ' testParameters.py', '', 'OPTIONAL OPTIONS:', ' -h - Print this help information', '' ] ps2 = Parameters() ps2('prefix', '--param-') ps2.a yield ps2, [ 'USAGE:', ' testParameters.py [OPTIONS]', '', 'OPTIONAL OPTIONS:', ' --param-a - Default: None', ' -h, --help, -H - Print this help information', '' ] ps3 = Parameters() ps3.e = False ps3.e.type = 'bool' ps3._.required = True ps3._.desc = 'positional options' yield ps3, [ 'USAGE:', ' testParameters.py [OPTIONS] POSITIONAL', '', 'REQUIRED OPTIONS:', ' POSITIONAL - positional options', '', 'OPTIONAL OPTIONS:', ' -e (BOOL) - Default: False', ' -h, --help, -H - Print this help information', '' ] ps4 = Parameters() ps4('prefix', '--param-') ps4.ef.required = True ps4.ef.type = 'str' ps4.ef.desc = 'This is a description of option ef. \n Option ef is required.' ps4.f = [] ps4.f.type = 'list' ps4.f.desc = 'This is a description of option f. \n Option f is not required.' ps4.g = ps4.f # alias ps4._.required = False ps4._.desc = 'positional options' ps4( 'usage', '{prog} User-defined usages\n{prog} User-defined another usage'. split('\n')) ps4('desc', 'This program is doing: \n* 1. blahblah\n* 2. lalala'.split('\n')) ps4._helpx = lambda items: items.update({'END': ['Bye!']}) or items yield ps4, [ 'DESCRIPTION:', ' This program is doing:', ' * 1. blahblah', ' * 2. lalala', '', 'USAGE:', ' testParameters.py User-defined usages', ' testParameters.py User-defined another usage', '', 'REQUIRED OPTIONS:', ' --param-ef <STR> - This is a description of option ef.', ' Option ef is required.', '', 'OPTIONAL OPTIONS:', ' --param-f, --param-g <LIST> - This is a description of option f.', ' Option f is not required.', ' Default: []', ' POSITIONAL - positional options', ' Default: None', ' -h, --help, -H - Print this help information', '', 'END:', ' Bye!', '' ] # show = False, description ps5 = Parameters() ps5.g = '' ps5.g.show = False yield ps5, [ 'Error: This is an error!', 'USAGE:', ' testParameters.py', '', 'OPTIONAL OPTIONS:', ' -h, --help, -H - Print this help information', '' ], 'This is an error!'
def dataProvider_testParse(self): ps = Parameters() yield ps, [], {}, 'USAGE', SystemExit ps1 = Parameters() ps1('hopts', '-h') yield ps1, ['a', 'b', '-h'], {}, 'USAGE', SystemExit, None ps2 = Parameters() ps2('prefix', '--param-') ps2.a yield ps2, ['--param-a=b'], {'a': 'b', '_': []} yield ps2, ['--param-d'], { 'a': 'b', '_': [] }, 'Warning: No such option: --param-d' ps3 = Parameters() ps3('prefix', '--param-') ps3.e = True ps3.e.type = 'bool' yield ps3, ['--param-e=False'], {'e': False, '_': []} # 5 yield ps3, ['--param-e'], {'e': True, '_': []} yield ps3, ['--param-e', 'Yes'], {'e': True, '_': []} yield ps3, ['--param-e', 't'], {'e': True, '_': []} yield ps3, ['--param-e', 'true'], {'e': True, '_': []} yield ps3, ['--param-e', 'y'], {'e': True, '_': []} # 10 yield ps3, ['--param-e', '1'], {'e': True, '_': []} yield ps3, ['--param-e', 'on'], {'e': True, '_': []} yield ps3, ['--param-e', 'f'], {'e': False, '_': []} yield ps3, ['--param-e', 'false'], {'e': False, '_': []} yield ps3, ['--param-e', 'no'], {'e': False, '_': []} # 15 yield ps3, ['--param-e', 'n'], {'e': False, '_': []} yield ps3, ['--param-e', '0'], {'e': False, '_': []} yield ps3, ['--param-e', 'off'], {'e': False, '_': []} yield ps3, ['--param-e', 'a'], { 'e': True, '_': [] }, None, ParameterTypeError, "Unable to coerce value 'a' to type: 'bool'" ps4 = Parameters() ps4('prefix', '--param-') ps4.f = [] ps4.f.type = 'list:str' yield ps4, ['--param-f=1'], {'f': ['1'], '_': []} # 20 yield ps4, ['--param-f=1', '2', '3'], { 'f': ['1', '1', '2', '3'], '_': [] } ps5 = Parameters() ps5('prefix', '--param-') ps5.g = '' yield ps5, ['--param-g'], {'g': '', '_': []}, '' yield ps5, ['--param-g', 'a', 'b'], {'g': 'a', '_': ['b']} ps6 = Parameters() ps6('prefix', '--param-') ps6('hbald', False) ps6.h.required = True # 23 yield ps6, [], {}, 'Error: Option --param-h is required.', SystemExit ps7 = Parameters() ps7('prefix', '--param-') ps7.i = 1 yield ps7, ['--param-i=a' ], {}, None, ParameterTypeError, 'Unable to coerce' # mixed ps8 = Parameters() ps8('prefix', '--param-') ps8.a.type = 'str' ps8.b.type = 'str' ps8.c # 25 yield ps8, ['--param-a=1', '--param-b', '2', '--param-c="3"'], { 'a': '1', 'b': '2', 'c': '"3"', '_': [] } ps9 = Parameters() ps9('prefix', '--param-') ps9.a = [] ps9.a.type = 'list:str' ps9.b = [] ps9.c = [] yield ps9, ['--param-a=1', '2', '--param-b', 'a', '--param-c'], { 'a': ['1', '2'], 'b': ['a'], 'c': [], '_': [] } ps10 = Parameters() ps10('prefix', '--param-') ps10.a = False ps10.b = False ps10.c = False yield ps10, ['--param-a', '--param-b', '1', '--param-c=yes'], { 'a': True, 'b': True, 'c': True, '_': [] } ps11 = Parameters() ps11('prefix', '--param-') ps11.a ps11.b = 'a' ps11.c = 1 ps11.d = False ps11.e = [] yield ps11, ['--param-d'], { 'a': None, 'b': 'a', 'c': 1, 'd': True, 'e': [], '_': [] } yield ps11, [ 'a', '--param-d', 'no', 'b', '--param-c=100', '--param-e:l:s', '-1', '-2' ], { 'a': None, 'b': 'a', 'c': 100, 'd': False, 'e': ['-1', '-2'], '_': ['a'] }, 'Warning: Unexpected value(s): b.' # 30 ps12 = Parameters() ps12.a ps12.b yield ps12, ['-a', '-b=1'], {'a': True, 'b': 1, '_': []} ps13 = Parameters() ps13.a.type = list yield ps13, ['-a', '1', '-a', '-a', '2', '3'], {'a': [2, 3], '_': []} # 32: test callback ps14 = Parameters() ps14.a.type = str def ps14_a_callback(a): a.value = 'arg:' + a.value ps14.a.callback = ps14_a_callback yield ps14, ['-a', '1'], {'a': 'arg:1', '_': []} ps15 = Parameters() ps15.infile.type = str def ps15_infile_callback(infile): return path.isfile(infile.value) or '"infile" does not exist.' ps15.infile.callback = ps15_infile_callback yield ps15, ['-infile', '__no_such_file__'], { 'a': '__no_such_file__', '_': [] }, '"infile" does not exist.', SystemExit ps16 = Parameters() ps16.d.type = str ps16.f.type = str ps16.f.callback = lambda f, ps: f.setValue( path.join(ps.d.value, f.value)) yield ps16, ['-d', 'dir', '-f', 'a.txt'], { 'd': 'dir', 'f': 'dir/a.txt', '_': [] }
def dataProvider_testHelp(self): ps = Parameters() yield ps, [ 'USAGE:', ' progname', '', 'OPTIONAL OPTIONS:', ' -h, --help, -H, -? - Print this help information.', '' ] ps1 = Parameters() ps1('hopts', '-h') yield ps1, [ 'USAGE:', ' progname', '', 'OPTIONAL OPTIONS:', ' -h - Print this help information.', '' ] ps2 = Parameters() ps2('prefix', '--param-') ps2.a yield ps2, [ 'USAGE:', ' progname [OPTIONS]', '', 'OPTIONAL OPTIONS:', ' --param-a - DEFAULT: None', ' -h, --help, -H, -? - Print this help information.', '' ] ps3 = Parameters() ps3.e = False ps3.e.type = 'bool' ps3._.required = True ps3._.desc = 'positional options' yield ps3, [ 'USAGE:', ' progname [OPTIONS] <POSITIONAL>', '', 'REQUIRED OPTIONS:', ' <POSITIONAL> - positional options', '', 'OPTIONAL OPTIONS:', ' -e (bool) - DEFAULT: False', ' -h, --help, -H, -? - Print this help information.', '' ] ps4 = Parameters() ps4('prefix', '--param-') ps4.ef.required = True ps4.ef.type = 'str' ps4.ef.desc = 'This is a description of option ef. \n Option ef is required.' ps4.f = [] ps4.f.type = 'list' ps4.f.desc = 'This is a description of option f. \n Option f is not required.' ps4._.required = True ps4._.desc = 'positional options' ps4('usage', '{prog} User-defined usages\n{prog} User-defined another usage') ps4('desc', 'This program is doing: \n* 1. blahblah\n* 2. lalala') ps4('example', '{prog} --param-f abc\n {prog} --param-f 22') yield ps4, [ 'DESCRIPTION:', ' This program is doing:', ' * 1. blahblah', ' * 2. lalala', '', 'USAGE:', ' progname User-defined usages', ' progname User-defined another usage', '', 'EXAMPLE:', ' progname --param-f abc', ' progname --param-f 22', '', 'REQUIRED OPTIONS:', ' --param-ef <str> - This is a description of option ef. ', ' Option ef is required.', ' <POSITIONAL> - positional options', '', 'OPTIONAL OPTIONS:', ' --param-f <list> - This is a description of option f. ', ' Option f is not required.', ' DEFAULT: []', ' -h, --help, -H, -? - Print this help information.', '' ] # show = False, description ps5 = Parameters() ps5.g = '' ps5.g.show = False yield ps5, [ 'USAGE:', ' progname', '', 'OPTIONAL OPTIONS:', ' -h, --help, -H, -? - Print this help information.', '' ]
def dataProvider_testParse(self): ps = Parameters() yield ps, [], {}, 'USAGE', SystemExit ps1 = Parameters() ps1('hopts', '-h') yield ps1, ['a', 'b', '-h'], {}, 'USAGE', SystemExit, None ps2 = Parameters() ps2('prefix', '--param-') ps2.a yield ps2, ['--param-a=b'], {'a': 'b', '_': []} yield ps2, ['--param-d'], { 'a': 'b', '_': [] }, 'WARNING: Unknown option' ps3 = Parameters() ps3('prefix', '--param-') ps3.e = True ps3.e.type = 'bool' yield ps3, ['--param-e=False'], {'e': False, '_': []} # 5 yield ps3, ['--param-e'], {'e': True, '_': []} yield ps3, ['--param-e', 'Yes'], {'e': True, '_': []} yield ps3, ['--param-e', 't'], {'e': True, '_': []} yield ps3, ['--param-e', 'true'], {'e': True, '_': []} yield ps3, ['--param-e', 'y'], {'e': True, '_': []} # 10 yield ps3, ['--param-e', '1'], {'e': True, '_': []} yield ps3, ['--param-e', 'on'], {'e': True, '_': []} yield ps3, ['--param-e', 'f'], {'e': False, '_': []} yield ps3, ['--param-e', 'false'], {'e': False, '_': []} yield ps3, ['--param-e', 'no'], {'e': False, '_': []} # 15 yield ps3, ['--param-e', 'n'], {'e': False, '_': []} yield ps3, ['--param-e', '0'], {'e': False, '_': []} yield ps3, ['--param-e', 'off'], {'e': False, '_': []} yield ps3, ['--param-e', 'a'], { 'e': True, '_': [] }, 'WARNING: Unknown bool value, use True instead of \'a\'' ps4 = Parameters() ps4('prefix', '--param-') ps4.f = [] ps4.f.type = 'list:str' yield ps4, ['--param-f=1'], {'f': ['1'], '_': []} # 20 yield ps4, ['--param-f=1', '2', '3'], { 'f': ['1', '1', '2', '3'], '_': [] } ps5 = Parameters() ps5('prefix', '--param-') ps5.g = '' yield ps5, ['--param-g'], { 'g': True, '_': [] }, 'WARNING: Decleared type "str" ignored, use "bool" instead for option --param-g.' yield ps5, ['--param-g', 'a', 'b'], {'g': 'a', '_': ['b']} ps6 = Parameters() ps6('prefix', '--param-') ps6('hopts', '-?') ps6.h.required = True yield ps6, [], {}, 'ERROR: Option --param-h is required.', SystemExit ps7 = Parameters() ps7('prefix', '--param-') ps7.i = 1 yield ps7, ['--param-i=a' ], {}, None, ParameterTypeError, 'Unable to coerce' # mixed ps8 = Parameters() ps8('prefix', '--param-') ps8.a.type = 'str' ps8.b.type = 'str' ps8.c # 25 yield ps8, ['--param-a=1', '--param-b', '2', '--param-c="3"'], { 'a': '1', 'b': '2', 'c': '"3"', '_': [] } ps9 = Parameters() ps9('prefix', '--param-') ps9.a = [] ps9.a.type = 'list:str' ps9.b = [] ps9.c = [] yield ps9, ['--param-a=1', '2', '--param-b', 'a', '--param-c'], { 'a': ['1', '2'], 'b': ['a'], 'c': [], '_': [] } ps10 = Parameters() ps10('prefix', '--param-') ps10.a = False ps10.b = False ps10.c = False yield ps10, ['--param-a', '--param-b', '1', '--param-c=yes'], { 'a': True, 'b': True, 'c': True, '_': [] } ps11 = Parameters() ps11('prefix', '--param-') ps11.a ps11.b = 'a' ps11.c = 1 ps11.d = False ps11.e = [] yield ps11, ['--param-d'], { 'a': None, 'b': 'a', 'c': 1, 'd': True, 'e': [], '_': [] } yield ps11, [ 'a', '--param-d', 'no', 'b', '--param-c=100', '--param-e:l:s', '-1', '-2' ], { 'a': None, 'b': 'a', 'c': 100, 'd': False, 'e': ['-1', '-2'], '_': ['a', 'b'] }, 'WARNING: Decleared type "list" ignored, use "list:str" instead for option --param-e.' ps12 = Parameters() ps12.a ps12.b yield ps12, ['-a', '-b=1'], {'a': True, 'b': 1, '_': []}