tests.sphinx.test_sphinx_viewcode moduleΒΆ

Tests for the sphinx.ext.viewcode pages a build publishes.

tests.sphinx.test_sphinx_viewcode.FRUITS_MODULE = 'import re\n\nSEED = re.compile(r"\\d+")\n"""Pattern of a seed count."""\n\n\ndef ripen(fruit):\n    """Ripen a fruit."""\n'ΒΆ

A module documenting a constant whose value is an instance of re.Pattern.

viewcode looks for SEED in the module of that class, re, and finds nothing to link to there.

tests.sphinx.test_sphinx_viewcode.PUBLISHED_PAGES = ['_modules/fruits.html', '_modules/index.html']ΒΆ

The module page of fruits, and the index linking to it.

tests.sphinx.test_sphinx_viewcode.write_project(srcdir)[source]ΒΆ

Write a project whose last document read documents fruits.

No later document purges the unused re entry, so a serial read keeps it too.

Return type:

None

tests.sphinx.test_sphinx_viewcode.module_pages(outdir)[source]ΒΆ

List the viewcode pages of a build, relative to its output directory.

Return type:

list[str]

tests.sphinx.test_sphinx_viewcode.test_serial_read_publishes_linked_modules_only(tmp_path, monkeypatch)[source]ΒΆ

A serial read publishes no page for the module it read for nothing.

tests.sphinx.test_sphinx_viewcode.test_parallel_read_publishes_the_pages_of_a_serial_one(tmp_path)[source]ΒΆ

A parallel read publishes the same pages as a serial one.

Its workers merge their entries after every purge has run, which is the case of sphinx-doc/sphinx#14675. The build runs in a process of its own: forking the test process, which runs other threads, can deadlock the workers.

tests.sphinx.test_sphinx_viewcode.VINEYARD_MODULES = {'__init__.py': '', 'grape.py': 'class Grape:\n    """A grape of the vineyard."""\n', 'harvest.py': 'from vineyard.grape import Grape\n\nMERLOT = Grape()\n"""A grape of the harvest."""\n'}ΒΆ

A package whose harvest module documents an instance of a grape class.

viewcode reads MERLOT in the module of its class, vineyard.grape, and finds no definition of it there.

A [docs] link leads to its object, whatever signature viewcode read first.

The page documents the instance before the class, so the instance creates the viewcode entry of vineyard.grape under the module path vineyard.harvest (sphinx-doc/sphinx#14815). One page is enough: a serial read purges an entry only between two pages.