Debian Codegraph @

tests/test_markup/test_smartquotes.py

raw
1 """Test smart quotes."""
2
3 from __future__ import annotations
4
5 from typing import TYPE_CHECKING
6
7 import pytest
8
9 from sphinx.testing.util import etree_parse
10
11 if TYPE_CHECKING:
12 from sphinx.testing.util import SphinxTestApp
13
14
15 @pytest.mark.sphinx(
16 'html',
17 testroot='smartquotes',
18 freshenv=True,
19 )
20 def test_basic(app: SphinxTestApp) -> None:
21 app.build()
22
23 content = (app.outdir / 'index.html').read_text(encoding='utf8')
24 assert '<p>– “Sphinx” is a tool that makes it easy …</p>' in content
25
26
27 @pytest.mark.sphinx(
28 'html',
29 testroot='smartquotes',
30 freshenv=True,
31 )
32 def test_literals(app: SphinxTestApp) -> None:
33 app.build()
34
35 etree = etree_parse(app.outdir / 'literals.html')
36 for code_element in etree.iter('code'):
37 code_text = ''.join(code_element.itertext())
38
39 if code_text.startswith('code role'):
40 assert "'quotes'" in code_text
41 elif code_text.startswith('{'):
42 assert code_text == "{'code': 'role', 'with': 'quotes'}"
43 elif code_text.startswith('literal'):
44 assert code_text == "literal with 'quotes'"
45
46
47 @pytest.mark.sphinx(
48 'text',
49 testroot='smartquotes',
50 freshenv=True,
51 )
52 def test_text_builder(app: SphinxTestApp) -> None:
53 app.build()
54
55 content = (app.outdir / 'index.txt').read_text(encoding='utf8')
56 assert '-- "Sphinx" is a tool that makes it easy ...' in content
57
58
59 @pytest.mark.sphinx(
60 'man',
61 testroot='smartquotes',
62 freshenv=True,
63 )
64 def test_man_builder(app: SphinxTestApp) -> None:
65 app.build()
66
67 content = (app.outdir / 'projectnamenotset.1').read_text(encoding='utf8')
68 assert r'\-\- \(dqSphinx\(dq is a tool that makes it easy ...' in content
69
70
71 @pytest.mark.sphinx(
72 'latex',
73 testroot='smartquotes',
74 freshenv=True,
75 )
76 def test_latex_builder(app: SphinxTestApp) -> None:
77 app.build()
78
79 content = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
80 assert '\\textendash{} “Sphinx” is a tool that makes it easy …' in content
81
82
83 @pytest.mark.sphinx(
84 'html',
85 testroot='smartquotes',
86 freshenv=True,
87 confoverrides={'language': 'ja'},
88 )
89 def test_ja_html_builder(app: SphinxTestApp) -> None:
90 app.build()
91
92 content = (app.outdir / 'index.html').read_text(encoding='utf8')
93 assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content
94
95
96 @pytest.mark.sphinx(
97 'html',
98 testroot='smartquotes',
99 freshenv=True,
100 confoverrides={'language': 'zh_CN'},
101 )
102 def test_zh_cn_html_builder(app: SphinxTestApp) -> None:
103 app.build()
104
105 content = (app.outdir / 'index.html').read_text(encoding='utf8')
106 assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content
107
108
109 @pytest.mark.sphinx(
110 'html',
111 testroot='smartquotes',
112 freshenv=True,
113 confoverrides={'language': 'zh_TW'},
114 )
115 def test_zh_tw_html_builder(app: SphinxTestApp) -> None:
116 app.build()
117
118 content = (app.outdir / 'index.html').read_text(encoding='utf8')
119 assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content
120
121
122 @pytest.mark.sphinx(
123 'html',
124 testroot='smartquotes',
125 freshenv=True,
126 confoverrides={'smartquotes': False},
127 )
128 def test_smartquotes_disabled(app: SphinxTestApp) -> None:
129 app.build()
130
131 content = (app.outdir / 'index.html').read_text(encoding='utf8')
132 assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content
133
134
135 @pytest.mark.sphinx(
136 'html',
137 testroot='smartquotes',
138 freshenv=True,
139 confoverrides={'smartquotes_action': 'q'},
140 )
141 def test_smartquotes_action(app: SphinxTestApp) -> None:
142 app.build()
143
144 content = (app.outdir / 'index.html').read_text(encoding='utf8')
145 assert '<p>-- “Sphinx” is a tool that makes it easy ...</p>' in content
146
147
148 @pytest.mark.sphinx(
149 'html',
150 testroot='smartquotes',
151 freshenv=True,
152 confoverrides={'language': 'ja', 'smartquotes_excludes': {}},
153 )
154 def test_smartquotes_excludes_language(app: SphinxTestApp) -> None:
155 app.build()
156
157 content = (app.outdir / 'index.html').read_text(encoding='utf8')
158 assert '<p>– 「Sphinx」 is a tool that makes it easy …</p>' in content
159
160
161 @pytest.mark.sphinx(
162 'man',
163 testroot='smartquotes',
164 freshenv=True,
165 confoverrides={'smartquotes_excludes': {}},
166 )
167 def test_smartquotes_excludes_builders(app: SphinxTestApp) -> None:
168 app.build()
169
170 content = (app.outdir / 'projectnamenotset.1').read_text(encoding='utf8')
171 assert '– “Sphinx” is a tool that makes it easy …' in content