summaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
authorGustavo Niemeyer <gustavo@niemeyer.net>2007-11-22 20:01:27 -0200
committerGustavo Niemeyer <gustavo@niemeyer.net>2007-11-22 20:01:27 -0200
commit35d2aaafce5afc718e96cc78656201488c390725 (patch)
tree6848868ad0d36ad9b640afa361f362f24e1bb52a /test.py
parent16f6a2b6573857c91d7f232c5fc3c26a1479e45b (diff)
downloadmocker-35d2aaafce5afc718e96cc78656201488c390725.tar.gz
In recording mode, mock.__class__ will now return Mock, and not
record the action. This allows Mocker to be used in interactive environments which inspect the result's type, such as in iPython (reported by Alex Dante).
Diffstat (limited to 'test.py')
-rwxr-xr-xtest.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/test.py b/test.py
index dd499f7..ce984b1 100755
--- a/test.py
+++ b/test.py
@@ -2042,6 +2042,11 @@ class MockTest(unittest.TestCase):
def setUp(self):
self.paths = []
class StubMocker(object):
+ _recording = True
+ def is_recording(self):
+ return self._recording
+ def replay(self):
+ self._recording = False
@staticmethod
def act(path):
self.paths.append(path)
@@ -2079,13 +2084,24 @@ class MockTest(unittest.TestCase):
C = object()
self.assertEquals(Mock(self.mocker, spec=C).__mocker_spec__, C)
- def test_type(self):
- def raise_exception(self, path):
- raise MatchError
- self.StubMocker.act = raise_exception
+ def test_class_without_type(self):
+ mock = Mock(self.mocker)
+ self.assertEquals(mock.__class__, Mock)
+ self.mocker.replay()
+ self.assertEquals(mock.__class__, Mock)
+
+ def test_class_with_type_when_recording(self):
class C(object): pass
mock = Mock(self.mocker, type=C)
self.assertEquals(mock.__mocker_type__, C)
+ self.assertEquals(mock.__class__, Mock)
+ self.assertEquals(isinstance(mock, Mock), True)
+
+ def test_class_with_type_when_replaying(self):
+ class C(object): pass
+ mock = Mock(self.mocker, type=C)
+ self.mocker.replay()
+ self.assertEquals(mock.__mocker_type__, C)
self.assertEquals(mock.__class__, C)
self.assertEquals(isinstance(mock, C), True)