Beispiel #1
0
 def test_matching_regex_arguments(self):
     self.assertEqual(
         _matches_fuzzy(0, 0, 'sh ver .* blue'.split(),
                        'show version wx abc {arg}', {}, True)[0],
         {'arg': 'blue'})
     self.assertEqual(
         _matches_fuzzy(0, 0, 'sh a .* b .*c c'.split(),
                        'show {a} wx {b} abc {c}', {}, True)[0], {
                            'a': 'a',
                            'b': 'b',
                            'c': 'c'
                        })
     self.assertEqual(
         _matches_fuzzy(0, 0, 'sh .* a b c'.split(),
                        'show version wx abc {a} {b} {c}', {}, True)[0], {
                            'a': 'a',
                            'b': 'b',
                            'c': 'c'
                        })
     self.assertEqual(
         _matches_fuzzy(0, 0, 'sh .* a b c c'.split(),
                        'show version wx abc {a} {b} {c} c', {}, True)[0], {
                            'a': 'a',
                            'b': 'b',
                            'c': 'c'
                        })
     self.assertEqual(
         _matches_fuzzy(0, 0, 'sh .* a b c c.* f'.split(),
                        'show version wx abc {a} {b} {c} c d {f}', {},
                        True)[0], {
                            'a': 'a',
                            'b': 'b',
                            'c': 'c',
                            'f': 'f'
                        })
Beispiel #2
0
 def test_extra_spaces(self):
     self.assertIsNotNone(_matches_fuzzy(0, 0, 
         '   show    show  show     '.split(), 'show show show', {}, False))
     self.assertIsNotNone(_matches_fuzzy(0, 0, 
             '   show    .*  show     '.split(), 'show a show', {}, True))
     self.assertEqual(_fuzzy_search_command(
                                         ' s  e ipv6   n  d', False)[0][0], 
                                         'show eigrp ipv6 neighbors detail')
Beispiel #3
0
    def test_matching_simple(self):
        self.assertIsNotNone(
            common._matches_fuzzy(0, 0, 's v'.split(), 'show version', {},
                                  False))
        self.assertIsNotNone(
            common._matches_fuzzy(0, 0, 'sh ver'.split(), 'show version', {},
                                  False))
        self.assertIsNotNone(
            common._matches_fuzzy(0, 0, 'show vers'.split(), 'show version',
                                  {}, False))
        self.assertIsNotNone(
            common._matches_fuzzy(0, 0, 'sh version'.split(), 'show version',
                                  {}, False))

        self.assertIsNotNone(
            common._matches_fuzzy(0, 0, 's v'.split(), 'show version', {},
                                  True))
        self.assertIsNotNone(
            common._matches_fuzzy(0, 0, 'sh ver'.split(), 'show version', {},
                                  True))
        self.assertIsNotNone(
            common._matches_fuzzy(0, 0, 'show vers'.split(), 'show version',
                                  {}, True))
        self.assertIsNotNone(
            common._matches_fuzzy(0, 0, 'sh version'.split(), 'show version',
                                  {}, True))
Beispiel #4
0
 def test_double_argument(self):
     self.assertEqual(
         _matches_fuzzy(0, 0, 'a b c d'.split(), 'a b c {w}', {}, True)[0],
         {'w': 'd'})
     self.assertEqual(
         _matches_fuzzy(0, 0, 'a b c d e'.split(), 'a b c {w}', {},
                        True)[0], {'w': 'd e'})
     self.assertEqual(
         _matches_fuzzy(0, 0, 's b vpnv4 unicast a s'.split(),
                        'show bgp {stuff} all summary', {}, True)[0],
         {'stuff': 'vpnv4 unicast'})
     self.assertEqual(
         _matches_fuzzy(0, 0, 'a a b b'.split(), '{a} {b}', {}, True)[0], {
             'a': 'a a',
             'b': 'b b'
         })
     self.assertEqual(
         _matches_fuzzy(0, 0, 'w x y z z'.split(), 'w x y {a} {vrf}', {},
                        True)[0], {
                            'a': 'z',
                            'vrf': 'z'
                        })
     self.assertEqual(
         _matches_fuzzy(0, 0, 'w x y z z z'.split(), 'w x y {a} {vrf}', {},
                        True)[0], {
                            'a': 'z z',
                            'vrf': 'z'
                        })
     self.assertEqual(
         _matches_fuzzy(0, 0, 'w x y a b c'.split(), 'w x y {a} {b} {c}',
                        {}, True)[0], {
                            'a': 'a',
                            'b': 'b',
                            'c': 'c'
                        })
Beispiel #5
0
 def test_single_argument(self):
     self.assertEqual(
         _matches_fuzzy(0, 0, 'a b c d'.split(), 'a b c {vrf}', {},
                        True)[0], {'vrf': 'd'})
     self.assertEqual(
         _matches_fuzzy(0, 0, 'a b c d'.split(), 'a {vrf} c d', {},
                        True)[0], {'vrf': 'b'})
     self.assertEqual(
         _matches_fuzzy(0, 0, 'a b c d'.split(), '{vrf} b {rd} {instance}',
                        {}, True)[0], {
                            'vrf': 'a',
                            'rd': 'c',
                            'instance': 'd'
                        })
     self.assertEqual(
         _matches_fuzzy(0, 0, 'abc .* bdc ef'.split(),
                        'abcd www www {vrf} ef', {}, True)[0],
         {'vrf': 'bdc'})
     self.assertEqual(
         _matches_fuzzy(0, 0, 'a .* w .* p .* v'.split(),
                        'a b c {vrf} e f {instance} h v', {}, True)[0], {
                            'vrf': 'w',
                            'instance': 'p'
                        })
     self.assertEqual(
         _matches_fuzzy(0, 0, 'abc fileA fileB'.split(),
                        'abcdef {fileA} {fileB}', {}, True)[0], {
                            'fileA': 'fileA',
                            'fileB': 'fileB'
                        })
Beispiel #6
0
    def test_matching_arguments(self):
        self.assertEqual(
            common._matches_fuzzy(0, 0, 'sh ver blue'.split(),
                                  'show version {arg}', {}, False)[0],
            {'arg': 'blue'})
        self.assertEqual(
            common._matches_fuzzy(0, 0, 'sh red blue'.split(),
                                  'show {one} {arg}', {}, False)[0], {
                                      'arg': 'blue',
                                      'one': 'red'
                                  })
        self.assertEqual(
            common._matches_fuzzy(0, 0, 'sh red blu'.split(),
                                  'show {one} blue', {}, False)[0],
            {'one': 'red'})

        self.assertEqual(
            common._matches_fuzzy(0, 0, 'sh ver blue'.split(),
                                  'show version {arg}', {}, True)[0],
            {'arg': 'blue'})
        self.assertEqual(
            common._matches_fuzzy(0, 0, 'sh red blue'.split(),
                                  'show {one} {arg}', {}, True)[0], {
                                      'arg': 'blue',
                                      'one': 'red'
                                  })
        self.assertEqual(
            common._matches_fuzzy(0, 0, 'sh red blu'.split(),
                                  'show {one} blue', {}, True)[0],
            {'one': 'red'})

        self.assertEqual(
            common._matches_fuzzy(0, 0, 'sh red blu abc arg bg w w'.split(),
                                  'show {one} blue abc {arg} bgp {a} {b}', {},
                                  False)[0], {
                                      'one': 'red',
                                      'arg': 'arg',
                                      'a': 'w',
                                      'b': 'w'
                                  })
        self.assertEqual(
            common._matches_fuzzy(0, 0, 'sh red blu abc arg bg w w'.split(),
                                  'show {one} blue abc {arg} bgp {a} {b}', {},
                                  True)[0], {
                                      'one': 'red',
                                      'arg': 'arg',
                                      'a': 'w',
                                      'b': 'w'
                                  })
Beispiel #7
0
    def test_matching_regex(self):
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'show a b .* c'.split(), 
                                                    'show a b c d c', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'show .* .* .* .*'.split(), 
                                                    'show a b c d c', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 
            'show a b .* .* .* .*'.split(), 'show a b c d c abcdef', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'show a.*'.split(), 
                                                    'show a b c d c', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'show a .* d .*'.split(), 
                                                    'show a b c d c', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'show a .* d.* c'.split(), 
                                                    'show a b c d c', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, '.*'.split(), 
                                                    'show a b c d c', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'show (a|b) (b|c) .*'.split(), 
                                                    'show a b c d c', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'show .* d'.split(), 
                                                'show a b c d c d', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 
                                                'show .* a b c d e f g'.split(), 
                                    'show a b c d c d a b c d e f g', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'show [ab]* ab'.split(), 
                                                        'show ab ab', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'show [ab]* ab .* cd'.split(),    
                                            'show abababab ab oo cd', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'a? b c'.split(), 
                                                            'a b c', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'a b [a-z] d'.split(), 
                                                        'a b c d', {}, True))

        self.assertIsNotNone(_matches_fuzzy(0, 0, 'sh ver .*'.split(), 
                                            'show version abc def', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'sh ver .* int'.split(), 
                                    'show version abc def interface', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 
                                            'sh ver .* int b .* wwx'.split(), 
                        'show version abc def interface bgp mb wwx', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'sh .* inst al sess'.split(), 
                                    'show bgp instance all sessions', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 
                                                'sh .* inst al [a-z]*'.split(), 
                                    'show bgp instance all sessions', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'sh .* inst.*'.split(), 
                                    'show bgp instance all sessions', {}, True))

        self.assertIsNotNone(_matches_fuzzy(0, 0, 'sh .* inst.*'.split(), 
                                    'show bgp instance all sessions', {}, True))
        self.assertIsNotNone(_matches_fuzzy(0, 0, 'sh .* inst.*'.split(), 
                                    'show bgp instance all sessions', {}, True))
Beispiel #8
0
 def test_matching_negative_regex(self):
     self.assertIsNone(_matches_fuzzy(0, 0, 
                         'show a b .*'.split(), 'show a b c d', {}, False))
     self.assertIsNone(_matches_fuzzy(0, 0, 
             'show a b [a-z] [a-z] [a-z]'.split(), 'show a b c d', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 
                     'show a b .* .* .*'.split(), 'show a b c d', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 
                     'show a b .* f .*'.split(), 'show a b c d', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 
                     'show a b .* .* f'.split(), 'show a b c d', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 
                         'show a b .* m'.split(), 'show a b c d', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 
                 'show a b .* [a-z]'.split(), 'show a b c {ww}', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 
                             'show .*'.split(), 'show a {a} c', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 'show .* a f'.split(), 
                                                 'show a {a} c', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 'show .* a f .*'.split(), 
                                             'show a {vrf} {vrf}', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 'show .* a.* c'.split(), 
                                                 'show a {a} c', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 'show .* a b c'.split(), 
                                                  'show a b c', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 'a? b c'.split(), 
                                                          'b c', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 'sh .* inst al [ab]*'.split(), 
                                 'show bgp instance all sessions', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 'sh .* inst x [a-z]*'.split(), 
                                 'show bgp instance all sessions', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 'show [a-z]*'.split(), 
                                                 'show a b c d c', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 'show [ab]* ab'.split(), 
                                                     'show ab', {}, True))
     self.assertIsNone(_matches_fuzzy(0, 0, 'show ac ab .*'.split(), 
                                                 'show abc ab c', {}, True))
Beispiel #9
0
    def test_matching_negative(self): 
        self.assertIsNone(_matches_fuzzy(0, 0, 'sh ver blue'.split(), 
                                        'show version {arg} {b}', {}, False))
        self.assertIsNone(_matches_fuzzy(0, 0, 'sh ver blue'.split(), 
                                        'show version {arg} {b}', {}, True))

        self.assertIsNone(_matches_fuzzy(0, 0, 'show xyz'.split(), 
                                                    'show version', {}, False))
        self.assertIsNone(_matches_fuzzy(0, 0, 'show xyz'.split(), 
                                                    'show version', {}, True))

        self.assertIsNone(_matches_fuzzy(0, 0, 'show www xyz'.split(), 
                                                'show {b} version', {}, False))
        self.assertIsNone(_matches_fuzzy(0, 0, 'show www xyz'.split(), 
                                                'show {b} version', {}, True))

        self.assertIsNone(_matches_fuzzy(0, 0, 
                                            'sh bgp ixia inst all all'.split(), 
                    'show bgp instance {instance} all all summary', {}, False))
        self.assertIsNone(_matches_fuzzy(0, 0, 
                                        'sh bgp inst all all summary'.split(), 
                    'show bgp instance {instance} all all summary', {}, True))

        self.assertIsNone(_matches_fuzzy(0, 0, 'sh .*'.split(), 
                    'show bgp instance {instance} all all summary', {}, False))
        self.assertIsNone(_matches_fuzzy(0, 0, 'sh .*'.split(), 
                    'show bgp instance {instance} all all summary', {}, True))

        self.assertIsNone(_matches_fuzzy(0, 0, '.*'.split(), 
                                'show bgp instance all all summary', {}, False))
        self.assertIsNone(_matches_fuzzy(0, 0, 
                                    'show bgp instance .* all all .*'.split(),
                                'show bgp instance all all summary', {}, False))
        
        self.assertIsNone(_matches_fuzzy(0, 0, 
                            'show abb ab'.split(), 'show abc ab', {}, False))
        self.assertIsNone(_matches_fuzzy(0, 0, 
                                'ow abc ab'.split(), 'show abc ab', {}, False))

        self.assertIsNone(_matches_fuzzy(0, 0, 
                            'show abb ab xd'.split(), 'show {ww}', {}, False))
        self.assertIsNone(_matches_fuzzy(0, 0, 
                    'show show x abb ab xd'.split(), '{x} abb {wx}', {}, False))