tests.sphinx.test_sphinx_todos moduleΒΆ

Tests for the todolist deduplication hook and the unrendered-todo check.

tests.sphinx.test_sphinx_todos.TODO_SOURCE_RE = re.compile('<p class="todo-source">\\(The <a class="reference internal" href="([^"]+)">.*?located in (.*?), line (\\d+)\\.\\)</p>', re.DOTALL)ΒΆ

Captures the page, the origin and the line of every rendered todo entry.

sphinx.ext.todo emits one such paragraph per entry it puts on a todolist, so counting them counts the entries.

tests.sphinx.test_sphinx_todos.COMPOST_MODULE = '"""Turn fallen fruit into compost.\n\n.. todo::\n   Turn the heap once a week.\n"""\n'ΒΆ

A module docstring with a todo on its third line.

tests.sphinx.test_sphinx_todos.GRAFTING_MODULE = '"""Fruit grafting."""\n\n\ndef _graft(branch):\n    """Join ``branch`` to a rootstock.\n\n    .. todo::\n       Seal the cut with wax.\n    """\n    return branch\n'ΒΆ

A module whose only todo sits in a private function, which :members: skips.

tests.sphinx.test_sphinx_todos.VARIETIES_MODULE = '"""Fruit varieties."""\n\n\nclass Fruit:\n    """A fruit."""\n\n\nAPPLE = Fruit()\n"""A crisp apple.\n\n.. todo::\n   Pick the reddest one first.\n"""\n\nAPPLE.__doc__ = """A crisp apple.\n\n.. todo::\n   Pick the reddest one first.\n"""\n'ΒΆ

A module whose attribute docstring the instance carries too.

A registry of documented instances copies it this way, so that autodoc finds the docstring under a path that re-exports the attribute, where no source carries it. autodoc labels each rendering with the path it documented.

tests.sphinx.test_sphinx_todos.VARIETIES_INIT = '"""An orchard."""\n\nfrom .varieties import APPLE\n\n__all__ = ["APPLE"]\n'ΒΆ

A package re-exporting the attribute of VARIETIES_MODULE.

tests.sphinx.test_sphinx_todos.BOWLS_MODULE = '"""Fruit bowls."""\n\n\nclass Fruit:\n    """A fruit."""\n\n\nBOWL = Fruit()\n\nPEAR = BOWL\n"""A pear.\n\n.. todo::\n   Wait for autumn.\n"""\n\nQUINCE = BOWL\n"""A quince.\n\n.. todo::\n   Cook it first.\n"""\n'ΒΆ

Two attributes bound to one object, each with a todo of its own on one line.

tests.sphinx.test_sphinx_todos.UNRENDERED_RE = re.compile('(\\S+):(\\d+): WARNING: click_extra\\.sphinx: no page renders the docstring of (\\S+), so no todolist can list this todo\\.')ΒΆ

Captures the file, the line and the owner of every unrendered-todo warning.

tests.sphinx.test_sphinx_todos.build_project(tmp_path, package, pages, *, files=None, conf=(), dedupe=None, todo_extension=True)[source]ΒΆ

Build a throwaway project documenting package, and return the build.

pages maps a docname to its reStructuredText body. A todos page carrying the todolist is always appended, and every page is wired into the root toctree.

package names the generated package, and must differ between tests: the modules are imported by autodoc into the running interpreter, where sys.modules would otherwise serve the first test’s copy to every later one.

files maps a path inside the package to its source, written over the orchard’s own __init__.py and harvest.py. conf appends lines to the generated conf.py.

Returns the output directory, the warning stream and the exit status.

tests.sphinx.test_sphinx_todos.build_orchard(tmp_path, package, pages, **options)[source]ΒΆ

Build a project with build_project, and return its todo entries.

Returns the (page, origin, line) triples the todolist page rendered, in document order.

tests.sphinx.test_sphinx_todos.unrendered_todos(warnings)[source]ΒΆ

Return the (file name, line, owner) of each unrendered-todo warning.

tests.sphinx.test_sphinx_todos.automodule(target, no_index=False)[source]ΒΆ

Render an automodule block for target.

tests.sphinx.test_sphinx_todos.fake_node(source, line=1)[source]ΒΆ

A todo node reduced to the two attributes the identity helpers read.

tests.sphinx.test_sphinx_todos.test_todo_identity_ignores_the_import_path_of_a_docstring()[source]ΒΆ

Two renderings of one docstring share an identity whatever reached it.

tests.sphinx.test_sphinx_todos.test_todo_identity_reads_the_source_form_without_a_file()[source]ΒΆ

A source autodoc wrote without a file yields its label like one with a file.

tests.sphinx.test_sphinx_todos.test_is_reexport(source, expected)[source]ΒΆ

Only a docstring reached through a package __init__ ranks as re-exported.

tests.sphinx.test_sphinx_todos.test_full_api_page_and_feature_page_yield_one_entry_each(tmp_path)[source]ΒΆ

A module documented twice across pages lists each todo once.

tests.sphinx.test_sphinx_todos.test_reexported_members_yield_one_entry_each(tmp_path)[source]ΒΆ

A member documented under both its package and its module lists once.

tests.sphinx.test_sphinx_todos.test_surviving_entry_attributes_to_the_defining_module(tmp_path)[source]ΒΆ

The kept rendering names the module defining the object, not the package.

tests.sphinx.test_sphinx_todos.test_reexported_attribute_yields_one_entry(tmp_path)[source]ΒΆ

An attribute documented under its package and its module lists once.

The two renderings of its docstring carry different labels, the paths autodoc documented: only the object behind both labels matches them.

tests.sphinx.test_sphinx_todos.test_attributes_sharing_an_object_keep_an_entry_each(tmp_path)[source]ΒΆ

Two docstrings of one object keep their entries, though the object matches.

tests.sphinx.test_sphinx_todos.test_dedupe_switched_off_restores_every_rendering(tmp_path)[source]ΒΆ

click_extra_dedupe_todos = False gives Sphinx’s raw output back.

tests.sphinx.test_sphinx_todos.test_distinct_todos_all_survive(tmp_path)[source]ΒΆ

Deduplication collapses repeats, never two different directives.

tests.sphinx.test_sphinx_todos.test_build_succeeds_without_the_todo_extension(tmp_path)[source]ΒΆ

The hook is inert on a project that never registered the todo domain.

tests.sphinx.test_sphinx_todos.test_sort_todos_orders_the_domain_by_page()[source]ΒΆ

Entries merged out of page order, as a parallel read does, come back sorted.

tests.sphinx.test_sphinx_todos.test_sort_todos_is_inert_without_entries(domains)[source]ΒΆ

A project with no todo domain, or no todo in it, is left as it was.

tests.sphinx.test_sphinx_todos.test_docstring_todos(source, expected)[source]ΒΆ

Each todo is found at its line, under the path autodoc labels it with.

tests.sphinx.test_sphinx_todos.test_docstring_todos_rejects_invalid_source()[source]ΒΆ

A module that does not parse raises, for the caller to skip it.

tests.sphinx.test_sphinx_todos.test_package_modules_walks_without_importing(tmp_path, monkeypatch)[source]ΒΆ

Every module of a package is found, private ones included, none imported.

tests.sphinx.test_sphinx_todos.test_unrendered_todos_warn_at_their_line(tmp_path)[source]ΒΆ

A todo in a docstring no page renders is reported at its own line.

tests.sphinx.test_sphinx_todos.test_rendered_todos_do_not_warn(tmp_path)[source]ΒΆ

No todo a page renders is reported, a re-exported one included.

tests.sphinx.test_sphinx_todos.test_todo_rendered_under_another_path_does_not_warn(tmp_path)[source]ΒΆ

A docstring autodoc labels with another path still counts as rendered.

With its __module__ overridden, pick is labeled with the path of the package, not with the path of the module that defines it.

tests.sphinx.test_sphinx_todos.test_unrendered_todo_check_stays_silent(tmp_path, package, options)[source]ΒΆ

The check is inert when no todo renders, and suppress_warnings hides it.

tests.sphinx.test_sphinx_todos.test_listed_unrendered_todo_fails_the_build(tmp_path)[source]ΒΆ

Listing the warning in click_extra_fail_on_warnings fails the build.