[commit-gajim] r11199 - trunk/test/lib
asterix at gajim.org
asterix at gajim.org
Mon Apr 6 15:07:12 CEST 2009
Author: asterix
Date: 2009-04-06 15:07:12 +0200 (Mon, 06 Apr 2009)
New Revision: 11199
Modified:
trunk/test/lib/mock.py
Log:
fix Mock class: child of object class and fix realClass usage
Modified: trunk/test/lib/mock.py
===================================================================
--- trunk/test/lib/mock.py 2009-04-06 13:05:03 UTC (rev 11198)
+++ trunk/test/lib/mock.py 2009-04-06 13:07:12 UTC (rev 11199)
@@ -11,6 +11,7 @@
#
#
# Copyright (c) 2005, Dave Kirby
+# Copyright (c) 2009, Yann Leboulanger
#
# All rights reserved.
#
@@ -60,7 +61,7 @@
class MockInterfaceError(Exception):
pass
-class Mock:
+class Mock(object):
"""
The Mock class emulates any other class for testing purposes.
All method calls are stored for later examination.
@@ -83,6 +84,7 @@
self.mockAllCalledMethods = []
self.mockReturnValues = returnValues or {}
self.mockExpectations = {}
+ self.realClass = realClass
self.realClassMethods = None
if realClass:
self.realClassMethods = dict(inspect.getmembers(realClass, inspect.isroutine))
@@ -92,7 +94,7 @@
self._setupSubclassMethodInterceptors()
def _setupSubclassMethodInterceptors(self):
- methods = inspect.getmembers(self.__class__,inspect.isroutine)
+ methods = inspect.getmembers(self.realClass,inspect.isroutine)
baseMethods = dict(inspect.getmembers(Mock, inspect.ismethod))
for m in methods:
name = m[0]
@@ -119,7 +121,7 @@
if self.realClassMethods is None:
return
if name not in self.realClassMethods:
- raise MockInterfaceError("Calling mock method '%s' that was not found in the original class" % name)
+ return
func = self.realClassMethods[name]
try:
@@ -268,7 +270,7 @@
def makeCall(self, params, kwparams):
if self.handcrafted:
allPosParams = (self.mock,) + params
- func = _findFunc(self.mock.__class__, self.name)
+ func = _findFunc(self.mock.realClass, self.name)
if not func:
raise NotImplementedError
return func(*allPosParams, **kwparams)
@@ -463,4 +465,4 @@
-# vim: se ts=3:
\ No newline at end of file
+# vim: se ts=3:
More information about the Commits
mailing list