Beispiel #1
0
 def test_regexp_matcher(self):
     matcher = Matcher('F .*', ignore=['-'], caseless=False, spaceless=True,
                       regexp=True)
     assert matcher.pattern == 'F .*'
     assert matcher.match('Foo')
     assert matcher.match('--Foo')
     assert not matcher.match('foo')
 def test_regexp_matcher(self):
     matcher = Matcher('F .*', ignore=['-'], caseless=False, spaceless=True,
                       regexp=True)
     assert matcher.pattern == 'F .*'
     assert matcher.match('Foo')
     assert matcher.match('--Foo')
     assert not matcher.match('foo')
    def page_should_not_contain_match(self, txt, ignore_case=False, error_message=None):
        """Fails if the given string matches the given pattern.

        Pattern matching is similar as matching files in a shell, and it is always case-sensitive.
        In the pattern, * matches to anything and ? matches to any single character.

        Note that the entire screen is only considered a string for this keyword, so if you want to search
        for the string "something" and it is somewhere other than at the beginning or end of the screen it
        should be reported as follows: **something**

        The search is case sensitive, if you want ignore this you can pass the argument: ignore_case=${True} and you
        can edit the raise exception message with error_message.

        Example:
            | Page Should Not Contain Match | **something** |
            | Page Should Not Contain Match | **so???hing** |
            | Page Should Not Contain Match | **someTHING** | ignore_case=${True} |
            | Page Should Not Contain Match | **something** | error_message=New error message |
        """
        message = error_message
        all_screen = self._read_all_screen()
        if ignore_case:
            txt = txt.lower()
            all_screen = all_screen.lower()
        matcher = Matcher(txt, caseless=False, spaceless=False)
        result = matcher.match(all_screen)
        if result:
            if message is None:
                message = 'There are matches found for "' + txt + '" pattern'
            raise Exception(message)
Beispiel #4
0
class TagStatDoc:
    def __init__(self, pattern, doc):
        self.text = doc
        self._matcher = Matcher(pattern, ignore=['_'])

    def matches(self, tag):
        return self._matcher.match(tag)
Beispiel #5
0
    def page_should_not_contain_match(
            self,
            txt: str,
            ignore_case: bool = False,
            error_message: Optional[str] = None) -> None:
        """Assert that the text displayed on the mainframe screen does NOT match the given pattern.

        Pattern matching is similar to matching files in a shell, and it is always case sensitive.
        In the pattern, * matches anything and ? matches any single character.

        Note that for this keyword the entire screen is considered a string. So if you want to search
        for the string "something" and it is somewhere other than at the beginning or end of the screen, it
        should be reported as follows: **something**

        The assertion is case sensitive. If you want it to be case insensitive, you can pass the argument ignore_case=True.

        You can change the exception message by setting a custom string to error_message.

        Example:
            | Page Should Not Contain Match | **something** |
            | Page Should Not Contain Match | **so???hing** |
            | Page Should Not Contain Match | **someTHING** | ignore_case=True |
            | Page Should Not Contain Match | **something** | error_message=New error message |
        """
        message = error_message
        all_screen = self._read_all_screen()
        if ignore_case:
            txt = txt.lower()
            all_screen = all_screen.lower()
        matcher = Matcher(txt, caseless=False, spaceless=False)
        result = matcher.match(all_screen)
        if result:
            if message is None:
                message = 'There are matches found for "' + txt + '" pattern'
            raise Exception(message)
Beispiel #6
0
class ByNameKeywordRemover(_KeywordRemover):
    def __init__(self, pattern):
        _KeywordRemover.__init__(self)
        self._matcher = Matcher(pattern, ignore='_')

    def start_keyword(self, kw):
        if self._matcher.match(kw.name) and not self._warning_or_error(kw):
            self._clear_content(kw)
class TagStatDoc:

    def __init__(self, pattern, doc):
        self.text = doc
        self._matcher = Matcher(pattern, ignore=['_'])

    def matches(self, tag):
        return self._matcher.match(tag)
class ByNameKeywordRemover(_KeywordRemover):

    def __init__(self, pattern):
        _KeywordRemover.__init__(self)
        self._matcher = Matcher(pattern, ignore='_')

    def start_keyword(self, kw):
        if self._matcher.match(kw.name) and not self._contains_warning(kw):
            self._clear_content(kw)
class _SingleTagPattern(object):
    def __init__(self, pattern):
        self._matcher = Matcher(pattern, ignore=['_'])

    def match(self, tags):
        return any(self._matcher.match(tag) for tag in tags)

    def __unicode__(self):
        return self._matcher.pattern
Beispiel #10
0
class _SingleTagPattern(object):
    def __init__(self, pattern):
        self._matcher = Matcher(pattern, ignore=["_"])

    def match(self, tags):
        return any(self._matcher.match(tag) for tag in tags)

    def __unicode__(self):
        return self._matcher.pattern
class ExcludeTests(SuiteVisitor):

    def __init__(self, pattern):
        self.matcher = Matcher(pattern)

    def start_suite(self, suite):
        """Remove tests that match the given pattern."""
        suite.tests = [t for t in suite.tests if not self._is_excluded(t)]

    def _is_excluded(self, test):
        return self.matcher.match(test.name) or self.matcher.match(test.longname)

    def end_suite(self, suite):
        """Remove suites that are empty after removing tests."""
        suite.suites = [s for s in suite.suites if s.test_count > 0]

    def visit_test(self, test):
        """Avoid visiting tests and their keywords to save a little time."""
        pass
Beispiel #12
0
def _get_matches_in_iterable(iterable, pattern, case_insensitive=False,
                             whitespace_insensitive=False):
    if not is_string(pattern):
        raise TypeError("Pattern must be string, got '%s'." % type_name(pattern))
    regexp = False
    if pattern.startswith('regexp='):
        pattern = pattern[7:]
        regexp = True
    elif pattern.startswith('glob='):
        pattern = pattern[5:]
    matcher = Matcher(pattern,
                      caseless=is_truthy(case_insensitive),
                      spaceless=is_truthy(whitespace_insensitive),
                      regexp=regexp)
    return [string for string in iterable
            if is_string(string) and matcher.match(string)]
 def _message_matches(self, actual, expected):
     if actual == expected:
         return True
     if expected.startswith('REGEXP:'):
         pattern = '^%s$' % expected.replace('REGEXP:', '', 1).strip()
         if re.match(pattern, actual, re.DOTALL):
             return True
     if expected.startswith('GLOB:'):
         pattern = expected.replace('GLOB:', '', 1).strip()
         matcher = Matcher(pattern, caseless=False, spaceless=False)
         if matcher.match(actual):
             return True
     if expected.startswith('STARTS:'):
         start = expected.replace('STARTS:', '', 1).strip()
         if actual.startswith(start):
             return True
     return False
Beispiel #14
0
def _get_matches_in_iterable(iterable, pattern, case_insensitive=False,
                             whitespace_insensitive=False):
    if not iterable:
        return []
    regexp = False
    if not isinstance(pattern, basestring):
        raise TypeError(
            "Pattern must be string, got '%s'." % type(pattern).__name__)
    if pattern.startswith('regexp='):
        pattern = pattern[7:]
        regexp = True
    elif pattern.startswith('glob='):
        pattern = pattern[5:]
    matcher = Matcher(pattern, caseless=case_insensitive,
                      spaceless=whitespace_insensitive, regexp=regexp)
    return [string for string in iterable
            if isinstance(string, basestring)
            and matcher.match(string)]
Beispiel #15
0
 def test_ipy_bug_workaround(self):
     # https://github.com/IronLanguages/ironpython2/issues/515
     matcher = Matcher("'12345678901234567890'")
     assert matcher.match("'12345678901234567890'")
     assert not matcher.match("'xxx'")
 def test_ipy_bug_workaround(self):
     # https://github.com/IronLanguages/ironpython2/issues/515
     matcher = Matcher("'12345678901234567890'")
     assert matcher.match("'12345678901234567890'")
     assert not matcher.match("'xxx'")