diff options
author | Brett Cannon <bcannon@gmail.com> | 2004-08-19 03:48:24 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2004-08-19 03:48:24 (GMT) |
commit | caa9798410887317226c4bf89f38d318b8436612 (patch) | |
tree | f240fbf4f49dc5db1807554fd5c897ca3f92af2e /Lib | |
parent | c6f3c8b612c8265fcf9c1dc9d8c8ca4c6316a37a (diff) | |
download | cpython-caa9798410887317226c4bf89f38d318b8436612.zip cpython-caa9798410887317226c4bf89f38d318b8436612.tar.gz cpython-caa9798410887317226c4bf89f38d318b8436612.tar.bz2 |
Rewrite test_order so as to be more "proper". Originally relied on an
error based on decorating with staticmethod too soon for the code to execute.
This meant that if the test didn't pass it just errored out. Now if the test
doesn't pass it leads to a failure instead.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_decorators.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/test/test_decorators.py b/Lib/test/test_decorators.py index c4eb8be..56aa5e1 100644 --- a/Lib/test/test_decorators.py +++ b/Lib/test/test_decorators.py @@ -191,13 +191,19 @@ class TestDecorators(unittest.TestCase): self.assertEqual(C.foo.booh, 42) def test_order(self): - class C(object): - @staticmethod - @funcattrs(abc=1) - def foo(): return 42 - # This wouldn't work if staticmethod was called first - self.assertEqual(C.foo(), 42) - self.assertEqual(C().foo(), 42) + # Test that decorators are applied in the proper order to the function + # they are decorating. + def callnum(num): + """Decorator factory that returns a decorator that replaces the + passed-in function with one that returns the value of 'num'""" + def deco(func): + return lambda: num + return deco + @callnum(2) + @callnum(1) + def foo(): return 42 + self.assertEqual(foo(), 2, + "Application order of decorators is incorrect") def test_eval_order(self): # Evaluating a decorated function involves four steps for each |