diff options
| author | robot-piglet <[email protected]> | 2025-09-10 15:34:55 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2025-09-10 15:52:03 +0300 |
| commit | b0091b5ec4e788ed216c0a23786c921307b79b0a (patch) | |
| tree | 4da0bd43ceae17f84820956bcd3801cdb8c0ebb8 /contrib/python/PyHamcrest/py3/hamcrest | |
| parent | 3f573d26f7b92eb46dfff503d68a5897c96386ce (diff) | |
Intermediate changes
commit_hash:6b9536340f4f2533b62d862c22cbfeb121d4fa3f
Diffstat (limited to 'contrib/python/PyHamcrest/py3/hamcrest')
13 files changed, 91 insertions, 32 deletions
diff --git a/contrib/python/PyHamcrest/py3/hamcrest/__init__.py b/contrib/python/PyHamcrest/py3/hamcrest/__init__.py index 3a751d44f62..f45b032075d 100644 --- a/contrib/python/PyHamcrest/py3/hamcrest/__init__.py +++ b/contrib/python/PyHamcrest/py3/hamcrest/__init__.py @@ -2,7 +2,7 @@ from __future__ import absolute_import from hamcrest.core import * from hamcrest.library import * -__version__ = "1.9.0" +__version__ = "1.10.1" __author__ = "Chris Rose" -__copyright__ = "Copyright 2015 hamcrest.org" +__copyright__ = "Copyright 2020 hamcrest.org" __license__ = "BSD, see License.txt" diff --git a/contrib/python/PyHamcrest/py3/hamcrest/core/assert_that.py b/contrib/python/PyHamcrest/py3/hamcrest/core/assert_that.py index b38bc243ca0..8c36ceab764 100644 --- a/contrib/python/PyHamcrest/py3/hamcrest/core/assert_that.py +++ b/contrib/python/PyHamcrest/py3/hamcrest/core/assert_that.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +import warnings from hamcrest.core.matcher import Matcher from hamcrest.core.string_description import StringDescription @@ -42,6 +43,8 @@ def assert_that(arg1, arg2=None, arg3=''): if isinstance(arg2, Matcher): _assert_match(actual=arg1, matcher=arg2, reason=arg3) else: + if isinstance(arg1, Matcher): + warnings.warn("arg1 should be boolean, but was {}".format(type(arg1))) _assert_bool(assertion=arg1, reason=arg2) diff --git a/contrib/python/PyHamcrest/py3/hamcrest/core/base_description.py b/contrib/python/PyHamcrest/py3/hamcrest/core/base_description.py index 8c7c51364de..18b3ee9ee53 100644 --- a/contrib/python/PyHamcrest/py3/hamcrest/core/base_description.py +++ b/contrib/python/PyHamcrest/py3/hamcrest/core/base_description.py @@ -9,6 +9,7 @@ import six from hamcrest.core.description import Description from hamcrest.core.selfdescribingvalue import SelfDescribingValue from hamcrest.core.helpers.hasmethod import hasmethod +from hamcrest.core.helpers.ismock import ismock class BaseDescription(Description): """Base class for all :py:class:`~hamcrest.core.description.Description` @@ -21,7 +22,7 @@ class BaseDescription(Description): return self def append_description_of(self, value): - if hasmethod(value, 'describe_to'): + if not ismock(value) and hasmethod(value, 'describe_to'): value.describe_to(self) elif six.PY3 and isinstance(value, six.text_type): self.append(repr(value)) diff --git a/contrib/python/PyHamcrest/py3/hamcrest/core/core/allof.py b/contrib/python/PyHamcrest/py3/hamcrest/core/core/allof.py index 35c5d0bfeb6..e051f6abb30 100644 --- a/contrib/python/PyHamcrest/py3/hamcrest/core/core/allof.py +++ b/contrib/python/PyHamcrest/py3/hamcrest/core/core/allof.py @@ -8,18 +8,26 @@ __license__ = "BSD, see License.txt" class AllOf(BaseMatcher): - def __init__(self, *matchers): + def __init__(self, *matchers, **kwargs): self.matchers = matchers + self.describe_matcher_in_mismatch = kwargs.pop('describe_matcher_in_mismatch', True) # No keyword-only args in 2.7 :-( + self.describe_all_mismatches = kwargs.pop('describe_all_mismatches', False) def matches(self, item, mismatch_description=None): - for matcher in self.matchers: + found_mismatch = False + for i, matcher in enumerate(self.matchers): if not matcher.matches(item): if mismatch_description: - mismatch_description.append_description_of(matcher) \ - .append_text(' ') + if self.describe_matcher_in_mismatch: + mismatch_description.append_description_of(matcher) \ + .append_text(' ') matcher.describe_mismatch(item, mismatch_description) - return False - return True + found_mismatch = True + if not self.describe_all_mismatches: + break + elif i < len(self.matchers) - 1 and mismatch_description: + mismatch_description.append_text(' and ') + return not found_mismatch def describe_mismatch(self, item, mismatch_description): self.matches(item, mismatch_description) diff --git a/contrib/python/PyHamcrest/py3/hamcrest/core/core/raises.py b/contrib/python/PyHamcrest/py3/hamcrest/core/core/raises.py index 16614cc1b77..699a1ccc91d 100644 --- a/contrib/python/PyHamcrest/py3/hamcrest/core/core/raises.py +++ b/contrib/python/PyHamcrest/py3/hamcrest/core/core/raises.py @@ -2,6 +2,7 @@ from weakref import ref import re import sys from hamcrest.core.base_matcher import BaseMatcher +from hamcrest.core.helpers.wrap_matcher import wrap_matcher from hamcrest.core.compat import is_callable __author__ = "Per Fagrell" @@ -29,7 +30,7 @@ class Raises(BaseMatcher): self.actual = None try: self.actual_return_value = function() - except Exception: + except BaseException: self.actual = sys.exc_info()[1] if isinstance(self.actual, self.expected): @@ -69,7 +70,7 @@ class Raises(BaseMatcher): description.append_text("\nAdditional exception matcher: ") self.matcher.describe_mismatch(self.actual, description) else: - description.append_text('%s was raised instead' % type(self.actual)) + description.append_text('%r of type %s was raised instead' % (self.actual, type(self.actual))) def raises(exception, pattern=None, matcher=None): @@ -98,7 +99,7 @@ class DeferredCallable(object): self.kwargs = {} def __call__(self): - return self.func(*self.args, **self.kwargs) + self.func(*self.args, **self.kwargs) def with_args(self, *args, **kwargs): self.args = args diff --git a/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/ismock.py b/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/ismock.py new file mode 100644 index 00000000000..318e0d4f9cb --- /dev/null +++ b/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/ismock.py @@ -0,0 +1,15 @@ +MOCKTYPES = () +try: + from mock import Mock + MOCKTYPES += (Mock,) +except ImportError: + pass +try: + from unittest.mock import Mock + MOCKTYPES += (Mock,) +except ImportError: + pass + + +def ismock(obj): + return isinstance(obj, MOCKTYPES) diff --git a/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/wrap_matcher.py b/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/wrap_matcher.py index a5b506fb395..587ae4c6101 100644 --- a/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/wrap_matcher.py +++ b/contrib/python/PyHamcrest/py3/hamcrest/core/helpers/wrap_matcher.py @@ -28,9 +28,7 @@ def is_matchable_type(expected_type): 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)): + if isinstance(expected_type, tuple) and all(map(is_matchable_type, expected_type)): return True return False diff --git a/contrib/python/PyHamcrest/py3/hamcrest/core/selfdescribingvalue.py b/contrib/python/PyHamcrest/py3/hamcrest/core/selfdescribingvalue.py index dfa4e3a20e4..7f471e04f2d 100644 --- a/contrib/python/PyHamcrest/py3/hamcrest/core/selfdescribingvalue.py +++ b/contrib/python/PyHamcrest/py3/hamcrest/core/selfdescribingvalue.py @@ -24,4 +24,4 @@ class SelfDescribingValue(SelfDescribing): def describe_to(self, description): """Generates a description of the value.""" - description.append_value(self.value) + description.append_description_of(self.value) diff --git a/contrib/python/PyHamcrest/py3/hamcrest/core/string_description.py b/contrib/python/PyHamcrest/py3/hamcrest/core/string_description.py index 7626bf91e8e..172dfb4ff22 100644 --- a/contrib/python/PyHamcrest/py3/hamcrest/core/string_description.py +++ b/contrib/python/PyHamcrest/py3/hamcrest/core/string_description.py @@ -24,14 +24,21 @@ def tostring(selfdescribing): class StringDescription(BaseDescription): """A :py:class:`~hamcrest.core.description.Description` that is stored as a string. + """ def __init__(self): - self.__out_list = [] + self.out = '' def __str__(self): """Returns the description.""" - return ''.join(self.__out_list) + return self.out def append(self, string): - self.__out_list.append(six.text_type(string)) + if six.PY3: + self.out += str(string) + else: + if isinstance(string, unicode): + self.out += string + else: + self.out += unicode(string, errors="ignore") diff --git a/contrib/python/PyHamcrest/py3/hamcrest/library/__init__.py b/contrib/python/PyHamcrest/py3/hamcrest/library/__init__.py index a5a7963521f..d5f909c9216 100644 --- a/contrib/python/PyHamcrest/py3/hamcrest/library/__init__.py +++ b/contrib/python/PyHamcrest/py3/hamcrest/library/__init__.py @@ -23,6 +23,7 @@ __all__ = [ 'has_items', 'contains_inanyorder', 'contains', + 'contains_exactly', 'only_contains', 'match_equality', 'matches_regexp', diff --git a/contrib/python/PyHamcrest/py3/hamcrest/library/collection/__init__.py b/contrib/python/PyHamcrest/py3/hamcrest/library/collection/__init__.py index 2f899877883..f910e973259 100644 --- a/contrib/python/PyHamcrest/py3/hamcrest/library/collection/__init__.py +++ b/contrib/python/PyHamcrest/py3/hamcrest/library/collection/__init__.py @@ -7,7 +7,7 @@ from .isdict_containingvalue import has_value from .isin import is_in from .issequence_containing import has_item, has_items from .issequence_containinginanyorder import contains_inanyorder -from .issequence_containinginorder import contains +from .issequence_containinginorder import contains, contains_exactly from .issequence_onlycontaining import only_contains from .is_empty import empty diff --git a/contrib/python/PyHamcrest/py3/hamcrest/library/collection/issequence_containinginorder.py b/contrib/python/PyHamcrest/py3/hamcrest/library/collection/issequence_containinginorder.py index 3fd91a6c925..7c37b328b61 100644 --- a/contrib/python/PyHamcrest/py3/hamcrest/library/collection/issequence_containinginorder.py +++ b/contrib/python/PyHamcrest/py3/hamcrest/library/collection/issequence_containinginorder.py @@ -1,3 +1,5 @@ +import warnings + __author__ = "Jon Reid" __copyright__ = "Copyright 2011 hamcrest.org" __license__ = "BSD, see License.txt" @@ -69,7 +71,7 @@ class IsSequenceContainingInOrder(BaseMatcher): .append_list('[', ', ', ']', self.matchers) -def contains(*items): +def contains_exactly(*items): """Matches if sequence's elements satisfy a given list of matchers, in order. :param match1,...: A comma-separated list of matchers. @@ -86,3 +88,9 @@ def contains(*items): for item in items: matchers.append(wrap_matcher(item)) return IsSequenceContainingInOrder(matchers) + + +def contains(*items): + """Deprecated - use contains_exactly(*items)""" + warnings.warn("deprecated - use contains_exactly(*items)", DeprecationWarning) + return contains_exactly(*items) diff --git a/contrib/python/PyHamcrest/py3/hamcrest/library/object/hasproperty.py b/contrib/python/PyHamcrest/py3/hamcrest/library/object/hasproperty.py index d2536d69f40..18f591f1ed6 100644 --- a/contrib/python/PyHamcrest/py3/hamcrest/library/object/hasproperty.py +++ b/contrib/python/PyHamcrest/py3/hamcrest/library/object/hasproperty.py @@ -1,9 +1,9 @@ -from hamcrest.core.base_matcher import BaseMatcher +from hamcrest import described_as from hamcrest.core import anything -from hamcrest.core.core.allof import all_of -from hamcrest.core.string_description import StringDescription -from hamcrest.core.helpers.hasmethod import hasmethod +from hamcrest.core.base_matcher import BaseMatcher +from hamcrest.core.core.allof import AllOf from hamcrest.core.helpers.wrap_matcher import wrap_matcher as wrap_shortcut +from hamcrest.core.string_description import StringDescription __author__ = "Chris Rose" __copyright__ = "Copyright 2011 hamcrest.org" @@ -38,13 +38,15 @@ class IsObjectWithProperty(BaseMatcher): return if not hasattr(item, self.property_name): - mismatch_description.append_value(item) \ - .append_text(' did not have the ') \ - .append_value(self.property_name) \ - .append_text(' property') + mismatch_description.append_description_of(item) \ + .append_text(' did not have the ') \ + .append_description_of(self.property_name) \ + .append_text(' property') return - mismatch_description.append_text('property ').append_value(self.property_name).append_text(' ') + mismatch_description.append_text('property ') \ + .append_description_of(self.property_name) \ + .append_text(' ') value = getattr(item, self.property_name) self.value_matcher.describe_mismatch(value, mismatch_description) @@ -150,5 +152,20 @@ def has_properties(*keys_valuematchers, **kv_args): for key, value in kv_args.items(): base_dict[key] = wrap_shortcut(value) - return all_of(*[has_property(property_name, property_value_matcher) for \ - property_name, property_value_matcher in base_dict.items()]) + if len(base_dict) > 1: + description = StringDescription().append_text('an object with properties ') + for i, (property_name, property_value_matcher) in enumerate(sorted(base_dict.items())): + description.append_value(property_name).append_text(' matching ').append_description_of( + property_value_matcher) + if i < len(base_dict) - 1: + description.append_text(' and ') + + return described_as(str(description), + AllOf(*[has_property(property_name, property_value_matcher) + for property_name, property_value_matcher + in sorted(base_dict.items())], + describe_all_mismatches=True, + describe_matcher_in_mismatch=False)) + else: + property_name, property_value_matcher = base_dict.popitem() + return has_property(property_name, property_value_matcher) |
