From 4aecac8251f3c061aa33d056c87e978d13ce970c Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 13 Apr 2019 22:48:49 +0900 Subject: [PATCH] refactor: Move subject of inspection to rootdir --- .../test-ext-autodoc/target/functions.py | 11 ++ .../roots/test-ext-autodoc/target/methods.py | 24 +++++ tests/test_util_inspect.py | 102 +++++++----------- 3 files changed, 73 insertions(+), 64 deletions(-) create mode 100644 tests/roots/test-ext-autodoc/target/functions.py create mode 100644 tests/roots/test-ext-autodoc/target/methods.py diff --git a/tests/roots/test-ext-autodoc/target/functions.py b/tests/roots/test-ext-autodoc/target/functions.py new file mode 100644 index 000000000..7c79188d9 --- /dev/null +++ b/tests/roots/test-ext-autodoc/target/functions.py @@ -0,0 +1,11 @@ +from functools import partial + + +def func(): + pass + + +partial_func = partial(func) + +builtin_func = print +partial_builtin_func = partial(print) diff --git a/tests/roots/test-ext-autodoc/target/methods.py b/tests/roots/test-ext-autodoc/target/methods.py new file mode 100644 index 000000000..49122eb4c --- /dev/null +++ b/tests/roots/test-ext-autodoc/target/methods.py @@ -0,0 +1,24 @@ +from functools import partialmethod + + +class Base(): + def meth(self): + pass + + @staticmethod + def staticmeth(): + pass + + @classmethod + def classmeth(cls): + pass + + @property + def prop(self): + pass + + partialmeth = partialmethod(meth) + + +class Inherited(Base): + pass diff --git a/tests/test_util_inspect.py b/tests/test_util_inspect.py index 99fb83a27..d167c1740 100644 --- a/tests/test_util_inspect.py +++ b/tests/test_util_inspect.py @@ -383,78 +383,52 @@ def test_dict_customtype(): assert ": 2" in description -def test_isstaticmethod(): - class Foo(): - @staticmethod - def method1(): - pass +@pytest.mark.sphinx(testroot='ext-autodoc') +def test_isstaticmethod(app): + from target.methods import Base, Inherited - def method2(self): - pass - - class Bar(Foo): - pass - - assert inspect.isstaticmethod(Foo.method1, Foo, 'method1') is True - 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 + assert inspect.isstaticmethod(Base.staticmeth, Base, 'staticmeth') is True + assert inspect.isstaticmethod(Base.meth, Base, 'meth') is False + assert inspect.isstaticmethod(Inherited.staticmeth, Inherited, 'staticmeth') is True + assert inspect.isstaticmethod(Inherited.meth, Inherited, 'meth') is False -def test_isfunction(): - def func(x, y, z): - pass +@pytest.mark.sphinx(testroot='ext-autodoc') +def test_isfunction(app): + from target.functions import builtin_func, partial_builtin_func + from target.functions import func, partial_func + from target.methods import Base - 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 + assert inspect.isfunction(func) is True # function + assert inspect.isfunction(partial_func) is True # partial-ed function + assert inspect.isfunction(Base.meth) is True # method of class + assert inspect.isfunction(Base.partialmeth) is True # partial-ed method of class + assert inspect.isfunction(Base().meth) is False # method of instance + assert inspect.isfunction(builtin_func) is False # builtin function + assert inspect.isfunction(partial_builtin_func) is False # partial-ed builtin function -def test_isbuiltin(): - def func(x, y, z): - pass +@pytest.mark.sphinx(testroot='ext-autodoc') +def test_isbuiltin(app): + from target.functions import builtin_func, partial_builtin_func + from target.functions import func, partial_func + from target.methods import Base - 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 + assert inspect.isbuiltin(builtin_func) is True # builtin function + assert inspect.isbuiltin(partial_builtin_func) is True # partial-ed builtin function + assert inspect.isbuiltin(func) is False # function + assert inspect.isbuiltin(partial_func) is False # partial-ed function + assert inspect.isbuiltin(Base.meth) is False # method of class + assert inspect.isbuiltin(Base().meth) is False # method of instance -def test_isdescriptor(): - def func(x, y, z): - pass +@pytest.mark.sphinx(testroot='ext-autodoc') +def test_isdescriptor(app): + from target.functions import func + from target.methods import Base - 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(Base.prop) is True # property of class + assert inspect.isdescriptor(Base().prop) is False # property of instance + assert inspect.isdescriptor(Base.meth) is True # method of class + assert inspect.isdescriptor(Base().meth) is True # method of instance assert inspect.isdescriptor(func) is True # function