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/object/hasstring.py | |
parent | 38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff) |
add ydb deps
Diffstat (limited to 'contrib/python/PyHamcrest/py3/hamcrest/library/object/hasstring.py')
-rw-r--r-- | contrib/python/PyHamcrest/py3/hamcrest/library/object/hasstring.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/contrib/python/PyHamcrest/py3/hamcrest/library/object/hasstring.py b/contrib/python/PyHamcrest/py3/hamcrest/library/object/hasstring.py new file mode 100644 index 00000000000..8b50547e21c --- /dev/null +++ b/contrib/python/PyHamcrest/py3/hamcrest/library/object/hasstring.py @@ -0,0 +1,40 @@ +from hamcrest.core.base_matcher import BaseMatcher +from hamcrest.core.helpers.wrap_matcher import wrap_matcher + +__author__ = "Jon Reid" +__copyright__ = "Copyright 2011 hamcrest.org" +__license__ = "BSD, see License.txt" + + +class HasString(BaseMatcher): + + def __init__(self, str_matcher): + self.str_matcher = str_matcher + + def _matches(self, item): + return self.str_matcher.matches(str(item)) + + def describe_to(self, description): + description.append_text('an object with str ') \ + .append_description_of(self.str_matcher) + + +def has_string(match): + """Matches if ``str(item)`` satisfies a given matcher. + + :param match: The matcher to satisfy, or an expected value for + :py:func:`~hamcrest.core.core.isequal.equal_to` matching. + + This matcher invokes the :py:func:`str` function on the evaluated object to + get its length, passing the result to a given matcher for evaluation. If + the ``match`` argument is not a matcher, it is implicitly wrapped in an + :py:func:`~hamcrest.core.core.isequal.equal_to` matcher to check for + equality. + + Examples:: + + has_string(starts_with('foo')) + has_string('bar') + + """ + return HasString(wrap_matcher(match)) |