tests.sphinx packageΒΆ

SubmodulesΒΆ

tests.sphinx.conftest moduleΒΆ

Fixtures and helpers for Sphinx tests.

Separated from the root tests/conftest.py so that the Sphinx dependency (and its ecosystem: myst-parser, docutils, etc.) is only imported when running the tests in this subdirectory. Downstream packagers can skip these tests with --ignore=tests/sphinx without affecting the rest of the test suite.

class tests.sphinx.conftest.FormatType(*values)[source]ΒΆ

Bases: Enum

Sphinx document format types and their file extensions.

RST = '.rst'ΒΆ
MYST = '.md'ΒΆ
class tests.sphinx.conftest.SphinxAppWrapper(app, format_type)[source]ΒΆ

Bases: object

Wrapper around Sphinx application with additional testing methods.

classmethod create(format_type, tmp_path, return_srcdir=False, enable_exec_directives=True)[source]ΒΆ

Factory method to create a SphinxAppWrapper with given format.

enable_exec_directives opts the test app into the click:* and python:* directive families. Defaults to True for every fixture-built app because the test suite primarily exercises those directives. Tests that verify the off-by-default production gate flip the flag back to False explicitly.

Return type:

Generator[SphinxAppWrapper | tuple[SphinxAppWrapper, Path], None, None]

build_document(content)[source]ΒΆ

Build a Sphinx document with content and return the HTML output.

Automatically detects the format from the app configuration and uses the appropriate file extension (.rst or .md).

Return type:

str | None

generate_test_content(test_case)[source]ΒΆ

Generate content for a test case based on the app’s format type.

Return type:

str

tests.sphinx.conftest.sphinx_app(request, tmp_path)[source]ΒΆ

Create a Sphinx application for testing.

tests.sphinx.conftest.sphinx_app_rst(tmp_path)[source]ΒΆ

Create a Sphinx application for testing RST format only.

The click:* and python:* directive families are enabled so tests can exercise them. Tests that explicitly verify the off-by- default opt-in gate construct their own app via SphinxAppWrapper.create() with enable_exec_directives=False.

tests.sphinx.conftest.sphinx_app_myst(tmp_path)[source]ΒΆ

Create a Sphinx application for testing MyST format only.

The click:* and python:* directive families are enabled β€” see sphinx_app_rst() for the rationale.

tests.sphinx.conftest.sphinx_app_myst_with_include(tmp_path)[source]ΒΆ

Create a Sphinx application for testing MyST format with include files.

class tests.sphinx.conftest.DirectiveTestCase(name, format_type=None, source_block=None, run_block=None, document=None, html_matches=None)[source]ΒΆ

Bases: object

Test case data for directive tests.

name: strΒΆ
format_type: FormatType | None = NoneΒΆ
source_block: str | None = NoneΒΆ
run_block: str | None = NoneΒΆ
document: str | None = NoneΒΆ
html_matches: Sequence[str] | str | None = NoneΒΆ
supports_format(format_type)[source]ΒΆ

Check if this test case supports the given format type.

Todo

Get rid of this method, and make the test case provide its own sphinx_app.

Return type:

bool

tests.sphinx.conftest.python_block(*lines)[source]ΒΆ

Build expected Python highlight block.

Return type:

str

tests.sphinx.conftest.shell_block(*lines)[source]ΒΆ

Build expected shell session block.

Return type:

str

tests.sphinx.conftest.admonition_block(admonition_type, content)[source]ΒΆ

Build expected admonition block.

Return type:

str

Args:

admonition_type: The type of admonition (note, tip, warning, etc.) content: The inner HTML content of the admonition (without the title)

tests.sphinx.test_sphinx moduleΒΆ

Fixtures and utilities for Sphinx testing.

tests.sphinx.test_sphinx.test_sphinx_extension_setup(sphinx_app)[source]ΒΆ

Test that the Sphinx extension is properly loaded.

tests.sphinx.test_sphinx.test_resolve_any_xref(sphinx_app)[source]ΒΆ

Test that resolve_any_xref is implemented and returns an empty list.

tests.sphinx.test_sphinx_alerts moduleΒΆ

Tests for GitHub alert syntax conversion in Sphinx with MyST parser.

tests.sphinx.test_sphinx_alerts.test_all_alert_types(alert_type)[source]ΒΆ

Test all supported alert types are converted correctly.

tests.sphinx.test_sphinx_alerts.test_alert_conversion(text, expected)[source]ΒΆ

Test GitHub alerts are converted to MyST admonitions.

When expected is None, no conversion should occur.

tests.sphinx.test_sphinx_alerts.test_sphinx_integration(sphinx_app, test_case)[source]ΒΆ

Integration-critical tests that verify Sphinx rendering behavior.

tests.sphinx.test_sphinx_alerts.test_github_alert_no_colon_fence(tmp_path)[source]ΒΆ

Test that ConfigError is raised when colon_fence is not enabled.

tests.sphinx.test_sphinx_alerts.test_github_alert_in_included_files(sphinx_app_myst_with_include, included_files, main_content, expected_fragments, unexpected_fragments)[source]ΒΆ

Test GitHub alerts in included files with various configurations.

tests.sphinx.test_sphinx_click moduleΒΆ

Tests for Sphinx directives click:source and click:run in rST and MyST formats.

tests.sphinx.test_sphinx_click.test_directive_functionality(sphinx_app, test_case)[source]ΒΆ

Test standard directive functionalities in both rST and MyST.

tests.sphinx.test_sphinx_click.test_directive_option_format(sphinx_app_rst)[source]ΒΆ

rST will fail to render if an :option: is not followed by an empty line.

tests.sphinx.test_sphinx_click.test_directive_option_language_override(sphinx_app)[source]ΒΆ

Test that language override works for click:run directive.

tests.sphinx.test_sphinx_click.test_sphinx_directive_state_persistence(sphinx_app)[source]ΒΆ

Test that state persists between declare and run directives in real Sphinx.

tests.sphinx.test_sphinx_click.test_directive_variable_conflict(var_name, sphinx_app, content, directive_lineno, error_lineno)[source]ΒΆ

Test that variable conflicts are properly detected in real Sphinx environment.

tests.sphinx.test_sphinx_click.test_exit_exception_percolate(sphinx_app)[source]ΒΆ

Test directives that handle command errors and exit codes.