summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_decorators.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_decorators.py')
-rw-r--r--Lib/test/test_decorators.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_decorators.py b/Lib/test/test_decorators.py
index 2558247..1499004 100644
--- a/Lib/test/test_decorators.py
+++ b/Lib/test/test_decorators.py
@@ -266,8 +266,44 @@ class TestDecorators(unittest.TestCase):
self.assertEqual(bar(), 42)
self.assertEqual(actions, expected_actions)
+class TestClassDecorators(unittest.TestCase):
+
+ def test_simple(self):
+ def plain(x):
+ x.extra = 'Hello'
+ return x
+ @plain
+ class C(object): pass
+ self.assertEqual(C.extra, 'Hello')
+
+ def test_double(self):
+ def ten(x):
+ x.extra = 10
+ return x
+ def add_five(x):
+ x.extra += 5
+ return x
+
+ @add_five
+ @ten
+ class C(object): pass
+ self.assertEqual(C.extra, 15)
+
+ def test_order(self):
+ def applied_first(x):
+ x.extra = 'first'
+ return x
+ def applied_second(x):
+ x.extra = 'second'
+ return x
+ @applied_second
+ @applied_first
+ class C(object): pass
+ self.assertEqual(C.extra, 'second')
+
def test_main():
test_support.run_unittest(TestDecorators)
+ test_support.run_unittest(TestClassDecorators)
if __name__=="__main__":
test_main()