def test_itermatches(self): x = list(self.rule.itermatches(self.text)) self.assertEqual(len(x), 1) pattern, matches = x[0] flags = process_flags(self.rule_data['flags'], DEFAULT_FLAGS) self.assertEqual(pattern['original'], self.expr) self.assertEqual(pattern['compiled'], re.compile(self.prefix + self.expr + self.suffix, flags)) matches_list = list(matches) self.assertEqual(len(matches_list), 7) self.assertEqual(matches_list[0], (0, 4)) self.assertEqual(matches_list[1], (5, 9)) self.assertEqual(matches_list[2], (14, 18)) self.assertEqual(matches_list[3], (19, 25)) self.assertEqual(matches_list[4], (26, 27)) self.assertEqual(matches_list[5], (28, 35)) self.assertEqual(matches_list[6], (36, 45))
def test_process_flags_minus(self): flags = '-U+X' expected = re.S | re.X self.assertEqual(expected, process_flags(flags, DEFAULT_FLAGS))
def test_process_flags_all(self): flags = 'SLUMIX' default = 0 expected = re.S | re.L | re.U | re.M | re.I | re.X self.assertEqual(expected, process_flags(flags, default))