Compare commits
10 Commits
713a39c4c0
...
8df4f7eb7e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8df4f7eb7e | ||
|
|
a046bb6074 | ||
|
|
0fedd6a1e6 | ||
|
|
22ed65ad3d | ||
|
|
5059c1b16f | ||
|
|
e1a6a81853 | ||
|
|
2fb6108f94 | ||
|
|
1fb9162b3e | ||
|
|
34d499b6b5 | ||
|
|
344e1d120e |
@ -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
|
|
||||||
|
|
||||||
73
Ordered-comparison-matchers-should-fail-for-incompar.patch
Normal file
73
Ordered-comparison-matchers-should-fail-for-incompar.patch
Normal 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
|
||||||
|
|
||||||
@ -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
|
||||||
|
|
||||||
42
numpy-1.20.0-alias-depr.patch
Normal file
42
numpy-1.20.0-alias-depr.patch
Normal 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.
BIN
python-hamcrest-2.0.3.tar.gz
Normal file
BIN
python-hamcrest-2.0.3.tar.gz
Normal file
Binary file not shown.
@ -1,11 +1,13 @@
|
|||||||
Name: python-hamcrest
|
Name: python-hamcrest
|
||||||
Version: 1.9.0
|
Version: 2.0.3
|
||||||
Release: 9
|
Release: 4
|
||||||
Summary: Hamcrest matchers for Python
|
Summary: Hamcrest matchers for Python
|
||||||
License: BSD
|
License: BSD-3-Clause
|
||||||
URL: https://github.com/hamcrest/PyHamcrest
|
URL: https://github.com/hamcrest/PyHamcrest
|
||||||
Source0: https://github.com/hamcrest/PyHamcrest/archive/V1.9.0/%{name}-1.9.0.tar.gz
|
Source0: https://github.com/hamcrest/PyHamcrest/archive/V2.0.3/%{name}-%{version}.tar.gz
|
||||||
Patch0001: 0001-Add-boolean-matchers.patch
|
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
|
BuildArch: noarch
|
||||||
|
|
||||||
%description
|
%description
|
||||||
@ -19,6 +21,7 @@ commonly used.
|
|||||||
Summary: Hamcrest matchers for Python
|
Summary: Hamcrest matchers for Python
|
||||||
%{?python_provide:%python_provide python3-hamcrest}
|
%{?python_provide:%python_provide python3-hamcrest}
|
||||||
BuildRequires: python3-devel python3-setuptools python3-pytest python3-mock python3-six
|
BuildRequires: python3-devel python3-setuptools python3-pytest python3-mock python3-six
|
||||||
|
BuildRequires: python3-numpy
|
||||||
Requires: python3-six
|
Requires: python3-six
|
||||||
|
|
||||||
%description -n python3-hamcrest
|
%description -n python3-hamcrest
|
||||||
@ -39,7 +42,6 @@ Python 3 version.
|
|||||||
%py3_install
|
%py3_install
|
||||||
|
|
||||||
%check
|
%check
|
||||||
mv pytest.ini pytest.ini~
|
|
||||||
PYTHONPATH=%{buildroot}%{python3_sitelib} py.test-%{python3_version} -v
|
PYTHONPATH=%{buildroot}%{python3_sitelib} py.test-%{python3_version} -v
|
||||||
|
|
||||||
|
|
||||||
@ -47,6 +49,24 @@ PYTHONPATH=%{buildroot}%{python3_sitelib} py.test-%{python3_version} -v
|
|||||||
%{python3_sitelib}/*
|
%{python3_sitelib}/*
|
||||||
|
|
||||||
%changelog
|
%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
|
* Wed Aug 05 2020 lingsheng <lingsheng@huawei.com> - 1.9.0-9
|
||||||
- Remove python2-hamcrest subpackage
|
- Remove python2-hamcrest subpackage
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user