testtools-dev team mailing list archive
-
testtools-dev team
-
Mailing list archive
-
Message #00679
[Merge] lp:~kampka/testtools/greater-than-matcher into lp:testtools
Christian Kampka has proposed merging lp:~kampka/testtools/greater-than-matcher into lp:testtools.
Requested reviews:
Jonathan Lange (jml)
For more details, see:
https://code.launchpad.net/~kampka/testtools/greater-than-matcher/+merge/64864
testtools has a LessThan matcher, but the opposite, a GreaterThan matcher, is not yet included but just as useful.
--
https://code.launchpad.net/~kampka/testtools/greater-than-matcher/+merge/64864
Your team testtools developers is subscribed to branch lp:testtools.
=== modified file 'testtools/matchers.py'
--- testtools/matchers.py 2011-04-20 23:45:52 +0000
+++ testtools/matchers.py 2011-06-16 16:41:23 +0000
@@ -19,6 +19,7 @@
'Is',
'KeysEqual',
'LessThan',
+ 'GreaterThan',
'MatchesAll',
'MatchesAny',
'MatchesException',
@@ -292,6 +293,11 @@
comparator = operator.__lt__
mismatch_string = 'is not >'
+class GreaterThan(_BinaryComparison):
+ """Matches if the item is greater than the matchers reference object."""
+
+ comparator = operator.__gt__
+ mismatch_string = 'is not <'
class MatchesAny(object):
"""Matches if any of the matchers it is created with match."""
=== modified file 'testtools/tests/test_matchers.py'
--- testtools/tests/test_matchers.py 2011-04-20 23:45:52 +0000
+++ testtools/tests/test_matchers.py 2011-06-16 16:41:23 +0000
@@ -25,6 +25,7 @@
KeysEqual,
Is,
LessThan,
+ GreaterThan,
MatchesAny,
MatchesAll,
MatchesException,
@@ -175,6 +176,20 @@
('4 is not > 4', 4, LessThan(4)),
]
+class TestGreaterThanInterface(TestCase, TestMatchersInterface):
+
+ matches_matcher = GreaterThan(4)
+ matches_matches = [5, 8]
+ matches_mismatches = [-2, 0, 4]
+
+ str_examples = [
+ ("GreaterThan(12)", GreaterThan(12)),
+ ]
+
+ describe_examples = [
+ ('5 is not < 4', 4, GreaterThan(5)),
+ ('4 is not < 4', 4, GreaterThan(4)),
+ ]
def make_error(type, *args, **kwargs):
try:
Follow ups