Esempio n. 1
0
 def test_get_match_multiple_regex_fail(self):
     """
     Test one of multiple 'regex' patterns matches
     """
     shortcut = {'regex': ['m1', 'm2'], 'shell': 'result'}
     input_data = 'm3'
     result = main.get_match(input_data, shortcut)
     self.assertIsNone(result)
Esempio n. 2
0
 def test_get_match_multiple_regex(self):
     """
     Test one of multiple 'regex' patterns matches
     """
     shortcut = {'regex': ['m1', 'm2'], 'bash': 'result'}
     input_data = 'm1'
     result = main.get_match(input_data, shortcut)
     self.assertEqual(result, {'bash': 'result'})
Esempio n. 3
0
    def test_get_match_bad_label(self):
        """
        Test that a query with specific label does not match a shortcut with a
        different label
        """
        shortcut = {'match': '', 'shell': '', 'label': 'other_label'}

        result = main.get_match('input_data', shortcut, label='some_label')
        self.assertIsNone(result)
Esempio n. 4
0
 def test_get_match_regex_no_match(self):
     """
     Test that "format" matching works correctly
     """
     shortcut = {
         'match': r'My name is (\w+) Potter',
         'bash': 'echo "Hello {}!"',
     }
     input_data = 'My name is not Harry Potter'
     result = main.get_match(input_data, shortcut)
     self.assertIsNone(result)
Esempio n. 5
0
 def test_get_match_parse_regex(self):
     """
     Test that "regex" matching works correctly
     """
     shortcut = {
         'regex': r'My name is (\w+) Potter',
         'bash': 'echo "Hello {}!"',
     }
     input_data = 'My name is Harry Potter'
     result = main.get_match(input_data, shortcut)
     self.assertEqual(result, {'bash': 'echo "Hello Harry!"'})
Esempio n. 6
0
    def test_get_match_multilabel(self):
        """
        Test that a pattern is picked when given label is in pattern's label
        list
        """
        shortcut = {
            'match': 'input_data',
            'bash': 'command',
            'label': ['l1', 'l2']
        }

        result = main.get_match('input_data', shortcut, label='l2')
        self.assertEqual(result, {'bash': 'command'})
Esempio n. 7
0
    def test_get_match_multilabel_fail(self):
        """
        Test that a pattern is not picked if given label is not in the
        pattern's label list
        """
        shortcut = {
            'match': 'input_data',
            'shell': 'command',
            'label': ['l1', 'l2']
        }

        result = main.get_match('input_data', shortcut, label='l3')
        self.assertIsNone(result)