summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmiddlek <smiddlek@b1010a0a-674b-0410-b734-77272b80c875>2010-07-10 18:29:52 +0000
committersmiddlek <smiddlek@b1010a0a-674b-0410-b734-77272b80c875>2010-07-10 18:29:52 +0000
commit4821b508508bc99a47eb2826bd1eacd94f1274ed (patch)
tree85e36943aa5e63e17f22ea4505f1c1e5c1d0f193
parent0351c33996da073395f5af405f3cb36d800839ac (diff)
downloadmox-4821b508508bc99a47eb2826bd1eacd94f1274ed.tar.gz
Fix for issue 21:
+ Add str() before assuming that types are strings in comparator __repr__ functions. + Add some doc and formatting to the Is() comparator. + Add some tests that In() works properly when the key is a tuple. git-svn-id: http://pymox.googlecode.com/svn/trunk@54 b1010a0a-674b-0410-b734-77272b80c875
-rwxr-xr-xmox.py9
-rwxr-xr-xmox_test.py20
2 files changed, 27 insertions, 2 deletions
diff --git a/mox.py b/mox.py
index c8ef6a6..14ea121 100755
--- a/mox.py
+++ b/mox.py
@@ -1238,10 +1238,14 @@ class Comparator:
return not self.equals(rhs)
class Is(Comparator):
+ """Comparison class used to check identity, instead of equality."""
+
def __init__(self, obj):
self._obj = obj
+
def equals(self, rhs):
return rhs is self._obj
+
def __repr__(self):
return "<is %r (%s)>" % (self._obj, id(self._obj))
@@ -1423,7 +1427,7 @@ class In(Comparator):
return self._key in rhs
def __repr__(self):
- return '<sequence or map containing \'%s\'>' % self._key
+ return '<sequence or map containing \'%s\'>' % str(self._key)
class Not(Comparator):
@@ -1491,7 +1495,8 @@ class ContainsKeyValue(Comparator):
return False
def __repr__(self):
- return '<map containing the entry \'%s: %s\'>' % (self._key, self._value)
+ return '<map containing the entry \'%s: %s\'>' % (str(self._key),
+ str(self._value))
class ContainsAttributeValue(Comparator):
diff --git a/mox_test.py b/mox_test.py
index 2166107..611f8fb 100755
--- a/mox_test.py
+++ b/mox_test.py
@@ -185,6 +185,19 @@ class InTest(unittest.TestCase):
"""Should return True if the item is a key in a dict."""
self.assert_(mox.In("test") == {"test" : "module"})
+ def testItemInTuple(self):
+ """Should return True if the item is in the list."""
+ self.assert_(mox.In(1) == (1, 2, 3))
+
+ def testTupleInTupleOfTuples(self):
+ self.assert_(mox.In((1, 2, 3)) == ((1, 2, 3), (1, 2)))
+
+ def testItemNotInList(self):
+ self.failIf(mox.In(1) == [2, 3])
+
+ def testTupleNotInTupleOfTuples(self):
+ self.failIf(mox.In((1, 2)) == ((1, 2, 3), (4, 5)))
+
class NotTest(unittest.TestCase):
"""Test Not correctly identifies False predicates."""
@@ -561,6 +574,13 @@ class MockAnythingTest(unittest.TestCase):
self.assertRaises(mox.UnexpectedMethodCallError,
self.mock_object.OtherValidCall)
+# def testReplayWithUnexpectedCell_BadSignatureWithTuple(self):
+# self.mock_object.ValidCall(mox.In((1, 2, 3)))
+# self.mock_object._Replay()
+# self.assertRaises(mox.UnexpectedMethodCallError,
+# self.mock_object.ValidCall, 4)
+
+
def testVerifyWithCompleteReplay(self):
"""Verify should not raise an exception for a valid replay."""
self.mock_object.ValidCall() # setup method call