コード例 #1
0
from ut_utils import Method, ClassMethod, StaticMethod
from ut_utils import build_old_style_class
from ut_utils import build_new_style_class
from ut_utils import resets_forge_at_end
from forge import SignatureException

METHODS = [
    Method('method(self, a, b, c)'),
    ClassMethod('class_method(cls, a, b, c)'),
    StaticMethod('static_method(a, b, c)'),
    Method('without_self()'),
    Method('with_varargs_self(*args)'),
    Method('__len__(self)'),
    ]

MockedNewStyleClass = build_new_style_class(METHODS)
MockedOldStyleClass = build_old_style_class(METHODS)

def for_each_mock(func):
    @functools.wraps(func)
    def newfunc(self, *args, **kwargs):
        for obj in self.mocks:
            func(self, obj, *args, **kwargs)
    return newfunc

class MockInstanceMethodTest(ForgeTestCase):
    def setUp(self):
        super(MockInstanceMethodTest, self).setUp()
        self.newstyle_mock = self.forge.create_mock(MockedNewStyleClass)
        self.oldstyle_mock = self.forge.create_mock(MockedOldStyleClass)
        self.mocks = [self.newstyle_mock, self.oldstyle_mock]
コード例 #2
0
 def setUp(self):
     super(NewStyleSpecialMethodsAbsenceTest, self).setUp()
     self.obj = self.forge.create_mock(build_new_style_class())