File: test_processing.py

package info (click to toggle)
mkdocs-click 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 300 kB
  • sloc: python: 715; sh: 17; makefile: 6
file content (85 lines) | stat: -rw-r--r-- 1,612 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# (C) Datadog, Inc. 2020-present
# All rights reserved
# Licensed under the Apache license (see LICENSE)
from mkdocs_click._processing import replace_blocks


def test_replace_options():
    """Replace a block with options."""

    source = """
# Some content
foo
::: target
    :option1: value1
    :optiøn2: val ue2
\t:option3:
    :option4:\x20
    :option5: 1
bar
""".strip()

    expected = """
# Some content
foo
{'option1': 'value1', 'optiøn2': 'val ue2', 'option3': '', 'option4': '', 'option5': '1'}
bar
""".strip()

    output = list(
        replace_blocks(
            source.splitlines(), title="target", replace=lambda **options: [str(options)]
        )
    )
    assert output == expected.splitlines()


def test_replace_no_options():
    """Replace a block that has no options."""

    source = """
# Some content
foo
::: target
bar
""".strip()

    expected = """
# Some content
foo
> mock
bar
""".strip()

    output = list(
        replace_blocks(source.splitlines(), title="target", replace=lambda **options: ["> mock"])
    )
    assert output == expected.splitlines()


def test_other_blocks_unchanged():
    """Blocks other than the target block are left unchanged."""

    source = """
# Some content
::: target
::: plugin1
    :option1: value1
::: target
    :option: value
::: plugin2
    :option2: value2
bar
""".strip()

    expected = """
# Some content
::: plugin1
    :option1: value1
::: plugin2
    :option2: value2
bar
""".strip()

    output = list(replace_blocks(source.splitlines(), title="target", replace=lambda **kwargs: []))
    assert output == expected.splitlines()