From a046bb6074766ea585c9fdfd8adc3916b5c10cbb Mon Sep 17 00:00:00 2001 From: wang--ge Date: Wed, 13 Nov 2024 10:17:24 +0800 Subject: [PATCH] sync branch openEuler-24.03-LTS --- ...on-matchers-should-fail-for-incompar.patch | 73 +++++++++++++++++++ ...type-annotation-bug-in-isdict_contai.patch | 36 +++++++++ python-hamcrest.spec | 10 ++- 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 Ordered-comparison-matchers-should-fail-for-incompar.patch create mode 100644 backport-nit-fix-a-minor-type-annotation-bug-in-isdict_contai.patch diff --git a/Ordered-comparison-matchers-should-fail-for-incompar.patch b/Ordered-comparison-matchers-should-fail-for-incompar.patch new file mode 100644 index 0000000..eb290da --- /dev/null +++ b/Ordered-comparison-matchers-should-fail-for-incompar.patch @@ -0,0 +1,73 @@ +From 78e99b0eb25d5bd81d8f183f50bc91bed2d1fcf5 Mon Sep 17 00:00:00 2001 +From: Simon Brunning +Date: Thu, 3 Mar 2022 13:31:21 +0000 +Subject: [PATCH] Ordered comparison matchers should fail for incomparable + types. Fix for #185 + +--- + src/hamcrest/library/number/ordering_comparison.py | 5 ++++- + .../issequence_containinginanyorder_test.py | 11 +++++++++++ + .../number/ordering_comparison_test.py | 3 +++ + 3 files changed, 18 insertions(+), 1 deletion(-) + +diff --git a/src/hamcrest/library/number/ordering_comparison.py b/src/hamcrest/library/number/ordering_comparison.py +index 6c6275d..f121caf 100644 +--- a/src/hamcrest/library/number/ordering_comparison.py ++++ b/src/hamcrest/library/number/ordering_comparison.py +@@ -22,7 +22,10 @@ class OrderingComparison(BaseMatcher[Any]): + self.comparison_description = comparison_description + + def _matches(self, item: Any) -> bool: +- return self.comparison_function(item, self.value) ++ try: ++ return self.comparison_function(item, self.value) ++ except TypeError: ++ return False + + def describe_to(self, description: Description) -> None: + description.append_text("a value ").append_text(self.comparison_description).append_text( +diff --git a/tests/hamcrest_unit_test/collection/issequence_containinginanyorder_test.py b/tests/hamcrest_unit_test/collection/issequence_containinginanyorder_test.py +index 5c21fbb..b36d192 100644 +--- a/tests/hamcrest_unit_test/collection/issequence_containinginanyorder_test.py ++++ b/tests/hamcrest_unit_test/collection/issequence_containinginanyorder_test.py +@@ -1,5 +1,6 @@ + import unittest + ++from hamcrest import greater_than + from hamcrest.core.core.isequal import equal_to + from hamcrest.library.collection.issequence_containinginanyorder import contains_inanyorder + from hamcrest_unit_test.matcher_test import MatcherTest +@@ -84,6 +85,16 @@ class IsSequenceContainingInAnyOrderBase(object): + "no item matches: <2> in [<3>, <1>]", matcher, self._sequence(3, 1) + ) + ++ def testIncomparableTypes(self): ++ self.assert_matches("Incomparable types", contains_inanyorder(*[4, "a"]), ["a", 4]) ++ ++ def testIncomparableTypesInNestedMatcher(self): ++ self.assert_matches( ++ "Incomparable types in nested matcher", ++ contains_inanyorder(*[greater_than(0), "a"]), ++ ["a", 4], ++ ) ++ + + class IsConcreteSequenceContainingInAnyOrderTest( + MatcherTest, IsSequenceContainingInAnyOrderBase, SequenceForm +diff --git a/tests/hamcrest_unit_test/number/ordering_comparison_test.py b/tests/hamcrest_unit_test/number/ordering_comparison_test.py +index 76143df..d944519 100644 +--- a/tests/hamcrest_unit_test/number/ordering_comparison_test.py ++++ b/tests/hamcrest_unit_test/number/ordering_comparison_test.py +@@ -67,6 +67,9 @@ class OrderingComparisonTest(MatcherTest): + self.assert_describe_mismatch("was <0>", greater_than_or_equal_to(1), 0) + self.assert_describe_mismatch("was <2>", less_than_or_equal_to(1), 2) + ++ def testIncomparableTypes(self): ++ self.assert_does_not_match("incomparable types", greater_than(1), "a") ++ + + if __name__ == "__main__": + unittest.main() +-- +2.27.0 + diff --git a/backport-nit-fix-a-minor-type-annotation-bug-in-isdict_contai.patch b/backport-nit-fix-a-minor-type-annotation-bug-in-isdict_contai.patch new file mode 100644 index 0000000..6f10fe7 --- /dev/null +++ b/backport-nit-fix-a-minor-type-annotation-bug-in-isdict_contai.patch @@ -0,0 +1,36 @@ +From 41fac8c3bc727c0bdaa0d1b037783b759238c193 Mon Sep 17 00:00:00 2001 +From: Chris Rose +Date: Sat, 13 Aug 2022 07:51:31 -0500 +Subject: [PATCH] nit: fix a minor type annotation bug in + isdict_containingentries + +Fixes #182 +--- + changelog.d/182.bugfix.rst | 1 + + src/hamcrest/library/collection/isdict_containingentries.py | 2 +- + 2 files changed, 2 insertions(+), 1 deletion(-) + create mode 100644 changelog.d/182.bugfix.rst + +diff --git a/changelog.d/182.bugfix.rst b/changelog.d/182.bugfix.rst +new file mode 100644 +index 0000000..1b09d8c +--- /dev/null ++++ b/changelog.d/182.bugfix.rst +@@ -0,0 +1 @@ ++Use the correct generic type in the internal ``describe_keyvalue`` method +diff --git a/src/hamcrest/library/collection/isdict_containingentries.py b/src/hamcrest/library/collection/isdict_containingentries.py +index 490affa..8c17c20 100644 +--- a/src/hamcrest/library/collection/isdict_containingentries.py ++++ b/src/hamcrest/library/collection/isdict_containingentries.py +@@ -57,7 +57,7 @@ class IsDictContainingEntries(BaseMatcher[Mapping[K, V]]): + def describe_mismatch(self, item: Mapping[K, V], mismatch_description: Description) -> None: + self.matches(item, mismatch_description) + +- def describe_keyvalue(self, index: int, value: V, description: Description) -> None: ++ def describe_keyvalue(self, index: K, value: V, description: Description) -> None: + """Describes key-value pair at given index.""" + description.append_description_of(index).append_text(": ").append_description_of(value) + +-- +2.9.3.windows.1 + diff --git a/python-hamcrest.spec b/python-hamcrest.spec index 97f4fd1..2ef73c1 100644 --- a/python-hamcrest.spec +++ b/python-hamcrest.spec @@ -1,11 +1,13 @@ Name: python-hamcrest Version: 2.0.3 -Release: 2 +Release: 4 Summary: Hamcrest matchers for Python License: BSD-3-Clause URL: https://github.com/hamcrest/PyHamcrest Source0: https://github.com/hamcrest/PyHamcrest/archive/V2.0.3/%{name}-%{version}.tar.gz Patch0: numpy-1.20.0-alias-depr.patch +Patch1: backport-nit-fix-a-minor-type-annotation-bug-in-isdict_contai.patch +Patch2: Ordered-comparison-matchers-should-fail-for-incompar.patch BuildArch: noarch %description @@ -47,6 +49,12 @@ PYTHONPATH=%{buildroot}%{python3_sitelib} py.test-%{python3_version} -v %{python3_sitelib}/* %changelog +* Fri May 10 2024 lilu - 2.0.3-4 +- Fix the error that ordered comparison matchers should fail for incomparable types + +* Thu May 9 2024 wuzhaomin - 2.0.3-3 +- fix a minor type annotation bug in isdict_containingentries + * Sun Jul 23 2023 wangkai <13474090681@163.com> - 2.0.3-2 - Fix build error for numpy-1.20 -- Gitee