예제 #1
0
def test_plus():
    c = Command('ndcli',
                Group(Token('val'), Argument('val', action='append'), nargs='+'),
                Group(Token('endval'), Argument('endval'), nargs='?'))
    assert c.parse([]).errors
    assert c.parse(['endval', 'a']).errors
    assert c.parse(['val', 'a']).values == {'val': ['a'], 'endval': None}
    assert c.parse(['val', 'a', 'val', 'b']).values == {'val': ['a', 'b'], 'endval': None}
    assert c.parse(['val', 'a', 'val', 'b', 'endval', 'c']).values == {'val': ['a', 'b'], 'endval': 'c'}
예제 #2
0
def test_ambiguity():
    c = Command('ndcli',
                Argument('var', nargs='*', stop_at='end'),
                Group(Token('end'), Argument('endval'), nargs='?'))
    assert c.parse(['a']).values == {'var': ['a'], 'endval': None}
    assert c.parse(['a', 'end', '1']).values == {'var': ['a'], 'endval': '1'}
    assert c.parse('a end b end c'.split()).values == {'var': ['a', 'end', 'b'], 'endval': 'c'}
예제 #3
0
def test_star_star():
    c = Command('ndcli',
                Group(Argument('fields', choices=['a', 'b'], action='append_unique'), Argument('values', action='append'), nargs='*'),
                Argument('second', nargs='*'))
    assert c.parse(['a', '1', '2', '3']).values == {'fields': ['a'], 'values': ['1'], 'second': ['2', '3']}
    assert c.parse(['a', '1', 'b', 'c', '2', '3']).values == {'fields': ['a', 'b'], 'second': ['2', '3'], 'values': ['1', 'c']}
    assert c.parse([]).values == {'fields': [], 'second': [], 'values': []}
예제 #4
0
def test_completion_quoted():
    def completions(line):
        return c.complete(line, len(line))
    c = Command('ndcli', Group(Argument('field', choices=('a b', 'a!$\\'), action='append_unique')))
    assert completions('ndcli ') == set(['a\ b', 'a\'!\'\$\\\\'])
    assert completions("ndcli 'a") == set(["'a b'", "'a!$\\'"])
    assert completions('ndcli "a') == set(['"a b"', '"a"\'!\'"\$\\\\"'])
    assert completions('ndcli a\ ') == set(['a\\ b'])
예제 #5
0
    def test_groups(self):
        c = Command('ndcli', Group(Token('ttl'), Argument('ttl'), nargs='?'),
                    Command('test'))

        assert c.parse(('ttl', '10', 'test')).values == {'ttl': '10'}
        assert c.parse(('test', )).values == {'ttl': None}
        assert c.parse(('bbl', '10', 'test')).errors
        assert c.parse(('ttl', '10')).errors
예제 #6
0
 def setUp(self):
     self.c = Command(
         'ndcli',
         Command(
             'create',
             Command('pool', Argument('poolname'),
                     Group(Token('vlan'), Argument('vlan'), nargs='?'),
                     Argument('attrs', metavar='KEY:VALUE', nargs='*'))))
예제 #7
0
 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='*')))
예제 #8
0
def test_completion2():
    def completions(line):
        return c.complete(line, len(line))
    c = Command('ndcli',
                Group(Argument('field', choices=('f1', 'f2', 'f3'), action='append_unique'),
                      Argument('value', action='append'),
                      nargs='*'))
    assert completions('ndcli ') == set(['f1', 'f2', 'f3'])
    assert completions('ndcli f1 ') == set()
    assert completions('ndcli f1 1 ') == set(['f2', 'f3'])
    assert completions('ndcli f1 1 f') == set(['f2', 'f3'])
    assert completions('ndcli f1 1 f2 2 ') == set(['f3'])
예제 #9
0
    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'])