def testMethodFunc(self): #{{{
     '''Functions and methods are not wrapped'''
     def _(): #{{{
         pass
     # End def #}}}
     for o in (_, self.setUp):
         self.assertFalse(needs_wrapping(o))
示例#2
0
    def __init__(self, obj, callback=None, **kwargs): #{{{
        self.__name__ = getattr(obj, '__name__', 'UnnamedCallable')
        isw = needs_wrapping(obj)
        obj = callableobj(obj)
        if not obj:
            raise TypeError('Argument must be a valid callable object')
        elif callback is not None and not iscallable(callback):
            raise TypeError('callback argument must be a callable object')

        self._object = None
        self._function = None
        self._newcall = self.call
        self._numargs, self._maxargs = num_static_args(obj)
        isweak = bool(kwargs.get('weak', True))
        if isw:
            isweak = False

        mtype = methodtype(obj)
        self._methodtype = mtype
        if mtype not in (METHODTYPE_NOTMETHOD, METHODTYPE_UNBOUND):
            o = obj.im_class
            if mtype == METHODTYPE_INSTANCE:
                o = obj.im_self
            self._object = cref(o, callback, weak=isweak)
            self._function = obj.im_func
        else:
            self._function = cref(obj, callback, weak=isweak)
        self._funcid = cid(obj)
 def testCallableObjects(self): #{{{
     '''Objects with a __call__ method are not wrapped'''
     class _(object): #{{{
         def __call__(self): #{{{
             pass
         # End def #}}}
     # End class #}}}
     self.assertFalse(needs_wrapping(_()))
 def testNeedsWrapping(self): #{{{
     '''Any other object needs wrapping'''
     self.assertTrue(needs_wrapping(isinstance))
 def testClass(self): #{{{
     '''Classes are callable objects too'''
     class _(object): #{{{
         pass
     # End class #}}}
     self.assertFalse(needs_wrapping(_))
 def testNonCallable(self): #{{{
     '''Non-callable is not a wrapped object'''
     self.assertFalse(needs_wrapping(1))