Skip to content

Commit

Permalink
Finish test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmtroffaes committed Aug 24, 2023
1 parent 0efbb51 commit 1fa2776
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion test/roots/test-autoapi/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extensions = ["sphinxcontrib.bibtex", "autoapi.extension"]
exclude_patterns = ["_build"]
bibtex_bibfiles = ["test.bib"]
autoapi_python_class_content = "both" # document __init__ method too
autoapi_dirs = ["some_module/"]
autoapi_keep_files = True # useful for debugging
autoapi_add_toctree_entry = False
autoapi_add_toctree_entry = False
19 changes: 18 additions & 1 deletion test/roots/test-autoapi/some_module/footcite.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Docstring for some_module. :footcite:`testmodule`"""
"""Docstring for some_module. :footcite:`testmodule`
.. footbibliography::
"""


def func(funcarg):
Expand All @@ -7,26 +10,34 @@ def func(funcarg):
Long description goes here. See :footcite:`testfunc`.
:param funcarg: Docstring for parameter. :footcite:`testfuncarg`
.. footbibliography::
"""


a = 1
"""Docstring for variable a.
Long description goes here. See :footcite:`testdata`.
.. footbibliography::
"""


class Foo:
"""Docstring for class Foo.
Long description goes here. See :footcite:`testclass`.
.. footbibliography::
"""

b = 2
"""Docstring for class attribute b.
Long description goes here. See :footcite:`testclassattr`.
.. footbibliography::
"""

def __init__(self, initarg):
Expand All @@ -35,12 +46,16 @@ def __init__(self, initarg):
Long description goes here. See :footcite:`testinit`.
:param initarg: Docstring for parameter. :footcite:`testinitarg`
.. footbibliography::
"""

self.c = 3
"""Docstring for instance attribute c.
Long description goes here. See :footcite:`testinstanceattr`
.. footbibliography::
"""

def method(self, methodarg):
Expand All @@ -49,4 +64,6 @@ def method(self, methodarg):
Long description goes here. See :footcite:`testmethod`.
:param methodarg: Docstring for parameter. :footcite:`testmethodarg`
.. footbibliography::
"""
10 changes: 6 additions & 4 deletions test/test_autoapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
@pytest.mark.sphinx("html", testroot="autoapi")
def test_autoapi(app, warning) -> None:
app.build()
# assert not warning.getvalue()
assert not warning.getvalue()
root = (app.outdir / "index.html").read_text()
output = (app.outdir / "autoapi/some_module/cite/index.html").read_text()
labels = [
"One",
Expand Down Expand Up @@ -48,14 +49,15 @@ def test_autoapi(app, warning) -> None:
]
for label, title in zip(labels, titles):
assert len(html_citation_refs_single(label=label).findall(output)) == 1
assert len(html_citations(label=label).findall(output)) == 1
assert len(html_citations(label=label).findall(root)) == 1
match_ref = html_citation_refs_single(label=label).search(output)
match = html_citations(label=label).search(output)
match = html_citations(label=label).search(root)
assert match_ref
assert match
assert match_ref.group("refid") == match.group("id_")
assert title in match.group("text")
assert match_ref.group("id_") == match.group("backref")
# no backrefs as citations are in other document
# assert match_ref.group("id_") == match.group("backref")
output2 = (app.outdir / "autoapi/some_module/footcite/index.html").read_text()
assert len(html_footnote_refs().findall(output2)) == 11
for title in titles:
Expand Down

0 comments on commit 1fa2776

Please sign in to comment.