Compare commits

..

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
8df4f7eb7e
!21 synchronize branche openEuler-24.03-LTS Manually
From: @wang--ge 
Reviewed-by: @cherry530 
Signed-off-by: @cherry530
2024-11-13 03:28:12 +00:00
wang--ge
a046bb6074 sync branch openEuler-24.03-LTS 2024-11-13 10:17:24 +08:00
openeuler-ci-bot
0fedd6a1e6
!11 Fix build error for numpy-1.20
From: @wk333 
Reviewed-by: @caodongxia 
Signed-off-by: @caodongxia
2023-07-23 08:15:11 +00:00
wk333
22ed65ad3d Fix build error for numpy-1.20 2023-07-23 15:47:19 +08:00
openeuler-ci-bot
5059c1b16f
!9 Package upgrade
From: @starlet-dx 
Reviewed-by: @myeuler 
Signed-off-by: @myeuler
2022-06-29 07:42:26 +00:00
starlet-dx
e1a6a81853 Package upgrade 2022-06-29 14:55:20 +08:00
openeuler-ci-bot
2fb6108f94
!8 License compliance rectification
From: @houyingchao 
Reviewed-by: @shinwell_hu 
Signed-off-by: @shinwell_hu
2022-05-16 09:05:52 +00:00
houyingchao
1fb9162b3e License compliance rectification 2022-05-11 15:22:23 +08:00
openeuler-ci-bot
34d499b6b5 !5 port to pytest4
From: @maminjie
Reviewed-by: @small_leek
Signed-off-by: @small_leek
2021-01-11 20:35:22 +08:00
maminjie
344e1d120e port to pytest4 2021-01-11 19:01:52 +08:00
7 changed files with 177 additions and 140 deletions

View File

@ -1,134 +0,0 @@
From 37a4d0dbeb9a92b959edfb9b1aceba4eaacf9f78 Mon Sep 17 00:00:00 2001
From: Alex Panov <thealexpanov@gmail.com>
Date: Sun, 15 May 2016 23:36:18 -0400
Subject: [PATCH] Add boolean matchers
---
README.rst | 5 ++++
src/hamcrest/library/__init__.py | 3 ++
src/hamcrest/library/bool/__init__.py | 1 +
src/hamcrest/library/bool/bool_comparison.py | 22 ++++++++++++++
tests/hamcrest_unit_test/bool/__init__.py | 0
.../bool/bool_comparison_test.py | 34 ++++++++++++++++++++++
6 files changed, 65 insertions(+)
create mode 100644 src/hamcrest/library/bool/__init__.py
create mode 100644 src/hamcrest/library/bool/bool_comparison.py
create mode 100644 tests/hamcrest_unit_test/bool/__init__.py
create mode 100644 tests/hamcrest_unit_test/bool/bool_comparison_test.py
diff --git a/README.rst b/README.rst
index 8ef46bb..d2200f8 100644
--- a/README.rst
+++ b/README.rst
@@ -148,6 +148,11 @@ PyHamcrest comes with a library of useful matchers:
* ``greater_than``, ``greater_than_or_equal_to``, ``less_than``,
``less_than_or_equal_to`` - match numeric ordering
+* Boolean
+
+ * ``is_true`` - verify the value is True
+ * ``is_false`` - verify the value is False
+
* Text
* ``contains_string`` - match part of a string
diff --git a/src/hamcrest/library/__init__.py b/src/hamcrest/library/__init__.py
index a5a7963..55dfcda 100644
--- a/src/hamcrest/library/__init__.py
+++ b/src/hamcrest/library/__init__.py
@@ -7,6 +7,7 @@ from hamcrest.library.integration import *
from hamcrest.library.number import *
from hamcrest.library.object import *
from hamcrest.library.text import *
+from hamcrest.library.bool import *
__author__ = "Jon Reid"
__copyright__ = "Copyright 2011 hamcrest.org"
@@ -41,4 +42,6 @@ __all__ = [
'ends_with',
'starts_with',
'string_contains_in_order',
+ 'is_true',
+ 'is_false'
]
diff --git a/src/hamcrest/library/bool/__init__.py b/src/hamcrest/library/bool/__init__.py
new file mode 100644
index 0000000..7cf13a3
--- /dev/null
+++ b/src/hamcrest/library/bool/__init__.py
@@ -0,0 +1 @@
+from .bool_comparison import is_true, is_false
diff --git a/src/hamcrest/library/bool/bool_comparison.py b/src/hamcrest/library/bool/bool_comparison.py
new file mode 100644
index 0000000..af7e1b6
--- /dev/null
+++ b/src/hamcrest/library/bool/bool_comparison.py
@@ -0,0 +1,22 @@
+from hamcrest.core.base_matcher import BaseMatcher
+
+
+class IsABool(BaseMatcher):
+ def __init__(self, boolean_value):
+ self.boolean_value = boolean_value
+
+ def describe_to(self, description):
+ description.append_text(str(self.boolean_value))
+
+ def _matches(self, item):
+ if not isinstance(item, bool):
+ return False
+ return item == self.boolean_value
+
+
+def is_true():
+ return IsABool(True)
+
+
+def is_false():
+ return IsABool(False)
diff --git a/tests/hamcrest_unit_test/bool/__init__.py b/tests/hamcrest_unit_test/bool/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/hamcrest_unit_test/bool/bool_comparison_test.py b/tests/hamcrest_unit_test/bool/bool_comparison_test.py
new file mode 100644
index 0000000..e865365
--- /dev/null
+++ b/tests/hamcrest_unit_test/bool/bool_comparison_test.py
@@ -0,0 +1,34 @@
+from hamcrest import assert_that, equal_to
+from hamcrest.core.string_description import StringDescription
+from hamcrest.library.bool import is_false, is_true
+from hamcrest_unit_test.matcher_test import MatcherTest
+
+
+class BoolComparisonTest(MatcherTest):
+ def test_true_is_true(self):
+ self.assert_matches('Is True', is_true(), True)
+
+ def test_false_is_not_true(self):
+ self.assert_does_not_match('False', is_true(), False)
+
+ def test_false_is_false(self):
+ self.assert_matches('False', is_false(), False)
+
+ def test_true_is_not_false(self):
+ self.assert_does_not_match('True', is_false(), True)
+
+ def test_number_is_not_true(self):
+ self.assert_does_not_match('True', is_true(), 1)
+
+ def test_number_is_not_false(self):
+ self.assert_does_not_match('False', is_false(), 1)
+
+ def test_is_true_description(self):
+ description = StringDescription()
+ is_true().describe_to(description)
+ assert_that(str(description), equal_to('True'))
+
+ def test_is_false_description(self):
+ description = StringDescription()
+ is_false().describe_to(description)
+ assert_that(str(description), equal_to('False'))
--
2.9.3

View File

@ -0,0 +1,73 @@
From 78e99b0eb25d5bd81d8f183f50bc91bed2d1fcf5 Mon Sep 17 00:00:00 2001
From: Simon Brunning <simon@brunningonline.net>
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

View File

@ -0,0 +1,36 @@
From 41fac8c3bc727c0bdaa0d1b037783b759238c193 Mon Sep 17 00:00:00 2001
From: Chris Rose <offline@offby1.net>
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

View File

@ -0,0 +1,42 @@
From 8ccad121bccd576ecd212efb44109d697024fbf9 Mon Sep 17 00:00:00 2001
From: aekoroglu <ali.erdinc.koroglu@intel.com>
Date: Mon, 5 Sep 2022 16:42:51 +0300
Subject: [PATCH] deprecated numpy alias
Refer: https://github.com/hamcrest/PyHamcrest/pull/218
---
tests/hamcrest_unit_test/number/iscloseto_test.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/hamcrest_unit_test/number/iscloseto_test.py b/tests/hamcrest_unit_test/number/iscloseto_test.py
index f83964fd..b82109c5 100644
--- a/tests/hamcrest_unit_test/number/iscloseto_test.py
+++ b/tests/hamcrest_unit_test/number/iscloseto_test.py
@@ -64,7 +64,7 @@ def testMatcherSupportsDecimal(self):
class IsNumericTest(unittest.TestCase):
@unittest.skipUnless(NUMPY_AVAILABLE, "Skipped because it needs NumPy")
def test_numpy_numeric_type_int(self):
- self.assertTrue(isnumeric(np.int(1)), "Platform integer (normally either int32 or int64)")
+ self.assertTrue(isnumeric(np.int_(1)), "Platform integer (normally either int32 or int64)")
@unittest.skipUnless(NUMPY_AVAILABLE, "Skipped because it needs NumPy")
def test_numpy_numeric_type_int8(self):
@@ -102,7 +102,7 @@ def test_numpy_numeric_type_uint64(self):
@unittest.skipUnless(NUMPY_AVAILABLE, "Skipped because it needs NumPy")
def test_numpy_numeric_type_float(self):
- self.assertTrue(isnumeric(np.float(1)), "Shorthand for float64.")
+ self.assertTrue(isnumeric(np.float_(1)), "Shorthand for float64.")
@unittest.skipUnless(NUMPY_AVAILABLE, "Skipped because it needs NumPy")
def test_numpy_numeric_type_float16(self):
@@ -127,7 +127,7 @@ def test_numpy_numeric_type_float64(self):
@unittest.skipUnless(NUMPY_AVAILABLE, "Skipped because it needs NumPy")
def test_numpy_numeric_type_complex(self):
- self.assertTrue(isnumeric(np.complex(1)), "Shorthand for complex128.")
+ self.assertTrue(isnumeric(np.complex_(1)), "Shorthand for complex128.")
@unittest.skipUnless(NUMPY_AVAILABLE, "Skipped because it needs NumPy")
def test_numpy_numeric_type_complex64(self):

Binary file not shown.

Binary file not shown.

View File

@ -1,11 +1,13 @@
Name: python-hamcrest
Version: 1.9.0
Release: 9
Version: 2.0.3
Release: 4
Summary: Hamcrest matchers for Python
License: BSD
License: BSD-3-Clause
URL: https://github.com/hamcrest/PyHamcrest
Source0: https://github.com/hamcrest/PyHamcrest/archive/V1.9.0/%{name}-1.9.0.tar.gz
Patch0001: 0001-Add-boolean-matchers.patch
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
@ -19,6 +21,7 @@ commonly used.
Summary: Hamcrest matchers for Python
%{?python_provide:%python_provide python3-hamcrest}
BuildRequires: python3-devel python3-setuptools python3-pytest python3-mock python3-six
BuildRequires: python3-numpy
Requires: python3-six
%description -n python3-hamcrest
@ -39,7 +42,6 @@ Python 3 version.
%py3_install
%check
mv pytest.ini pytest.ini~
PYTHONPATH=%{buildroot}%{python3_sitelib} py.test-%{python3_version} -v
@ -47,6 +49,24 @@ PYTHONPATH=%{buildroot}%{python3_sitelib} py.test-%{python3_version} -v
%{python3_sitelib}/*
%changelog
* Fri May 10 2024 lilu <lilu@kylinos.cn> - 2.0.3-4
- Fix the error that ordered comparison matchers should fail for incomparable types
* Thu May 9 2024 wuzhaomin <wuzhaomin@kylinos.cn> - 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
* Wed Jun 29 2022 yaoxin <yaoxin30@h-partners.com> - 2.0.3-1
- Update to 2.0.3
* Wed May 11 2022 houyingchao <houyingchao@h-partners.com> - 1.9.0-11
- License compliance rectification
* Fri Jan 08 2021 maminjie <maminjie1@huawei.com> - 1.9.0-10
- port to pytest4
* Wed Aug 05 2020 lingsheng <lingsheng@huawei.com> - 1.9.0-9
- Remove python2-hamcrest subpackage