mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #6291 from tk0miya/test_util_inspect2
Add testcases for sphinx.util.inspect
This commit is contained in:
@@ -399,3 +399,62 @@ def test_isstaticmethod():
|
||||
assert inspect.isstaticmethod(Foo.method2, Foo, 'method2') is False
|
||||
assert inspect.isstaticmethod(Bar.method1, Bar, 'method1') is True
|
||||
assert inspect.isstaticmethod(Bar.method2, Bar, 'method2') is False
|
||||
|
||||
|
||||
def test_isfunction():
|
||||
def func(x, y, z):
|
||||
pass
|
||||
|
||||
func2 = functools.partial(func, 1)
|
||||
|
||||
class Foo:
|
||||
def meth(self):
|
||||
pass
|
||||
|
||||
print2 = functools.partial(print, 1)
|
||||
|
||||
assert inspect.isfunction(func) is True # function
|
||||
assert inspect.isfunction(func2) is True # partial-ed function
|
||||
assert inspect.isfunction(Foo.meth) is True # method of class
|
||||
assert inspect.isfunction(Foo().meth) is False # method of instance
|
||||
assert inspect.isfunction(print) is False # builtin function
|
||||
assert inspect.isfunction(print2) is False # partial-ed builtin function
|
||||
|
||||
|
||||
def test_isbuiltin():
|
||||
def func(x, y, z):
|
||||
pass
|
||||
|
||||
func2 = functools.partial(func, 1)
|
||||
|
||||
class Foo:
|
||||
def meth(self):
|
||||
pass
|
||||
|
||||
print2 = functools.partial(print, 1)
|
||||
|
||||
assert inspect.isbuiltin(print) is True # builtin function
|
||||
assert inspect.isbuiltin(print2) is True # partial-ed builtin function
|
||||
assert inspect.isbuiltin(func) is False # function
|
||||
assert inspect.isbuiltin(func2) is False # partial-ed function
|
||||
assert inspect.isbuiltin(Foo.meth) is False # method of class
|
||||
assert inspect.isbuiltin(Foo().meth) is False # method of instance
|
||||
|
||||
|
||||
def test_isdescriptor():
|
||||
def func(x, y, z):
|
||||
pass
|
||||
|
||||
class Foo:
|
||||
def meth(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
def prop(self):
|
||||
pass
|
||||
|
||||
assert inspect.isdescriptor(Foo.prop) is True # property of class
|
||||
assert inspect.isdescriptor(Foo().prop) is False # property of instance
|
||||
assert inspect.isdescriptor(Foo.meth) is True # method of class
|
||||
assert inspect.isdescriptor(Foo().meth) is True # method of instance
|
||||
assert inspect.isdescriptor(func) is True # function
|
||||
|
||||
Reference in New Issue
Block a user