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.
- tests.sphinx.conftest.MYST_HAS_NATIVE_ALERTS = TrueΒΆ
Flip-switch reused by tests to branch between the two alert rendering paths:
click_extraβs regex converter (pre-5.1) andmyst-parserβs native"alert"extension (>=5.1). Both paths must produce the same admonition HTML.
- class tests.sphinx.conftest.FormatType(*values)[source]ΒΆ
Bases:
EnumSphinx document format types and their file extensions.
- RST = '.rst'ΒΆ
- MYST = '.md'ΒΆ
- class tests.sphinx.conftest.SphinxAppWrapper(app, format_type)[source]ΒΆ
Bases:
objectWrapper 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_directivesopts the test app into theclick:*andpython:*directive families. Defaults toTruefor 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 toFalseexplicitly.- Return type:
Generator[SphinxAppWrapper|tuple[SphinxAppWrapper,Path],None,None]
- tests.sphinx.conftest.sphinx_app(request, tmp_path)[source]ΒΆ
Create a Sphinx application for testing.
- tests.sphinx.conftest.sphinx_app_for_format(request, tmp_path)[source]ΒΆ
sphinx_appvariant whose format is supplied by the caller.Identical to
sphinx_app()but without the defaultparams: theFormatTypeis taken from the testβs indirect parametrization. Aparams-bearing fixture cannot also be parametrized by a test (pytest rejects it as a duplicate parametrization), so a test that drives the format per case parametrizes this variant instead, usually throughformat_params().
- tests.sphinx.conftest.sphinx_app_rst(tmp_path)[source]ΒΆ
Create a Sphinx application for testing RST format only.
The
click:*andpython:*directive families are enabled so tests can exercise them. Tests that explicitly verify the off-by- default opt-in gate construct their own app viaSphinxAppWrapper.create()withenable_exec_directives=False.
- tests.sphinx.conftest.sphinx_app_myst(tmp_path)[source]ΒΆ
Create a Sphinx application for testing MyST format only.
The
click:*andpython:*directive families are enabled: seesphinx_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:
objectTest case data for directive tests.
- format_type: FormatType | None = NoneΒΆ
- tests.sphinx.conftest.format_params(*test_cases)[source]ΒΆ
Pair each test case with every document format it is written for.
Feeds the indirect parametrization of
sphinx_app_for_format(), so a case is only ever built by an app whose format it can render: a case pinned to aFormatTypeyields that format alone, a format-agnostic one yields a parameter per format.
- tests.sphinx.conftest.unescape_quotes(text)[source]ΒΆ
Replace quote entities with bare quotes, so both escapings compare equal.
Pygments 2.21.0 replaced its
escape_html()helper withhtml.escape(value, quote=False). Token text carries bare"and'since then, where older releases produced"and'. Both forms render the same, and thepygmentsextra declares a floor spanning that release, so HTML fragments are compared with quotes normalized.- Return type:
- tests.sphinx.conftest.python_block(*lines)[source]ΒΆ
Build expected Python highlight block.
- Return type:
tests.sphinx.test_sphinx moduleΒΆ
Fixtures and utilities for Sphinx testing.
- tests.sphinx.test_sphinx.test_import_without_myst_parser()[source]ΒΆ
The extension imports for a reST-only project, which installs no myst-parser.
The
sphinxextra does not declaremyst-parserand Sphinx does not depend on it, so a hard import of it inclick_extra.sphinxbreaks such a project outright.
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_for_format, test_case)[source]ΒΆ
Integration-critical tests that verify Sphinx rendering behavior.
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_for_format, test_case)[source]ΒΆ
Test standard directive functionalities in each format a case targets.
- 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_for_format, content, directive_lineno, error_lineno)[source]ΒΆ
Test that variable conflicts are properly detected in real Sphinx environment.
- tests.sphinx.test_sphinx_click.GENERATED_BLOCK_ANCHOR = 'from click_extra import command, echo'ΒΆ
First body line of the
GENERATED_BLOCK_LINE_CASESdocuments below.The line a generated block is expected to be attributed to, located in the document itself so editing a case moves the expectation with it.
- tests.sphinx.test_sphinx_click.test_generated_block_is_attributed_to_the_directive_body(sphinx_app_for_format, test_case)[source]ΒΆ
A block a directive generates is attributed to its first body line.
The generated lines exist nowhere in the document, so the parser has to be told which document line to hang a diagnostic raised inside them on. Both formats must answer the same way, and neither is free to fall back on its own default: docutils numbers an unlabelled block from the top of the file, and
myst-parsermeasures its offsets from the directive rather than the document.The last two cases pin the
content_offsetinflationclick_extra.sphinx.click.MYST_CONTENT_OFFSET_INFLATED_MAXdocuments, which only fires on a directive carrying both an option block and a body ending in blank lines.
- tests.sphinx.test_sphinx_click.test_exit_exception_percolate(sphinx_app)[source]ΒΆ
Test directives that handle command errors and exit codes.
- tests.sphinx.test_sphinx_click.test_clickrunner_forces_color(monkeypatch)[source]ΒΆ
ClickRunnerforcesFORCE_COLORso Rich-based CLIs colorize underNO_COLOR.The runner already passes
color=True(Clickβs color system). But rich-click renders help through RichβsConsole, gated onFORCE_COLOR, whichcolor=Truenever reaches. The runner therefore also forcesFORCE_COLOR(clearing the disabling vars) around the executed command, then restores the environment.
- tests.sphinx.test_sphinx_click.test_clickrunner_capture_mode_controls_fileno(capture, renders)[source]ΒΆ
ClickRunner(capture=...)decides whether a fileno-writing CLI renders.Clickβs
"sys"mode backs the captured stream with an in-memory buffer whosefileno()raisesio.UnsupportedOperation, so a documented command that re-opens its descriptor (a common UTF-8-on-Windows guard) aborts."fd"(the default on Unix, also exposed as theclick_extra_run_captureconf.py value) backs it with a real descriptor, so the command renders. On Windows, where fd-backed streams are not supported, the default falls back to"sys".
- tests.sphinx.test_sphinx_click.test_program_from_command_line(command_line, expected)[source]ΒΆ
Only an interpreter prefix is dropped from a displayed command line.
- tests.sphinx.test_sphinx_click.test_clickrunner_keeps_a_multi_word_prog_name(monkeypatch)[source]ΒΆ
A subcommand-shaped program name reaches the command it runs, whole.
- tests.sphinx.test_sphinx_click.test_clickrunner_prompt_inlines_environment_assignments(monkeypatch)[source]ΒΆ
Variables are set on the invocation, the way the runner applies them.
CliRunnerscopesenvto the one call, so anexportline would advertise a persistence the next block does not inherit.
- tests.sphinx.test_sphinx_click.test_clickrunner_prompt_quotes_a_spaced_argument(monkeypatch)[source]ΒΆ
An argument holding spaces stays the single token a reader must type.
- tests.sphinx.test_sphinx_click.test_clickrunner_hide_prompt_drops_the_invocation(monkeypatch)[source]ΒΆ
_show_prompt=Falseleaves the output alone and drops the line above it.
- tests.sphinx.test_sphinx_click.test_click_run_prompt_options(sphinx_app_myst, options, prompted)[source]ΒΆ
:show-prompt:/:hide-prompt:gate the invocation line.
- tests.sphinx.test_sphinx_click.test_click_run_hide_prompt_reaches_the_screenshot(sphinx_app_myst)[source]ΒΆ
A capture is drawn from the same lines, so it loses the prompt too.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_writes_the_asset(sphinx_app_myst)[source]ΒΆ
:screenshot:writes the capture beside the documentation.The image is a side effect: the page keeps its results code block, which inside Sphinx beats an image by staying selectable and searchable.
- tests.sphinx.test_sphinx_click.ANIMATED_SOURCE = '\n ```{click:source}\n :hide-source:\n from click_extra import SPINNERS, Spinner, Style, command, echo\n\n @command\n def greet():\n echo("Hello, papaya!")\n\n steeping = Spinner("Steeping", spinner=SPINNERS["moon"], style=Style(fg="green"))\n ```\n'ΒΆ
A spinner and a CLI, seeded for the animated-capture blocks below.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_animate_stacks_a_spinner(sphinx_app_myst)[source]ΒΆ
:screenshot-animate:draws every frame of the spinner it names.The frames and the interval are taken off the spinner itself, so the picture and the animation cannot disagree about either.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_animate_defines_every_class_it_uses(sphinx_app_myst)[source]ΒΆ
No frame names a class the animated capture leaves undefined.
A frame whose rules are missing does not vanish: it falls back to the presentation attributes and draws in the wrong face and the wrong color, which reads as the animation resetting its styling once a cycle.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_animate_accepts_bare_frames(sphinx_app_myst)[source]ΒΆ
A sequence of texts animates too, timed by
:screenshot-interval:.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_animate_bare_frames_need_an_interval(sphinx_app_myst)[source]ΒΆ
Bare frames carry no timing of their own, so one has to be stated.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_animate_rejects_a_foreign_subject(sphinx_app_myst)[source]ΒΆ
Something that is neither a spinner nor frames fails the build.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_animate_is_deterministic(sphinx_app_myst)[source]ΒΆ
A declared subject composes the same lines on every build.
This is what lets an animated capture be committed at all: a recording would time its frames a little differently on every run and dirty the tree.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_animate_rewrites_a_declared_asset(sphinx_app_myst)[source]ΒΆ
A declared animation is regenerated on every build, like any capture.
It composes the same lines every time, so rewriting costs nothing and is what keeps the asset from drifting away from the code. Gating the write on what the animation is would freeze out every change to how it is drawn.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_animate_carries_a_presentation_change(sphinx_app_myst)[source]ΒΆ
Restating how an animation is drawn reaches the committed asset.
The frames are untouched by a margin, so nothing about what the animation is moves. The picture still has to change.
- tests.sphinx.test_sphinx_click.RECORDED_SOURCE = '\n ```{click:source}\n :hide-source:\n from click_extra.recording import Frame\n\n kettle = [Frame("filling", 0.2), Frame("boiled", 0.2)]\n ```\n'ΒΆ
A stand-in recording: frames carrying their own durations, as one does.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_record_writes_once(sphinx_app_myst)[source]ΒΆ
A recorded animation is written the first time and then left alone.
Which spinner glyph pairs with which screen is settled by the scheduler, so a recording cannot be reproduced and rewriting it would dirty the working tree for nothing anyone did.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_record_holds_its_last_frame(sphinx_app_myst)[source]ΒΆ
A recording pauses on its final screen before starting over.
An animation that ends somewhere is worth reading, and a loop restarting the instant it arrives never lets anyone.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_hold_overrides_the_pause(sphinx_app_myst)[source]ΒΆ
:screenshot-hold:states the pause a page would rather have.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_blank_closes_the_cycle(sphinx_app_myst)[source]ΒΆ
A recording ends on an empty beat, so the loopβs turnover is visible.
Without it, a loop jumping from its last frame back to its first reads as one long animation doing something odd rather than as a repetition.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_speed_scales_the_recorded_frames(sphinx_app_myst)[source]ΒΆ
:screenshot-speed:replays faster, leaving the pauses as stated.The pauses are how long a reader is given, not part of what is replayed, so they are stated in real seconds and speed does not touch them.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_emphasize_lines_bands_a_still(sphinx_app_myst)[source]ΒΆ
:screenshot-emphasize-lines:draws a band behind the lines it names.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_emphasize_lines_bands_an_animation(sphinx_app_myst)[source]ΒΆ
A band marks a row of the screen, so an animation keeps it throughout.
Drawn once behind every frame rather than per frame: the emphasis is on the row, not on whatever a given frame happened to put there.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_emphasize_lines_rejects_a_line_that_is_not_there(sphinx_app_myst)[source]ΒΆ
Naming a line the capture never drew fails the build rather than passing.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_background(sphinx_app_myst)[source]ΒΆ
:screenshot-background:draws the capture on the chrome it names.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_columns_auto(sphinx_app_myst)[source]ΒΆ
:screenshot-columns: autowidens the image to what the block printed.Click wraps a CLIβs own text at its fixed width whatever the option says. What it decides is the picture, and a line the CLI never wrapped (the prompt of a long invocation) is the one that needs the room.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_columns_rejects_an_unusable_width(value)[source]ΒΆ
A width narrower than the floor, or no width at all, is a build error.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_frame_options(sphinx_app_myst)[source]ΒΆ
The
:screenshot-*:options restate the window, the title included.The hex color is quoted because a directiveβs options are read as YAML, where an unquoted
#opens a comment and leaves the option empty.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_preset_swaps_the_prompt(sphinx_app_myst)[source]ΒΆ
A capture drawn as another terminal prompts the way that one does.
A block runs under a documentation build, so its own prompt is this platformβs
$. The picture is of a Windows terminal, whose shell prompts with something else entirely.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_preset_defaults_to_the_project_wide_one(sphinx_app_myst)[source]ΒΆ
A project drawing every capture as the same terminal states it once.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_carries_no_watermark_by_default(sphinx_app_myst)[source]ΒΆ
A capture a build rewrites carries no release number to go stale.
The
screenshotcommand credits click-extra on every image it writes. A blockβs image is regenerated and committed on every build, so the same mark would rewrite every asset the day the release it names changes.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_watermark(sphinx_app_myst)[source]ΒΆ
A project wanting its captures credited states the line once.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_opacity(sphinx_app_myst)[source]ΒΆ
A see-through window lets the page it is laid on show through its body.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_opacity_rejects_what_is_not_one(argument)[source]ΒΆ
Anything outside the zero-to-one range fails the build instead of clamping.
- tests.sphinx.test_sphinx_click.test_click_run_screenshot_background_rejects_an_unknown_chrome()[source]ΒΆ
A typo names the chromes it could have been, instead of drawing a default.
- tests.sphinx.test_sphinx_click.test_click_run_mirror_region_round_trips()[source]ΒΆ
:mirror:inserts an image link below the fence, then leaves it alone.
- tests.sphinx.test_sphinx_click.test_click_run_mirror_needs_both_options()[source]ΒΆ
A block missing either option gets no region.
:screenshot:alone maintains an asset some other surface embeds, without putting it on this page;:mirror:alone has no capture to point at.
- tests.sphinx.test_sphinx_click.test_click_run_mirror_skips_a_nested_example()[source]ΒΆ
A
click:runshown inside a longer fence is documentation, not a block.
- tests.sphinx.test_sphinx_click.test_click_source_screenshot_pictures_its_own_code(sphinx_app_myst)[source]ΒΆ
A source blockβs
:screenshot:draws the code it declares.A directive that runs something has output worth committing; one that only declares code has none, so its subject is the code itself.
- tests.sphinx.test_sphinx_click.test_click_source_screenshot_takes_a_syntax_style(sphinx_app_myst)[source]ΒΆ
:screenshot-syntax-style:repaints the window along with the code.
- tests.sphinx.test_sphinx_click.test_click_source_screenshot_bands_its_emphasized_lines(sphinx_app_myst)[source]ΒΆ
:emphasize-lines:marks the same lines on the page and in the image.A source block has one content, so saying it twice would be the surprise.
- tests.sphinx.test_sphinx_click.test_click_source_screenshot_is_deterministic(sphinx_app_myst)[source]ΒΆ
Two builds of one source block write the same bytes.
Nothing here runs a command or reads a clock, so a committed asset stays put and leaves the working tree clean.
tests.sphinx.test_sphinx_click_tree moduleΒΆ
Tests for the click:tree Sphinx directive.
- tests.sphinx.test_sphinx_click_tree.KITCHEN_CLI = '```{click:source}\n:hide-source:\nfrom click import command, echo, group, option\n\n@group\ndef kitchen():\n """Manage kitchen tools and recipes."""\n\n@kitchen.command\n@option("--minutes", type=int, default=5)\ndef boil(minutes):\n """Boil water for tea."""\n echo(f"Boiling for {minutes} minutes.")\n\n@kitchen.group\ndef pantry():\n """Inspect pantry contents."""\n\n@pantry.command\ndef jars():\n """List jars on the shelf."""\n echo("Olives, honey, pickles.")\n```\n'ΒΆ
Toy CLI reused across tests. Defines a multi-level group so the walk exercises the recursive descent into nested
click.Groupcommands.
- tests.sphinx.test_sphinx_click_tree.test_click_tree_renders_summary_table_and_help_blocks(sphinx_app_myst)[source]ΒΆ
The directive expands into a GFM table + one help capture per command.
- tests.sphinx.test_sphinx_click_tree.test_click_tree_inline_import_in_body(sphinx_app_myst)[source]ΒΆ
The directive body runs as a preamble, so a seed
click:sourceis optional.
- tests.sphinx.test_sphinx_click_tree.test_click_tree_no_table_and_no_root(sphinx_app_myst)[source]ΒΆ
:no-table:and:no-root:drop the summary table and root block.
- tests.sphinx.test_sphinx_click_tree.test_click_tree_max_depth_truncates_walk(sphinx_app_myst)[source]ΒΆ
:max-depth: 1stops the walk at one level below the root.
- tests.sphinx.test_sphinx_click_tree.test_click_tree_label_and_anchor_prefix_override(sphinx_app_myst)[source]ΒΆ
:label-prefix:and:anchor-prefix:override the defaults.
- tests.sphinx.test_sphinx_click_tree.test_click_tree_errors_on_non_command(sphinx_app_myst)[source]ΒΆ
Resolving the argument to a non-Command raises a clear directive error.
- tests.sphinx.test_sphinx_click_tree.test_click_tree_errors_on_unknown_name(sphinx_app_myst)[source]ΒΆ
An expression that canβt be evaluated raises a clear directive error.
- tests.sphinx.test_sphinx_click_tree.test_click_tree_errors_in_rst(sphinx_app_rst)[source]ΒΆ
click:treeraises a clear error when used in an rST document.
- tests.sphinx.test_sphinx_click_tree.test_click_tree_heading_offset_defaults_to_top_level(sphinx_app_myst)[source]ΒΆ
Below a single
# Doc titlethe root renders ath2.Preserves the historical default behavior: a directive at the document body (inside the titleβs h1 section) emits its root one level below.
- tests.sphinx.test_sphinx_click_tree.test_click_tree_heading_offset_adapts_to_surrounding_section(sphinx_app_myst)[source]ΒΆ
Nested inside an
h3section, the root renders ath4.The default heading offset is computed from
state.memo.section_levelso the document outline stays consistent regardless of where the directive is placed.
- tests.sphinx.test_sphinx_click_tree.test_click_tree_heading_offset_explicit_override(sphinx_app_myst)[source]ΒΆ
An explicit
:heading-offset:wins over the auto-detected default.Surrounding headings establish a deep level so the overrideβs effect is clearly observable in the rendered HTML (without MyST normalizing skipped heading levels).
tests.sphinx.test_sphinx_manpages moduleΒΆ
Tests for click_extra.sphinx.manpages.
- tests.sphinx.test_sphinx_manpages.test_manpages_hook_writes_tree_into_outdir(tmp_path)[source]ΒΆ
An entry with just
scriptwrites the whole tree underman/.
- tests.sphinx.test_sphinx_manpages.test_manpages_hook_honors_prog_name_and_output_dir(tmp_path)[source]ΒΆ
An entry can override both the basename and the subdirectory.
- tests.sphinx.test_sphinx_manpages.test_manpages_hook_skips_non_html_builder(tmp_path)[source]ΒΆ
Non-HTML builders (like
linkcheck) must not emit man pages.
- tests.sphinx.test_sphinx_manpages.test_manpages_hook_empty_config_is_noop(tmp_path)[source]ΒΆ
An empty list leaves the build untouched.
- tests.sphinx.test_sphinx_manpages.test_manpages_hook_skips_entry_without_script(tmp_path)[source]ΒΆ
An entry missing
scriptis skipped (logged as a warning) instead of aborting the build.
- tests.sphinx.test_sphinx_manpages.test_manpages_module_help_documents_config_shape()[source]ΒΆ
The module docstring spells out every supported key.
A safety net against silent removal: distributors and downstream projects depend on the docstring as the canonical reference, since it is what
help(click_extra.sphinx.manpages)prints.
- tests.sphinx.test_sphinx_manpages.test_manpages_hook_emits_html_siblings(tmp_path)[source]ΒΆ
When a renderer is available, every
.1gets a.1.htmlnext to it whose body carries the section headings from the source roff.
- tests.sphinx.test_sphinx_manpages.test_manpages_hook_respects_render_html_opt_out(tmp_path)[source]ΒΆ
render_html=Falseskips the HTML pass even when a renderer is present, keeping the build to roff only.
- tests.sphinx.test_sphinx_manpages.test_manpages_directive_renders_one_link_per_command(tmp_path)[source]ΒΆ
The directive emits a bullet list with one entry per (sub)command of every script declared in
click_extra_manpages.
- tests.sphinx.test_sphinx_manpages.test_manpages_directive_links_follow_the_builder_layout(tmp_path, builder, page_file, prefix)[source]ΒΆ
Links resolve from wherever the builder publishes the page.
A second builder reusing pickled doctrees still gets its own layout.
Sphinx does not invalidate its doctree cache when the builder changes, so the directive never re-runs on the second pass. A link resolved at parse time would keep the first builderβs layout and point at nothing.
tests.sphinx.test_sphinx_python moduleΒΆ
Tests for the python:* Sphinx directive family.
Covers python:source, python:run, and the three render variants:
python:render(host parser)python:render-myst(forced MyST, regardless of host)python:render-rst(forced reST, regardless of host)
- tests.sphinx.test_sphinx_python.test_python_run_renders_stdout(sphinx_app_myst)[source]ΒΆ
python:runcapturesprintoutput and renders it in a code block.
- tests.sphinx.test_sphinx_python.test_python_source_seeds_namespace_for_python_run(sphinx_app_myst)[source]ΒΆ
python:sourceruns silently; a follow-uppython:runreuses its imports.
- tests.sphinx.test_sphinx_python.test_python_run_language_override(sphinx_app_myst)[source]ΒΆ
:language:overrides the defaulttextlexer for the result block.
- tests.sphinx.test_sphinx_python.test_python_run_emphasize_lines_split(sphinx_app_myst)[source]ΒΆ
:emphasize-lines:highlights source only;:emphasize-result-lines:highlights result only: independently, on the same block.
- tests.sphinx.test_sphinx_python.test_python_render_passes_block_level_html(sphinx_app_myst)[source]ΒΆ
python:renderpasses block-level raw HTML through unchanged.A naked
print('<div>...</div>')should reach the rendered page without any{raw} htmlwrapping. Locks down the natural-form pattern so a future MyST upgrade or extension reordering canβt silently regress it.
- tests.sphinx.test_sphinx_python.test_python_render_host_myst_injects_table(sphinx_app_myst)[source]ΒΆ
python:renderparses captured stdout with the host (MyST) parser.
- tests.sphinx.test_sphinx_python.test_python_render_host_myst_injects_heading(sphinx_app_myst)[source]ΒΆ
A heading printed by
python:renderbecomes a real heading node.
- tests.sphinx.test_sphinx_python.test_python_render_host_rst_injects_admonition(sphinx_app_rst)[source]ΒΆ
python:renderin an rST host: stdout is parsed as reST.
- tests.sphinx.test_sphinx_python.test_python_render_myst_in_rst_host(sphinx_app_rst)[source]ΒΆ
python:render-mystforces MyST parsing inside an rST host document.This is the headline use case: an rST file embeds Python that prints MyST markup and the directive parses it as MyST regardless of host.
- tests.sphinx.test_sphinx_python.test_python_render_rst_in_myst_host(sphinx_app_myst)[source]ΒΆ
python:render-rstforces reST parsing inside a MyST host document.
- tests.sphinx.test_sphinx_python.test_python_render_myst_in_myst_host_still_works(sphinx_app_myst)[source]ΒΆ
python:render-mystworks in MyST hosts too; it always picks MyST.
- tests.sphinx.test_sphinx_python.test_python_render_rst_in_rst_host_still_works(sphinx_app_rst)[source]ΒΆ
python:render-rstworks in rST hosts too; it always picks reST.
- tests.sphinx.test_sphinx_python.test_exec_directives_disabled_by_default(tmp_path)[source]ΒΆ
Without the opt-in flag,
click:*andpython:*are not registered.The Sphinx build still succeeds but neither familyβs directive body is ever executed. This is the desired security default: a project that adds
click_extra.sphinxto its extensions list does not silently gain build-time arbitrary Python execution.The exact rendering of an unrecognized directive is parser-dependent (MyST silently swallows it; reST emits a system message), so the assertion focuses on the security-relevant invariant: the directive bodyβs
printoutput never reaches the rendered HTML.
- tests.sphinx.test_sphinx_python.test_exec_directives_enabled_with_opt_in(tmp_path)[source]ΒΆ
Setting
click_extra_enable_exec_directives = Trueactivates them.
- tests.sphinx.test_sphinx_python.test_python_runner_isolated_from_click_runner(sphinx_app_myst)[source]ΒΆ
The Python and Click runners hold independent namespaces.
- tests.sphinx.test_sphinx_python.test_mirror_src_rewrite_inserts_region()[source]ΒΆ
A mirror-src comment with no region yet gets one, generator kept hidden.
- tests.sphinx.test_sphinx_python.test_mirror_src_rewrite_is_idempotent()[source]ΒΆ
Re-running over an already-filled mirror-src region is a no-op.
- tests.sphinx.test_sphinx_python.test_mirror_src_via_update_mirror_blocks(tmp_path)[source]ΒΆ
The offline refresher fills a mirror-src region, then round-trips clean.
- tests.sphinx.test_sphinx_python.test_mirror_src_rewrite_skips_example_nested_in_code_block()[source]ΒΆ
A mirror-src comment shown inside a longer code-block fence is never run.
- tests.sphinx.test_sphinx_python.test_mirror_rewrite_inserts_region()[source]ΒΆ
A mirror block with no region yet gets one inserted below the fence.
- tests.sphinx.test_sphinx_python.test_mirror_rewrite_is_idempotent()[source]ΒΆ
Re-running over an already-mirrored document is a no-op.
- tests.sphinx.test_sphinx_python.test_mirror_rewrite_replaces_stale_region()[source]ΒΆ
A stale region is refreshed from the blockβs current output.
- tests.sphinx.test_sphinx_python.test_mirror_rewrite_skips_example_nested_in_code_block()[source]ΒΆ
A mirror block shown inside a longer code-block fence is never executed.
- tests.sphinx.test_sphinx_python.test_python_render_mirror_renders_fresh_without_touching_source(sphinx_app_myst)[source]ΒΆ
:mirror:renders the table once; the build never writes to the source.
- tests.sphinx.test_sphinx_python.test_update_mirror_blocks_populates_and_idempotent(tmp_path)[source]ΒΆ
The offline refresher inserts the region, then round-trips clean.
- tests.sphinx.test_sphinx_python.test_update_mirror_blocks_check_mode(tmp_path)[source]ΒΆ
check=Truereports the stale file without writing it.
- tests.sphinx.test_sphinx_python.test_update_mirror_blocks_imports_sibling_module(tmp_path)[source]ΒΆ
A mirror block imports a helper module living next to the page.
Matches the Sphinx build, where the
conf.pydirectory is importable, so adocs_update.py-style generator module works offline too. The path entry is scoped to the execution and removed afterwards.