def setUp(self): self.c = Command( 'ndcli', Option('D', 'detailed', help='detailed return codes'), Option('s', 'server', help='Dim server URL', action='store'), Command( 'set', Group(Argument('field', choices=('master', 'mail', 'export_file'), action='append_unique'), Argument('value', action='append'), nargs='*')))
def test_plus_options(): c = Command('ndcli', Option('q', 'quiet'), Command('sub', Argument('var', nargs='+', stop_at='end'))) assert c.parse(['sub', 'a']).values == {'var': ['a'], 'quiet': None} assert c.parse(['sub', 'a', '-q']).values == {'var': ['a'], 'quiet': True}
def test_default_subcommand(): c = Command('ndcli', Command('sub1', Argument('food'), Option('', 'drink'), defaults={'run': 'sub1'}), Command('sub2', defaults={'run': 'sub2'}), default_subcommand='sub1') assert c.parse([]).values == {'run': 'sub1', 'food': None, 'drink': None} assert c.parse(['sub1']).values.run == 'sub1' assert c.parse(['sub2']).values.run == 'sub2'
def test_completion(self): def completions(line): return c.complete(line, len(line)) c = Command( 'ndcli', Option('D', 'detailed'), Option('q', 'quiet'), Command( 'create', Command('pool', Argument('poolname'), Option('p', 'perfect'), Group(Token('vlan'), Argument('vlan'), nargs='?'), Command('a')))) assert completions('ndcli ') == set(['create']) assert completions('ndcli -') == set( ['--detailed', '-D', '--quiet', '-q']) assert completions('prog -- -') == set() assert completions('prog create ') == set(['pool']) assert completions('prog create pool ') == set() assert completions('prog create pool -') == set( ['--detailed', '-D', '--quiet', '-q', '--perfect', '-p']) assert completions('prog create pool test ') == set(['vlan', 'a']) assert completions('prog create pool test vlan ') == set() assert completions('prog create pool test vlan 1 ') == set(['a'])