本文整理匯總了Python中robot.utils.Matcher類的典型用法代碼示例。如果您正苦於以下問題:Python Matcher類的具體用法?Python Matcher怎麽用?Python Matcher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Matcher類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_regexp_matcher
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')
示例2: _get_matches_in_iterable
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)]
示例3: _message_matches
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
示例4: __init__
class TagStatDoc:
def __init__(self, pattern, doc):
self.text = doc
self._matcher = Matcher(pattern, ignore=['_'])
def matches(self, tag):
return self._matcher.match(tag)
示例5: ByNameKeywordRemover
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)
示例6: _SingleTagPattern
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
示例7: _get_matches_in_iterable
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)]
示例8: _SingleTagPattern
class _SingleTagPattern(object):
def __init__(self, pattern):
self._matcher = Matcher(pattern, ignore='_')
def match(self, tags):
return self._matcher.match_any(tags)
def __unicode__(self):
return self._matcher.pattern
示例9: ExcludeTests
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
示例10: _SingleTagPattern
class _SingleTagPattern(object):
def __init__(self, pattern):
self._matcher = Matcher(pattern, ignore='_')
def match(self, tags):
return self._matcher.match_any(tags)
# FIXME: Why only this class methods below??
def __unicode__(self):
return self._matcher.pattern
def __nonzero__(self):
return bool(self._matcher)
示例11: SingleTagPattern
class SingleTagPattern(object):
def __init__(self, pattern):
self._matcher = Matcher(pattern, ignore='_')
def match(self, tags):
return self._matcher.match_any(tags)
def __iter__(self):
yield self
def __unicode__(self):
return self._matcher.pattern
def __nonzero__(self):
return bool(self._matcher)
示例12: __init__
def __init__(self, pattern):
_KeywordRemover.__init__(self)
self._matcher = Matcher(pattern, ignore='_')
示例13: test_regexp_match_any
def test_regexp_match_any(self):
matcher = Matcher('H.llo', regexp=True)
assert matcher.match_any(('Hello', 'world'))
assert matcher.match_any(['jam', 'is', 'hillo'])
assert not matcher.match_any(('no', 'match', 'here'))
assert not matcher.match_any(())
示例14: test_ipy_bug_workaround
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'")
示例15: __init__
def __init__(self, pattern):
self.matcher = Matcher(pattern)