Skip to content
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
32 changes: 32 additions & 0 deletions tests/matchers/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
EndsWith,
Equals,
GreaterThan,
GreaterThanOrEqual,
HasLength,
Is,
IsInstance,
LessThan,
LessThanOrEqual,
MatchesRegex,
Nearly,
NotEquals,
Expand Down Expand Up @@ -217,6 +219,36 @@ class TestGreaterThanInterface(TestCase, TestMatchersInterface):
]


class TestLessThanOrEqualInterface(TestCase, TestMatchersInterface):
matches_matcher: ClassVar[Matcher[Any]] = LessThanOrEqual(4)
matches_matches: ClassVar[list[Any]] = [-5, 3, 4]
matches_mismatches: ClassVar[list[Any]] = [5, 5000]

str_examples: ClassVar = [
("LessThanOrEqual(12)", LessThanOrEqual(12)),
]

describe_examples: ClassVar = [
("5 > 4", 5, LessThanOrEqual(4)),
("6 > 4", 6, LessThanOrEqual(4)),
]


class TestGreaterThanOrEqualInterface(TestCase, TestMatchersInterface):
matches_matcher: ClassVar[Matcher[Any]] = GreaterThanOrEqual(4)
matches_matches: ClassVar[list[Any]] = [4, 5, 8]
matches_mismatches: ClassVar[list[Any]] = [-2, 0, 3]

str_examples: ClassVar = [
("GreaterThanOrEqual(12)", GreaterThanOrEqual(12)),
]

describe_examples: ClassVar = [
("3 < 4", 3, GreaterThanOrEqual(4)),
("2 < 4", 2, GreaterThanOrEqual(4)),
]


class TestContainsInterface(TestCase, TestMatchersInterface):
matches_matcher: ClassVar[Matcher[Any]] = Contains("foo")
matches_matches: ClassVar[list[Any]] = ["foo", "afoo", "fooa"]
Expand Down
4 changes: 4 additions & 0 deletions testtools/matchers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
"FileContains",
"FileExists",
"GreaterThan",
"GreaterThanOrEqual",
"HasLength",
"HasPermissions",
"Is",
"IsDeprecated",
"IsInstance",
"KeysEqual",
"LessThan",
"LessThanOrEqual",
"MatchesAll",
"MatchesAny",
"MatchesDict",
Expand Down Expand Up @@ -67,10 +69,12 @@
EndsWith,
Equals,
GreaterThan,
GreaterThanOrEqual,
HasLength,
Is,
IsInstance,
LessThan,
LessThanOrEqual,
MatchesRegex,
Nearly,
NotEquals,
Expand Down
16 changes: 16 additions & 0 deletions testtools/matchers/_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
"EndsWith",
"Equals",
"GreaterThan",
"GreaterThanOrEqual",
"HasLength",
"Is",
"IsInstance",
"LessThan",
"LessThanOrEqual",
"MatchesRegex",
"Nearly",
"NotEquals",
Expand Down Expand Up @@ -200,6 +202,20 @@ class GreaterThan(_BinaryComparison[T]):
mismatch_string = "<="


class LessThanOrEqual(_BinaryComparison[T]):
"""Matches if the item is less than or equal to the matchers reference object."""

comparator = operator.le
mismatch_string = ">"


class GreaterThanOrEqual(_BinaryComparison[T]):
"""Matches if the item is greater than or equal to the matchers reference object."""

comparator = operator.ge
mismatch_string = "<"


class _NotNearlyEqual(Mismatch, Generic[T]):
"""Mismatch for Nearly matcher."""

Expand Down