Пример #1
0
 def test_simple(self):
     p = parse_regex('/test/')
     self.assertEqual(p, re.compile("test"), "Should have no modifiers")
     self.assertIsNotNone(p.match("test"),
                          "Should match test string 'test'")
     self.assertIsNone(p.match("Test"),
                       "Should not match test string 'Test'")
Пример #2
0
 def test_alternative_separator(self):
     p = parse_regex('|test|i')
     self.assertEqual(p, re.compile("test", re.I), "Should have I modifier")
     self.assertIsNotNone(p.match("test"),
                          "Should match test string 'test'")
     self.assertIsNotNone(p.match("Test"),
                          "Should match test string 'Test'")
Пример #3
0
 def test_case_insensitive(self):
     p = parse_regex('/test/i')
     self.assertEqual(p, re.compile("test", re.I), "Should have I modifier")
     self.assertIsNotNone(p.match("test"),
                          "Should match test string 'test'")
     self.assertIsNotNone(p.match("Test"),
                          "Should match test string 'Test'")
Пример #4
0
    def test_case_insensitive_multiline(self):
        p = parse_regex(r'/test\s+me/im')
        self.assertEqual(p, re.compile(r"test\s+me", re.I | re.M),
                         "Should have I and M modifier")

        test_string = "test\nme"
        self.assertIsNotNone(p.match(test_string),
                             "Should match test string {}".format(test_string))

        test_string = "test\nME"
        self.assertIsNotNone(p.match(test_string),
                             "Should match test string {}".format(test_string))
Пример #5
0
    def categorize(series):
        for c in config:
            if series == c['code']:
                return c['code']
            elif c['code'] in str(series):
                return c['code']
            elif c['name'] in str(series):
                return c['code']

            for r in c.get('regex', []):
                p = parse_regex(r)
                if p.match(str(series)) is not None:
                    return c['code']

        return 'not matched'
Пример #6
0
 def __post_init__(self):
     assert self.type == 'regex'
     object.__setattr__(self, '__matcher', parse_regex(self.pattern))