testtools-dev team mailing list archive
-
testtools-dev team
-
Mailing list archive
-
Message #00031
[Merge] lp:~lifeless/testtools/lessthan into lp:testtools
Robert Collins has proposed merging lp:~lifeless/testtools/lessthan into lp:testtools.
Requested reviews:
testtools developers (testtools-dev)
Add a LessThan matcher. \o/
--
https://code.launchpad.net/~lifeless/testtools/lessthan/+merge/31815
Your team testtools developers is requested to review the proposed merge of lp:~lifeless/testtools/lessthan into lp:testtools.
=== modified file 'NEWS'
--- NEWS 2010-08-04 13:07:42 +0000
+++ NEWS 2010-08-05 06:24:50 +0000
@@ -16,6 +16,9 @@
* New 'Is' matcher, which lets you assert that a thing is identical to
another thing.
+ * New 'LessThan' matcher which lets you assert that a thing is less than
+ another thing.
+
* TestCase now has a 'patch()' method to make it easier to monkey-patching
objects in tests. See the manual for more information. Fixes bug #310770.
=== modified file 'testtools/matchers.py'
--- testtools/matchers.py 2010-08-03 17:03:59 +0000
+++ testtools/matchers.py 2010-08-05 06:24:50 +0000
@@ -16,6 +16,7 @@
'DocTestMatches',
'Equals',
'Is',
+ 'LessThan',
'MatchesAll',
'MatchesAny',
'NotEquals',
@@ -143,7 +144,7 @@
return "%s(%r)" % (self.__class__.__name__, self.expected)
def match(self, other):
- if self.comparator(self.expected, other):
+ if self.comparator(other, self.expected):
return None
return _BinaryMismatch(self.expected, self.mismatch_string, other)
@@ -188,6 +189,13 @@
mismatch_string = 'is not'
+class LessThan(_BinaryComparison):
+ """Matches if the item is less than the matchers reference object."""
+
+ comparator = operator.__lt__
+ mismatch_string = 'is >='
+
+
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 2010-08-03 17:03:59 +0000
+++ testtools/tests/test_matchers.py 2010-08-05 06:24:50 +0000
@@ -13,6 +13,7 @@
Equals,
DocTestMatches,
Is,
+ LessThan,
MatchesAny,
MatchesAll,
Not,
@@ -124,6 +125,19 @@
describe_examples = [("1 is not 2", 2, Is(1))]
+class TestLessThanInterface(TestCase, TestMatchersInterface):
+
+ matches_matcher = LessThan(4)
+ matches_matches = [-5, 3]
+ matches_mismatches = [4, 5, 5000]
+
+ str_examples = [
+ ("LessThan(12)", LessThan(12)),
+ ]
+
+ describe_examples = [('4 is >= 4', 4, LessThan(4))]
+
+
class TestNotInterface(TestCase, TestMatchersInterface):
matches_matcher = Not(Equals(1))
Follow ups