

def test_preserve_attributes(self):

    @myattr_dec
    @myattr2_dec
    def func():
        pass
    self.assertEqual(getattr(func, 'myattr', False), True)
    self.assertEqual(getattr(func, 'myattr2', False), True)

    class TestPlain(object):

        @myattr_dec_m
        @myattr2_dec_m
        def method(self):
            'A method'
            pass

    @method_decorator(myattr_dec_m, 'method')
    class TestMethodAndClass(object):

        @method_decorator(myattr2_dec_m)
        def method(self):
            'A method'
            pass
    decorators = (myattr_dec_m, myattr2_dec_m)

    @method_decorator(decorators, 'method')
    class TestIterable(object):

        def method(self):
            'A method'
            pass
    for Test in (TestPlain, TestMethodAndClass, TestIterable):
        self.assertEqual(getattr(Test().method, 'myattr', False), True)
        self.assertEqual(getattr(Test().method, 'myattr2', False), True)
        self.assertEqual(getattr(Test.method, 'myattr', False), True)
        self.assertEqual(getattr(Test.method, 'myattr2', False), True)
        self.assertEqual(Test.method.__doc__, 'A method')
        self.assertEqual(Test.method.__name__, 'method')

dataset/ETHPy150Open django/django/tests/decorators/tests.py MethodDecoratorTests.test_preserve_attributes/original