def test_parsed_args_valid_options(): def t(a, nl=None, sc=None, rf=None, d=False, v=False): assert a.APIfile == F assert a.nodelist == nl assert a.rankfile == rf assert a.sidecars == ([sc] if sc else None) assert a.dry == d assert a.verbose == v nl = 'http://localhost/nodelist.json' sc = 'contact services timeline' rf = 'rankfile.json' t(parsed_args([F, '-n', nl, '-s', sc, '-d', '-v']), nl=nl, sc=sc, d=True, v=True) t(parsed_args([F, '-n', nl, '-s', sc, '-d']), nl=nl, sc=sc, d=True) t(parsed_args([F, '-n', nl, '-s', sc, '-v']), nl=nl, sc=sc, v=True) t(parsed_args([F, '-n', nl, '-s', sc]), nl=nl, sc=sc) t(parsed_args([F, '-n', nl]), nl=nl) t(parsed_args([F, '-s', sc]), sc=sc) t(parsed_args([F, '-n', nl, '-r', rf]), nl=nl, rf=rf) t(parsed_args([F, '-n', nl, '-s', sc, '-r', rf]), nl=nl, sc=sc, rf=rf) t(parsed_args([F, '-n', nl, '-d']), nl=nl, d=True) t(parsed_args([F, '-s', sc, '-v']), sc=sc, v=True)
def run(argv=None): ''' Main function of |info_cname|. ''' ff = FFFlash(parsed_args(argv)) ff.log(info.ident) if not ff.access_for('api'): return (not ff.log('error loading API file', level=False)) modified = [] if ff.access_for('sidecars'): modified.append(handle_sidecars(ff)) if ff.access_for('nodelist'): modified.append(handle_nodelist(ff)) if ff.args.dry: ff.log('\n{}'.format(ff.api.pretty()), level='API file preview') else: if any(modified): ff.save() ff.log('saved api file') return (not any(modified))
def run(argv=None): ''' Main function of |info_cname|. ''' ff = FFFlash(parsed_args(argv)) ff.log(info.ident) if not ff.access_for('api'): return (not ff.log('error loading API file', level=False)) modified = [] if ff.access_for('sidecars'): modified.append( handle_sidecars(ff) ) if ff.access_for('nodelist'): modified.append( handle_nodelist(ff) ) if ff.args.dry: ff.log('\n{}'.format(ff.api.pretty()), level='API file preview') else: if any(modified): ff.save() ff.log('saved api file') return (not any(modified))
def test_parsed_args_rankefile_with_or_without_nodelist(): for ta in [ [F, '-n'], [F, '--nodelist'], [F, '-r'], [F, '--rankfile'], [F, '-n', N, '-r'], [F, '--nodelist', N, '--rankfile'], [F, '-r'], [F, '--rankfile', R], ]: sys_ex(ta) for ta in [ [F, '-n', N], [F, '--nodelist', N], [F, '-n', N, '-r', R], [F, '--nodelist', N, '--rankfile', R], ]: assert parsed_args(ta)
def test_parsed_args_rank_details(): a = vars(parsed_args([F])) for t in [ 'rankclients', 'rankoffline', 'rankonline', 'rankposition', 'rankwelcome' ]: sys_ex([F, '--{}'.format(t)]) sys_ex([F, '--{}'.format(t), 'test']) v = a.get(t) assert isinstance(v, float) assert v > 0
def fake_ffflash( apifile, nodelist=None, rankfile=None, dry=False, verbose=False, sidecars=[] ): a = [str(apifile)] if nodelist: a.extend(['-n', str(nodelist)]) if rankfile: a.extend(['-r', str(rankfile)]) if dry: a.append('-d') if verbose: a.append('-v') if sidecars: a.append('-s') [a.append(str(s)) for s in sidecars] return FFFlash(parsed_args(a))
def fake_ffflash(apifile, nodelist=None, rankfile=None, dry=False, verbose=False, sidecars=[]): a = [str(apifile)] if nodelist: a.extend(['-n', str(nodelist)]) if rankfile: a.extend(['-r', str(rankfile)]) if dry: a.append('-d') if verbose: a.append('-v') if sidecars: a.append('-s') [a.append(str(s)) for s in sidecars] return FFFlash(parsed_args(a))
def sys_ex(a): with pytest.raises(SystemExit): parsed_args(a)