From 681f8c2a8b67603690f60733931732569bc85e8b Mon Sep 17 00:00:00 2001 From: Tamar Oren <66771972+tamar-ot@users.noreply.github.com> Date: Fri, 23 Dec 2022 06:43:34 +0200 Subject: [PATCH 1/5] Create great_than_matcher.py adding matcher that check great_than --- src/expycted/matchers/great_than_matcher.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/expycted/matchers/great_than_matcher.py diff --git a/src/expycted/matchers/great_than_matcher.py b/src/expycted/matchers/great_than_matcher.py new file mode 100644 index 0000000..a50a399 --- /dev/null +++ b/src/expycted/matchers/great_than_matcher.py @@ -0,0 +1,15 @@ +from __future__ import annotations + +from typing import Any + +from expycted.core.matchers import BaseMatcher + + +class GreatThanMatcher(BaseMatcher): + """Asserts the actual value is great than the expected value.""" + + def _matches(self, *, expected: Any) -> bool: + if self._expectation.qualifiers.or_equal: + return self._expectation.actual >= expected + + return self._expectation.actual > expected From c08f67a7fa0493da1f3cc36a230b1ff8965ff988 Mon Sep 17 00:00:00 2001 From: Tamar Oren <66771972+tamar-ot@users.noreply.github.com> Date: Fri, 23 Dec 2022 06:49:47 +0200 Subject: [PATCH 2/5] Update __init__.py --- src/expycted/matchers/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/expycted/matchers/__init__.py b/src/expycted/matchers/__init__.py index 2fb9951..bd70d30 100644 --- a/src/expycted/matchers/__init__.py +++ b/src/expycted/matchers/__init__.py @@ -7,4 +7,5 @@ from .is_matcher import IsMatcher from .is_true_matcher import IsTrueMatcher from .less_than_matcher import LessThanMatcher +from .great_than_matcher import GreatThanMatcher from .type_matcher import TypeMatcher From 4b0e168d14a5517ed14bd48080b61897e9e5543e Mon Sep 17 00:00:00 2001 From: Tamar Oren <66771972+tamar-ot@users.noreply.github.com> Date: Fri, 23 Dec 2022 07:03:35 +0200 Subject: [PATCH 3/5] Update value.py --- src/expycted/internals/value.py | 76 +++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/src/expycted/internals/value.py b/src/expycted/internals/value.py index ec370be..1f303ad 100644 --- a/src/expycted/internals/value.py +++ b/src/expycted/internals/value.py @@ -12,6 +12,7 @@ IsFalseMatcher, IsTrueMatcher, LessThanMatcher, + GreatThanMatcher, TypeMatcher, ) @@ -219,16 +220,61 @@ def inherit(self, actual: type) -> None: bool: Result """ - @assertion_old - def be_greater_than(self, actual: Any) -> None: - """Check whether the value is greater than something + @property + @assertion + def be_greater_than(self) -> GreatThanMatcher: + """Asserts that the actual value is greater than the expected value.""" - Args: - actual (Any): Value to compare to + return GreatThanMatcher - Returns: - bool: Result - """ + @property + @assertion + def be_greater_than_or_equal_to(self) -> GreatThanMatcher: + """Asserts that the actual value is greater than or equal to the expected value.""" + + return GreatThanMatcher(self, or_equal=True) + + @property + def be_great_than(self) -> GreatThanMatcher: + """Alias for ``be_greater_than``.""" + + return self.be_greater_than + + @property + def be_great(self) -> GreatThanMatcher: + """Alias for ``be_greater_than``.""" + + return self.be_greater_than + + @property + def be_greater(self) -> GreatThanMatcher: + """Alias for ``be_greater_than``.""" + + return self.be_greater_than + + @property + def be_greater_or_equal_to(self) -> GreatThanMatcher: + """Alias for ``be_greater_than_or_equal_to``.""" + + return self.be_greater_than_or_equal_to + + @property + def be_great_than_or_equal_to(self) -> GreatThanMatcher: + """Alias for ``be_greater_than_or_equal_to``.""" + + return self.be_greater_than_or_equal_to + + @property + def be_great_or_equal(self) -> GreatThanMatcher: + """Alias for ``be_greater_than_or_equal_to``.""" + + return self.be_greater_than_or_equal_to + + @property + def be_greater_or_equal(self) -> GreatThanMatcher: + """Alias for ``be_greater_than_or_equal_to``.""" + + return self.be_greater_than_or_equal_to @property @assertion @@ -286,17 +332,6 @@ def be_lesser_or_equal(self) -> LessThanMatcher: return self.be_lesser_than_or_equal_to - @assertion_old - def be_greater_or_equal_to(self, actual: Any) -> None: - """Check whether the value is greater than or equal to something - - Args: - actual (Any): Value to compare to - - Returns: - bool: Result - """ - @assertion_old def be_numeric(self) -> None: """Check whether the value is numeric @@ -309,9 +344,6 @@ def be_numeric(self) -> None: be_a_number = be_numeric - be_greater_or_equal = be_greater_than_or_equal_to = be_greater_or_equal_to - be_greater = be_greater_than - be_in = be_included_in = be_contained_in have = include = contain From 379fdd514d5203811c6823531d75b0782ed48a3d Mon Sep 17 00:00:00 2001 From: tamar-ot Date: Mon, 26 Dec 2022 21:25:57 +0200 Subject: [PATCH 4/5] adding tests to great than matcher --- test/unit/matchers/test_great_than_matcher.py | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 test/unit/matchers/test_great_than_matcher.py diff --git a/test/unit/matchers/test_great_than_matcher.py b/test/unit/matchers/test_great_than_matcher.py new file mode 100644 index 0000000..76dd865 --- /dev/null +++ b/test/unit/matchers/test_great_than_matcher.py @@ -0,0 +1,80 @@ +from __future__ import annotations + +from expycted import expect +from expycted.matchers import GreatThanMatcher + +from helpers import stubs +from helpers.utils import parametrize_expectation + + +def test_via_expect(context): + expectation = expect(2) + + assert isinstance(expectation.to.be_great, GreatThanMatcher) + assert isinstance(expectation.to.be_great_than, GreatThanMatcher) + assert isinstance(expectation.to.be_greater, GreatThanMatcher) + assert isinstance(expectation.to.be_greater_than, GreatThanMatcher) + + assert isinstance(expectation.to.be_great_or_equal, GreatThanMatcher) + assert isinstance(expectation.to.be_great_than_or_equal_to, GreatThanMatcher) + assert isinstance(expectation.to.be_greater_or_equal_to, GreatThanMatcher) + assert isinstance(expectation.to.be_greater_than_or_equal_to, GreatThanMatcher) + + expectation.to.be_great_than(1) + expectation.to.be_great_than_or_equal_to(2) + + with context.raises: + expectation.to.be_great_than(2) + + +@parametrize_expectation( + [ + ("hello world", "hello"), + (3, 2), + (3.2, 3), + ([2], [1]), + ([1, 0], [1]), + ], + matcher=GreatThanMatcher, + wrap=False, +) +def test_matches(expectation): + matcher = expectation.matcher() + + assert matcher(expectation.expected) is True + + +@parametrize_expectation( + [ + ("hello world", "hello"), + ("hello", "hello"), + (3, 2), + (2, 2), + (3.2, 3), + ([2], [1]), + ([1], [1]), + ], + matcher=GreatThanMatcher, + wrap=False, +) +def test_or_equal_matches(expectation): + matcher = expectation.matcher(or_equal=True) + + assert matcher(expectation.expected) is True + + +@parametrize_expectation( + [ + ("hello", "hello world"), + (2, 3), + (3, 3.2), + ([1], [2]), + ([1], [1, 0]), + ], + matcher=GreatThanMatcher, + wrap=False, +) +def test_not_matches(expectation): + matcher = expectation.matcher() + + assert matcher(expectation.expected) is False From c2057578690718376b14805ac723cfb04e1977f3 Mon Sep 17 00:00:00 2001 From: tamar-ot Date: Tue, 27 Dec 2022 19:52:01 +0200 Subject: [PATCH 5/5] remove old great than tests --- test/expect_to_test_suite.py | 28 ---------------------------- test/helpers/stubs.py | 14 -------------- 2 files changed, 42 deletions(-) diff --git a/test/expect_to_test_suite.py b/test/expect_to_test_suite.py index d5a4d87..288b9c5 100644 --- a/test/expect_to_test_suite.py +++ b/test/expect_to_test_suite.py @@ -80,34 +80,6 @@ def test_to_inherit_type_error(expected, actual, context): expect(expected).to.inherit(actual) -@expected_actual_params(stubs.GREATER_THAN, extract_ids=False) -def test_to_be_greater_than(expected, actual, context): - expect(expected).to.be_greater_than(actual) - expect(expected).to.be_greater(actual) - - with context.raises: - expect(expected).to_not.be_greater_than(actual) - - with context.raises: - expect(expected).to_not.be_greater(actual) - - -@expected_actual_params(stubs.GREATER_THAN_OR_EQUAL, extract_ids=False) -def test_to_be_greater_than_or_equal_to(expected, actual, context): - expect(expected).to.be_greater_than_or_equal_to(actual) - expect(expected).to.be_greater_than_or_equal_to(actual) - expect(expected).to.be_greater_or_equal(actual) - - with context.raises: - expect(expected).to_not.be_greater_than_or_equal_to(actual) - - with context.raises: - expect(expected).to_not.be_greater_than_or_equal_to(actual) - - with context.raises: - expect(expected).to_not.be_greater_or_equal(actual) - - @expected_params(stubs.NUMERIC, extract_ids=False) def test_to_be_numeric(expected, context): expect(expected).to.be_numeric() diff --git a/test/helpers/stubs.py b/test/helpers/stubs.py index 4257c07..bc26c95 100644 --- a/test/helpers/stubs.py +++ b/test/helpers/stubs.py @@ -165,20 +165,6 @@ class Day(Enum): INHERIT_TYPE_ERROR = (("string", "str"),) -GREATER_THAN = ( - (3, 2), - (3.2, 3), - ([2], [1]), - ([1, 0], [1]), -) - - -GREATER_THAN_OR_EQUAL = ( - *GREATER_THAN, - (1, 1.0), - ([1], [1]), -) - NUMERIC = ( 1, "1",