Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚚 Migrating greater than matcher #72

Merged
merged 5 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 54 additions & 22 deletions src/expycted/internals/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
IsFalseMatcher,
IsTrueMatcher,
LessThanMatcher,
GreatThanMatcher,
TypeMatcher,
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/expycted/matchers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions src/expycted/matchers/great_than_matcher.py
Original file line number Diff line number Diff line change
@@ -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
28 changes: 0 additions & 28 deletions test/expect_to_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 0 additions & 14 deletions test/helpers/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
80 changes: 80 additions & 0 deletions test/unit/matchers/test_great_than_matcher.py
Original file line number Diff line number Diff line change
@@ -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