-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathinline_syntax_highlight_test.py
More file actions
70 lines (47 loc) · 1.35 KB
/
inline_syntax_highlight_test.py
File metadata and controls
70 lines (47 loc) · 1.35 KB
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
"""Tests related to theme's syntax highlighting
(default-literal inline and code-block)."""
import pytest
from sphinx.testing.util import SphinxTestApp
rst_prologue = """.. role:: python(code)
:language: python
:class: highlight
"""
default_literal_rst = """
The Test
========
Normal literal role: ``1 + 2``
.. default-literal-role:: python
Python literal role: ``1 + 2``
.. default-literal-role::
Normal literal role again: ``1 + 2``
"""
highlight_push_pop = """
The Test
========
.. highlight-push::
.. highlight:: json
The following literal block will be highlighted as JSON::
{"a": 10, "b": null, "c": 10}
.. highlight-push::
.. highlight:: python
The following block will be highlighted as Python::
def foo(x: int) -> None: ...
.. highlight-pop::
The following block will be highlighted as JSON::
[1, 2, true, false]
"""
@pytest.mark.parametrize(
"doc",
[
"\n".join([rst_prologue, default_literal_rst]),
pytest.param(default_literal_rst, marks=pytest.mark.xfail),
highlight_push_pop,
],
ids=["default_literal", "default_literal_warning", "highlight_push_pop"],
)
def test_syntax_highlighting(doc: str, immaterial_make_app):
app: SphinxTestApp = immaterial_make_app(
files={"index.rst": doc},
)
app.build()
assert not app._warning.getvalue() # type: ignore[attr-defined]