tests.mkdocs package¶

Submodules¶

tests.mkdocs.conftest module¶

Fixtures and helpers for MkDocs tests.

Separated from the root tests/conftest.py so that the MkDocs dependency (and mkdocs-click, pymdown-extensions) is only imported when running the tests in this subdirectory. Downstream packagers can skip these tests with --ignore=tests/mkdocs without affecting the rest of the test suite.

tests.mkdocs.test_mkdocs module¶

Tests for the MkDocs ANSI color plugin.

tests.mkdocs.test_mkdocs.test_mkdocs_entry_point()[source]¶

Verify the mkdocs.plugins entry point is declared in pyproject.toml.

tests.mkdocs.test_mkdocs.test_on_config_patches_formatters()[source]¶

After on_config, both formatter classes inherit from AnsiHtmlFormatter.

tests.mkdocs.test_mkdocs.test_on_config_idempotent()[source]¶

Calling on_config twice does not create a new class each time.

tests.mkdocs.test_mkdocs.test_patched_formatter_preserves_pymdownx_mro()[source]¶

The patched formatters still inherit from the original pymdownx classes.

tests.mkdocs.test_mkdocs.test_patched_formatter_renders_ansi()[source]¶

The patched block formatter decomposes compound ANSI tokens into CSS classes.

tests.mkdocs.test_mkdocs.test_ansi_stylesheet_only_contains_ansi_rules()[source]¶

The generated stylesheet colors the -Ansi-* classes and nothing else.

Standard Pygments token rules must stay out: dumping the full style would override the theme’s own syntax-highlighting colors for every code block.

tests.mkdocs.test_mkdocs.test_on_config_registers_stylesheet()[source]¶

on_config appends the ANSI stylesheet to extra_css exactly once.

tests.mkdocs.test_mkdocs.test_on_post_build_writes_stylesheet(tmp_path)[source]¶

on_post_build writes the ANSI stylesheet under the site directory.

tests.mkdocs.test_mkdocs.test_patch_mkdocs_click_usage()[source]¶

After patching, _make_usage yields ansi-output fences.

tests.mkdocs.test_mkdocs.test_patch_mkdocs_click_plain_options()[source]¶

After patching, _make_plain_options yields ansi-output fences.

tests.mkdocs.test_mkdocs.test_patch_mkdocs_click_idempotent()[source]¶

Calling _patch_mkdocs_click twice does not double-wrap.

tests.mkdocs.test_mkdocs.test_patch_mkdocs_click_forces_color_during_capture(monkeypatch)[source]¶

The patched generators capture help with color forced, even under NO_COLOR.

Swapping the lexer to ansi-output is pointless if the captured help carries no escape codes, which is exactly what happens when the build’s stdout is a pipe. The wrapper must therefore materialize the help while the color override is active. Spying on make_formatter (where Rich and Click read the environment to decide on color) proves FORCE_COLOR is set and the disabling vars are cleared at capture time, and that the surrounding environment is restored once the capture completes.

tests.mkdocs.test_mkdocs.test_on_config_patches_mkdocs_click()[source]¶

on_config patches mkdocs-click alongside pymdownx.highlight.

tests.mkdocs.test_mkdocs.test_full_build_renders_ansi_colors(tmp_path)[source]¶

An end-to-end MkDocs build strips escape codes and ships the color stylesheet.

This exercises the whole plugin wiring (formatter patch plus stylesheet injection) the way bump-my-version’s site does: an ansi-output block goes in, and class-decorated spans backed by a linked stylesheet come out, with no raw escape codes left behind.