diff options
author | nkozlovskiy <[email protected]> | 2023-09-29 12:24:06 +0300 |
---|---|---|
committer | nkozlovskiy <[email protected]> | 2023-09-29 12:41:34 +0300 |
commit | e0e3e1717e3d33762ce61950504f9637a6e669ed (patch) | |
tree | bca3ff6939b10ed60c3d5c12439963a1146b9711 /contrib/python/PyHamcrest/py3/hamcrest/library/text/stringmatches.py | |
parent | 38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff) |
add ydb deps
Diffstat (limited to 'contrib/python/PyHamcrest/py3/hamcrest/library/text/stringmatches.py')
-rw-r--r-- | contrib/python/PyHamcrest/py3/hamcrest/library/text/stringmatches.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/contrib/python/PyHamcrest/py3/hamcrest/library/text/stringmatches.py b/contrib/python/PyHamcrest/py3/hamcrest/library/text/stringmatches.py new file mode 100644 index 00000000000..2a16e29729b --- /dev/null +++ b/contrib/python/PyHamcrest/py3/hamcrest/library/text/stringmatches.py @@ -0,0 +1,40 @@ +__author__ = "Chris Rose" +__copyright__ = "Copyright 2011 hamcrest.org" +__license__ = "BSD, see License.txt" + +import re + +import six + +from hamcrest.core.base_matcher import BaseMatcher +from hamcrest.core.helpers.hasmethod import hasmethod + +class StringMatchesPattern(BaseMatcher): + + def __init__(self, pattern): + self.pattern = pattern + + def describe_to(self, description): + description.append_text("a string matching '") \ + .append_text(self.pattern.pattern) \ + .append_text("'") + + def _matches(self, item): + return self.pattern.search(item) is not None + + +def matches_regexp(pattern): + """Matches if object is a string containing a match for a given regular + expression. + + :param pattern: The regular expression to search for. + + This matcher first checks whether the evaluated object is a string. If so, + it checks if the regular expression ``pattern`` matches anywhere within the + evaluated object. + + """ + if isinstance(pattern, six.string_types): + pattern = re.compile(pattern) + + return StringMatchesPattern(pattern) |