Exemplo n.º 1
0
 def registered_function(value, frame):
     if regex is None:
         return func(value, frame, [])
     error_msg = value.args[0]
     match = re.match(regex, error_msg)
     if match:
         return func(value, frame, match.groups())
     return []
    def re_matches(self, text, regexp, results):
        """Check that text matches regexp and gives the right match groups.

        result is a tuple containing the expected return values for groups()
        and groupdict().
        """
        groups, named_groups = results
        self.assertRegexpMatches(text, regexp)   # does pretty printing
        match = re.match(regexp, text)
        self.assertTrue(match)
        self.assertEqual(groups, match.groups())
        self.assertEqual(named_groups, match.groupdict())
        self.check_more_about_re(text, regexp)
    def re_matches(self, text, regexp, results):
        """Check that text matches regexp and gives the right match groups.

        result is a tuple containing the expected return values for groups()
        and groupdict().
        """
        groups, named_groups = results
        self.assertRegexp(text, regexp)   # does pretty printing
        match = re.match(regexp, text)
        self.assertTrue(match)
        self.assertEqual(groups, match.groups())
        self.assertEqual(named_groups, match.groupdict())
        self.check_more_about_re(text, regexp)
    def check_more_about_re(self, text, regexp):
        """Check various properties about the regexp.

        Properties checked are configurable via global constants. These
        properties are not stricly speaking required but they help to
        detect potential issues much more quickly.
        """
        if CHECK_RE_VALUE:
            self.assertTrue(regexp.startswith('^'))
            self.assertTrue(regexp.endswith('$'))
        found = False
        for other_name, other_re in re.ALL_REGEXPS.items():
            if other_re == regexp:
                found = True
                if CHECK_RE_NAME:
                    self.assertTrue(other_name.endswith('_RE'))
            elif CHECK_OTHERS_DONT_MATCH:
                details = "text '%s' matches %s (on top of %s)" % \
                        (text, other_name, regexp)
                self.assertNotRegexpMatches(text, other_re, details)
                no_match = re.match(other_re, text)
                self.assertEqual(no_match, None, details)
        if CHECK_RE_LISTED:
            self.assertTrue(found)
    def check_more_about_re(self, text, regexp):
        """Check various properties about the regexp.

        Properties checked are configurable via global constants. These
        properties are not stricly speaking required but they help to
        detect potential issues much more quickly.
        """
        if CHECK_RE_VALUE:
            self.assertTrue(regexp.startswith('^'))
            self.assertTrue(regexp.endswith('$'))
        found = False
        for other_name, other_re in re.ALL_REGEXPS.items():
            if other_re == regexp:
                found = True
                if CHECK_RE_NAME:
                    self.assertTrue(other_name.endswith('_RE'))
            elif CHECK_OTHERS_DONT_MATCH:
                details = "text '%s' matches %s (on top of %s)" % \
                        (text, other_name, regexp)
                self.assertNotRegexp(text, other_re, details)
                no_match = re.match(other_re, text)
                self.assertEqual(no_match, None, details)
        if CHECK_RE_LISTED:
            self.assertTrue(found)