summaryrefslogtreecommitdiff
path: root/tests/decorators
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2018-04-16 10:38:37 -0700
committerTim Graham <timograham@gmail.com>2018-04-16 13:38:37 -0400
commitfdc936c9130cf4fb5d59869674b9a31cc79a7999 (patch)
tree39768f286ca892e77aca59749341e43397760ebf /tests/decorators
parenta480ef89adaf2302c52c5d95fe8a1b691624edc0 (diff)
downloaddjango-fdc936c9130cf4fb5d59869674b9a31cc79a7999.tar.gz
Fixed #29253 -- Made method_decorator(list) copy attributes.
Diffstat (limited to 'tests/decorators')
-rw-r--r--tests/decorators/tests.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py
index 5a7fa88044..e8f6b8d2d5 100644
--- a/tests/decorators/tests.py
+++ b/tests/decorators/tests.py
@@ -168,7 +168,7 @@ def myattr_dec(func):
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
wrapper.myattr = True
- return wraps(func)(wrapper)
+ return wrapper
myattr_dec_m = method_decorator(myattr_dec)
@@ -178,7 +178,7 @@ def myattr2_dec(func):
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
wrapper.myattr2 = True
- return wraps(func)(wrapper)
+ return wrapper
myattr2_dec_m = method_decorator(myattr2_dec)
@@ -210,12 +210,22 @@ class MethodDecoratorTests(SimpleTestCase):
def test_preserve_attributes(self):
# Sanity check myattr_dec and myattr2_dec
@myattr_dec
+ def func():
+ pass
+ self.assertIs(getattr(func, 'myattr', False), True)
+
+ @myattr2_dec
+ def func():
+ pass
+ self.assertIs(getattr(func, 'myattr2', False), True)
+
+ @myattr_dec
@myattr2_dec
def func():
pass
self.assertIs(getattr(func, 'myattr', False), True)
- self.assertIs(getattr(func, 'myattr2', False), True)
+ self.assertIs(getattr(func, 'myattr2', False), False)
# Decorate using method_decorator() on the method.
class TestPlain:
@@ -235,16 +245,23 @@ class MethodDecoratorTests(SimpleTestCase):
"A method"
pass
- # Decorate using an iterable of decorators.
+ # Decorate using an iterable of function decorators.
+ @method_decorator((myattr_dec, myattr2_dec), 'method')
+ class TestFunctionIterable:
+ def method(self):
+ "A method"
+ pass
+
+ # Decorate using an iterable of method decorators.
decorators = (myattr_dec_m, myattr2_dec_m)
@method_decorator(decorators, "method")
- class TestIterable:
+ class TestMethodIterable:
def method(self):
"A method"
pass
- tests = (TestPlain, TestMethodAndClass, TestIterable)
+ tests = (TestPlain, TestMethodAndClass, TestFunctionIterable, TestMethodIterable)
for Test in tests:
with self.subTest(Test=Test):
self.assertIs(getattr(Test().method, 'myattr', False), True)