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/library | |
parent | 3f573d26f7b92eb46dfff503d68a5897c96386ce (diff) |
Intermediate changes
commit_hash:6b9536340f4f2533b62d862c22cbfeb121d4fa3f
Diffstat (limited to 'contrib/python/PyHamcrest/py3/hamcrest/library')
4 files changed, 39 insertions, 13 deletions
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) |