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/core/helpers | |
parent | 38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff) |
add ydb deps
Diffstat (limited to 'contrib/python/PyHamcrest/py3/hamcrest/core/helpers')
3 files changed, 53 insertions, 0 deletions
diff --git a/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/__init__.py b/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/__init__.py new file mode 100644 index 00000000000..61cb82d43b5 --- /dev/null +++ b/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/__init__.py @@ -0,0 +1,5 @@ +"""Utilities for writing Matchers.""" + +__author__ = "Jon Reid" +__copyright__ = "Copyright 2011 hamcrest.org" +__license__ = "BSD, see License.txt" diff --git a/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/hasmethod.py b/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/hasmethod.py new file mode 100644 index 00000000000..a1f3bfb1549 --- /dev/null +++ b/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/hasmethod.py @@ -0,0 +1,12 @@ +__author__ = "Jon Reid" +__copyright__ = "Copyright 2011 hamcrest.org" +__license__ = "BSD, see License.txt" + + +def hasmethod(obj, methodname): + """Does ``obj`` have a method named ``methodname``?""" + + if not hasattr(obj, methodname): + return False + method = getattr(obj, methodname) + return callable(method) diff --git a/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/wrap_matcher.py b/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/wrap_matcher.py new file mode 100644 index 00000000000..a5b506fb395 --- /dev/null +++ b/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/wrap_matcher.py @@ -0,0 +1,36 @@ +import six + +from hamcrest.core.base_matcher import Matcher +from hamcrest.core.core.isequal import equal_to + +__author__ = "Jon Reid" +__copyright__ = "Copyright 2011 hamcrest.org" +__license__ = "BSD, see License.txt" + +import types + +def wrap_matcher(x): + """Wraps argument in a matcher, if necessary. + + :returns: the argument as-is if it is already a matcher, otherwise wrapped + in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher. + + """ + if isinstance(x, Matcher): + return x + else: + return equal_to(x) + +def is_matchable_type(expected_type): + if isinstance(expected_type, type): + return True + + if isinstance(expected_type, six.class_types): + return True + + if isinstance(expected_type, tuple) and \ + expected_type and \ + all(map(is_matchable_type, expected_type)): + return True + + return False |