File: test_sphinx_prompt.py

package info (click to toggle)
sphinx-prompt 1.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 244 kB
  • sloc: python: 242; makefile: 22; sh: 19
file content (173 lines) | stat: -rw-r--r-- 4,941 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from io import StringIO

import docutils.statemachine
import docutils.utils
import pytest

sphinx_prompt = __import__("sphinx_prompt")

testdata = [
    [
        [],
        {},
        ["one line"],
        """<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: " ";
}
</style><span class="prompt1">one line</span>
</pre></div></div>""",
    ],
    [
        ["bash"],
        {},
        ["one line"],
        """<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "$ ";
}
</style><span class="prompt1">one<span class="w"> </span>line</span>
</pre></div></div>""",
    ],
    [
        [],
        {"language": "bash"},
        ["one line"],
        """<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "$ ";
}
</style><span class="prompt1">one<span class="w"> </span>line</span>
</pre></div></div>""",
    ],
    [
        ["bash"],
        {},
        ["tow", "line"],
        """<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "$ ";
}
</style><span class="prompt1">tow</span>
<span class="prompt1">line</span>
</pre></div></div>""",
    ],
    [
        ["bash"],
        {},
        ["one split \\", "line"],
        """<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "$ ";
}
</style><span class="prompt1">one<span class="w"> </span>split<span class="w"> </span><span class="se">\\</span>
line</span>
</pre></div></div>""",
    ],
    [
        ["bash"],
        {},
        ["mixed split \\", "line", "second"],
        """<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "$ ";
}
</style><span class="prompt1">mixed<span class="w"> </span>split<span class="w"> </span><span class="se">\\</span>
line</span>
<span class="prompt1">second</span>
</pre></div></div>""",
    ],
    [
        ["bash", "%"],
        {},
        ["other prompt"],
        """<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "% ";
}
</style><span class="prompt1">other<span class="w"> </span>prompt</span>
</pre></div></div>""",
    ],
    [
        [],
        {"language": "bash", "prompts": "%"},
        ["other prompt opt"],
        """<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "% ";
}
</style><span class="prompt1">other<span class="w"> </span>prompt<span class="w"> </span>opt</span>
</pre></div></div>""",
    ],
    [
        ["batch"],
        {},
        ["batch"],
        """<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "C:\\\\> ";
}
</style><span class="prompt1">batch</span>
</pre></div></div>""",
    ],
    [
        ["powershell"],
        {},
        ["powershell"],
        """<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "PS C:\\\\> ";
}
</style><span class="prompt1"><span class="n">powershell</span></span>
</pre></div></div>""",
    ],
    [
        ["bash"],
        {},
        ['lexer 1 2 "tree"'],
        """<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "$ ";
}
</style><span class="prompt1">lexer<span class="w"> </span><span class="m">1</span><span class="w"> </span><span class="m">2</span><span class="w"> </span><span class="s2">&quot;tree&quot;</span></span>
</pre></div></div>""",
    ],
    [
        ["bash", "$,#", "auto"],
        {},
        ["$ user", "# root"],
        """<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "$ ";
}
span.prompt2:before {
  content: "# ";
}
</style><span class="prompt1">user</span>
<span class="prompt2">root</span>
</pre></div></div>""",
    ],
]


@pytest.mark.parametrize(("arguments", "options", "content", "expected"), testdata)
def test(arguments, options, content, expected):
    sphinx_prompt._cache.next_index = 1
    sphinx_prompt._cache.prompts.clear()
    stream = StringIO()
    reporter = docutils.utils.Reporter("test data", 2, 4, stream, 1)
    statemachine = docutils.statemachine.StateMachine([], None)
    statemachine.reporter = reporter
    directive = sphinx_prompt.PromptDirective(
        "prompt",
        arguments,
        options,
        content,
        0,
        0,
        "",
        None,
        statemachine,
    )
    result = directive.run()
    assert result[0].astext() == expected