nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 41 lines 1.5 kB view raw
1import json 2from pathlib import Path 3import pytest 4from markdown_it.token import Token 5 6import nixos_render_docs 7from nixos_render_docs.options import AnchorStyle 8 9def test_option_headings() -> None: 10 c = nixos_render_docs.options.HTMLConverter({}, 'local', 'vars', 'opt-', {}) 11 with pytest.raises(RuntimeError) as exc: 12 c._render("# foo") 13 assert exc.value.args[0] == 'md token not supported in options doc' 14 assert exc.value.args[1] == Token( 15 type='heading_open', tag='h1', nesting=1, attrs={}, map=[0, 1], level=0, children=None, 16 content='', markup='#', info='', meta={}, block=True, hidden=False 17 ) 18 19def test_options_commonmark() -> None: 20 c = nixos_render_docs.options.CommonMarkConverter({}, 'local') 21 with Path('tests/sample_options_simple.json').open() as f: 22 opts = json.load(f) 23 assert opts is not None 24 with Path('tests/sample_options_simple_default.md').open() as f: 25 expected = f.read() 26 27 c.add_options(opts) 28 s = c.finalize() 29 assert s == expected 30 31def test_options_commonmark_legacy_anchors() -> None: 32 c = nixos_render_docs.options.CommonMarkConverter({}, 'local', anchor_style = AnchorStyle.LEGACY, anchor_prefix = 'opt-') 33 with Path('tests/sample_options_simple.json').open() as f: 34 opts = json.load(f) 35 assert opts is not None 36 with Path('tests/sample_options_simple_legacy.md').open() as f: 37 expected = f.read() 38 39 c.add_options(opts) 40 s = c.finalize() 41 assert s == expected