def test_staticmethod(self): class Foo(object): @staticmethod def foo(): pass with self.assertRaises(TypeError): __unit__.ensure_method(Foo.foo)
def test_classmethod__of_instance(self): class Foo(object): @classmethod def foo(cls): pass __unit__.ensure_method(Foo().foo)
def test_regular_method_attached_to_class__of_instance(self): class Foo(object): pass def foo(self): pass Foo.foo = foo __unit__.ensure_method(Foo().foo)
def __call__(self, method): try: ensure_method(method) except TypeError: if not _OverrideDecorator.maybe_signal_classmethod(method): raise return _OverriddenMethod(method, self) # remember the override's base
def _get_member_name(member): if is_string(member): return member # Python has no "field declaration" objects, so the only valid # class or instance member is actually a method from taipan.objective.methods import ensure_method ensure_method(member) return member.__name__
def test_function_attached_to_object(self): class Foo(object): pass def foo(self): pass obj = Foo() obj.foo = foo __unit__.ensure_method(obj.foo)
def test_classmethod_attached_to_class(self): class Foo(object): pass @classmethod def foo(cls): pass Foo.foo = foo __unit__.ensure_method(Foo.foo)
def test_none(self): with self.assertRaises(TypeError): __unit__.ensure_method(None)
def test_regular_method__of_instance(self): class Foo(object): def foo(self): pass __unit__.ensure_method(Foo().foo)
def test_lambda(self): foo = lambda: None with self.assertRaises(TypeError): __unit__.ensure_method(foo)
def test_regular_function(self): def foo(): pass with self.assertRaises(TypeError): __unit__.ensure_method(foo)
def test_some_object(self): with self.assertRaises(TypeError): __unit__.ensure_method(object())