Ejemplo n.º 1
0
class TestRegularExpressionRuleSet(unittest.TestCase):

    def setUp(self):
        self.expr = '[A-Z]+'
        self.prefix = r'\b'
        self.suffix = r'\b'
        self.rule_data = {
            're': self.expr
        }
        self.text = 'Some text'
        self.data = {
            'ruleset': 'Test ruleset',
            'prefix': self.prefix,
            'suffix': self.suffix,
            'flags': 'I',
            'rules': [
                self.rule_data
            ]
        }
        self.ruleset = RegularExpressionRuleset(self.data, 'testdata')

    def test_process(self):
        result = self.ruleset.process(self.text)
        self.assertEqual(result.lines, {1: self.text})
        self.assertEqual(len(result.rules), 1)
        processed_rule = result.rules[0]
        self.assertEqual(processed_rule.rule.data, self.rule_data)
        self.assertEqual(result.ruleset.data, self.data)
        self.assertEqual(processed_rule.pattern_matches,
            {
                self.expr: {
                    1: [1, [(0, 4), (5, 9)]]
                }
            }
        )
Ejemplo n.º 2
0
 def setUp(self):
     self.expr = '[A-Z]+'
     self.prefix = r'\b'
     self.suffix = r'\b'
     self.rule_data = {
         're': self.expr
     }
     self.text = 'Some text'
     self.data = {
         'ruleset': 'Test ruleset',
         'prefix': self.prefix,
         'suffix': self.suffix,
         'flags': 'I',
         'rules': [
             self.rule_data
         ]
     }
     self.ruleset = RegularExpressionRuleset(self.data, 'testdata')