Merge "Fixes expose of staticmethod"

This commit is contained in:
Jenkins
2014-11-12 21:38:37 +00:00
committed by Gerrit Code Review
2 changed files with 33 additions and 0 deletions

View File

@@ -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

View File

@@ -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)