summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmiddlek <smiddlek@b1010a0a-674b-0410-b734-77272b80c875>2010-08-19 17:29:46 +0000
committersmiddlek <smiddlek@b1010a0a-674b-0410-b734-77272b80c875>2010-08-19 17:29:46 +0000
commit9751c637d6a58fe38a85668993f7c0079181fd0e (patch)
tree3e5426f781de4b173fc149c6d28aad74ced645df
parentabe12ce857c5978226b3d0549dceea2ab797df8a (diff)
downloadmox-9751c637d6a58fe38a85668993f7c0079181fd0e.tar.gz
MockObject should have the __name__ param by default.
When stubbing with MockAnything, force the __name__ param git-svn-id: http://pymox.googlecode.com/svn/trunk@57 b1010a0a-674b-0410-b734-77272b80c875
-rwxr-xr-xmox.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/mox.py b/mox.py
index d6be02a..d2711fe 100755
--- a/mox.py
+++ b/mox.py
@@ -316,6 +316,7 @@ class Mox(object):
stub = self.CreateMock(attr_to_replace)
else:
stub = self.CreateMockAnything(description='Stub for %s' % attr_to_replace)
+ stub.__name__ = attr_name
self.stubs.Set(obj, attr_name, stub)
@@ -543,14 +544,12 @@ class MockObject(MockAnything, object):
self._known_vars = set()
self._class_to_mock = class_to_mock
try:
- self._description = class_to_mock.__name__
- # If class_to_mock is a mock itself, then we'll get an UnknownMethodCall
- # error here from the underlying call to __getattr__('__name__')
- except (UnknownMethodCallError, AttributeError):
- try:
+ if inspect.isclass(self._class_to_mock):
+ self._description = class_to_mock.__name__
+ else:
self._description = type(class_to_mock).__name__
- except AttributeError:
- pass
+ except Exception:
+ pass
for method in dir(class_to_mock):
attr = getattr(class_to_mock, method)
@@ -770,6 +769,11 @@ class MockObject(MockAnything, object):
return self._class_to_mock
+ @property
+ def __name__(self):
+ """Return the name that is being mocked."""
+ return self._description
+
class _MockObjectFactory(MockObject):
"""A MockObjectFactory creates mocks and verifies __init__ params.