diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-11-12 21:38:37 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-11-12 21:38:37 +0000 |
commit | d0abd82c67c1a4e1046d82380cf0f5f3fd546c42 (patch) | |
tree | 1f7386ba67b99e061cf2122ebafc554d05d087ef | |
parent | 611272a89c0965aa0a311399f1edf9ead7c5d285 (diff) | |
parent | 9642f1901805519b5eb512a2b55d9eb8a7251dc3 (diff) | |
download | pecan-d0abd82c67c1a4e1046d82380cf0f5f3fd546c42.tar.gz |
Merge "Fixes expose of staticmethod"
-rw-r--r-- | pecan/tests/test_util.py | 27 | ||||
-rw-r--r-- | pecan/util.py | 6 |
2 files changed, 33 insertions, 0 deletions
diff --git a/pecan/tests/test_util.py b/pecan/tests/test_util.py index c1cdfbd..00e81f5 100644 --- a/pecan/tests/test_util.py +++ b/pecan/tests/test_util.py @@ -17,6 +17,11 @@ class TestArgSpec(unittest.TestCase): def index(self, a, b, c=1, *args, **kwargs): return 'Hello, World!' + @staticmethod + @expose() + def static_index(a, b, c=1, *args, **kwargs): + return 'Hello, World!' + return RootController() def test_no_decorator(self): @@ -24,6 +29,10 @@ class TestArgSpec(unittest.TestCase): actual = util.getargspec(self.controller.index.__func__) assert expected == actual + expected = inspect.getargspec(self.controller.static_index) + actual = util.getargspec(self.controller.static_index) + assert expected == actual + def test_simple_decorator(self): def dec(f): return f @@ -32,6 +41,10 @@ class TestArgSpec(unittest.TestCase): actual = util.getargspec(dec(self.controller.index.__func__)) assert expected == actual + expected = inspect.getargspec(self.controller.static_index) + actual = util.getargspec(dec(self.controller.static_index)) + assert expected == actual + def test_simple_wrapper(self): def dec(f): @functools.wraps(f) @@ -43,6 +56,10 @@ class TestArgSpec(unittest.TestCase): actual = util.getargspec(dec(self.controller.index.__func__)) assert expected == actual + expected = inspect.getargspec(self.controller.static_index) + actual = util.getargspec(dec(self.controller.static_index)) + assert expected == actual + def test_multiple_decorators(self): def dec(f): @functools.wraps(f) @@ -54,6 +71,11 @@ class TestArgSpec(unittest.TestCase): actual = util.getargspec(dec(dec(dec(self.controller.index.__func__)))) assert expected == actual + expected = inspect.getargspec(self.controller.static_index) + actual = util.getargspec(dec(dec(dec( + self.controller.static_index)))) + assert expected == actual + def test_decorator_with_args(self): def dec(flag): def inner(f): @@ -66,3 +88,8 @@ class TestArgSpec(unittest.TestCase): expected = inspect.getargspec(self.controller.index.__func__) actual = util.getargspec(dec(True)(self.controller.index.__func__)) assert expected == actual + + expected = inspect.getargspec(self.controller.static_index) + actual = util.getargspec(dec(True)( + self.controller.static_index)) + assert expected == actual diff --git a/pecan/util.py b/pecan/util.py index 168ff66..bdb5d2b 100644 --- a/pecan/util.py +++ b/pecan/util.py @@ -23,6 +23,12 @@ def getargspec(method): func_closure = six.get_function_closure(method) + # NOTE(sileht): if the closure is None we cannot look deeper, + # so return actual argspec, this occurs when the method + # is static for example. + if func_closure is None: + return argspec + closure = next( ( c for c in func_closure if six.callable(c.cell_contents) |