Skip to content

Commit

Permalink
Move func
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jul 28, 2023
1 parent 5759a71 commit 551ab65
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions tests/test_ext_autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,28 +283,6 @@ def foo3(self, d='\n'):
'(b, c=42, *d, **e)'


def _assert_getter_works(app, directive, objtype, name, attrs=(), **kw):
getattr_spy = []

def _special_getattr(obj, attr_name, *defargs):
if attr_name in attrs:
getattr_spy.append((obj, attr_name))
return None
return getattr(obj, attr_name, *defargs)

app.add_autodoc_attrgetter(type, _special_getattr)

getattr_spy.clear()
app.registry.documenters[objtype](directive, name).generate(**kw)

hooked_members = {s[1] for s in getattr_spy}
documented_members = {s[1] for s in processed_signatures}
for attr in attrs:
fullname = '.'.join((name, attr))
assert attr in hooked_members
assert fullname not in documented_members, f'{fullname!r} not intercepted'


@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_process_signature_typing_generic(app):
actual = do_autodoc(app, 'class', 'target.generic_class.A', {})
Expand Down Expand Up @@ -439,6 +417,28 @@ def test_attrgetter_using(app):
_assert_getter_works(app, directive, 'class', 'target.inheritance.Derived', ['inheritedmeth'])


def _assert_getter_works(app, directive, objtype, name, attrs=(), **kw):
getattr_spy = []

def _special_getattr(obj, attr_name, *defargs):
if attr_name in attrs:
getattr_spy.append((obj, attr_name))
return None
return getattr(obj, attr_name, *defargs)

app.add_autodoc_attrgetter(type, _special_getattr)

getattr_spy.clear()
app.registry.documenters[objtype](directive, name).generate(**kw)

hooked_members = {s[1] for s in getattr_spy}
documented_members = {s[1] for s in processed_signatures}
for attr in attrs:
fullname = '.'.join((name, attr))
assert attr in hooked_members
assert fullname not in documented_members, f'{fullname!r} not intercepted'


@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_py_module(app, warning):
# without py:module
Expand Down

0 comments on commit 551ab65

Please sign in to comment.