Example #1
0
    def test_staticmethod(self):
        class WithStaticMethod:
            @staticmethod
            def staticfunc():
                pass

        self.assertTrue(_callable(WithStaticMethod.staticfunc))
Example #2
0
    def test_classmethod(self):
        class WithClassMethod:
            @classmethod
            def classfunc(cls):
                pass

        self.assertTrue(_callable(WithClassMethod.classfunc))
Example #3
0
    def test_call_magic_method(self):
        class Callable:
            def __call__(self):
                pass

        instance = Callable()
        self.assertTrue(_callable(instance))
Example #4
0
def _patch_mock_callable(obj):
    if isinstance(obj, type):
        return True
    if getattr(obj, '__call__', None) is not None:
        return True
    if (isinstance(obj, (staticmethod, classmethod))
            and mock._callable(obj.__func__)):
        return True
    return False
Example #5
0
 def _patched_callable(obj):
     "Monkey patched version of mock._callable."
     # See https://code.google.com/p/mock/issues/detail?id=241 and
     # http://bugs.python.org/issue23078 for the relevant bugs this
     # monkeypatch fixes
     if isinstance(obj, type):
         return True
     if getattr(obj, '__call__', None) is not None:
         return True
     if (isinstance(obj, (staticmethod, classmethod)) and
             mock._callable(obj.__func__)):  #pylint: disable=W0212
         return True
     return False
Example #6
0
    def test_non_callable_classmethod(self):
        class BadClassMethod:
            not_callable = classmethod(None)

        self.assertFalse(_callable(BadClassMethod.not_callable))
Example #7
0
    def test_non_callable_staticmethod(self):
        class BadStaticMethod:
            not_callable = staticmethod(None)

        self.assertFalse(_callable(BadStaticMethod.not_callable))
Example #8
0
 def test_type(self):
     for obj in [str, bytes, int, list, tuple, SomeClass]:
         self.assertTrue(_callable(obj))