File: test_smartquotes.py

package info (click to toggle)
sphinx 9.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 28,732 kB
  • sloc: python: 109,394; javascript: 37,318; perl: 449; makefile: 183; sh: 37; xml: 19; ansic: 2
file content (171 lines) | stat: -rw-r--r-- 4,553 bytes parent folder | download | duplicates (10)
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
"""Test smart quotes."""

from __future__ import annotations

from typing import TYPE_CHECKING

import pytest

from sphinx.testing.util import etree_parse

if TYPE_CHECKING:
    from sphinx.testing.util import SphinxTestApp


@pytest.mark.sphinx(
    'html',
    testroot='smartquotes',
    freshenv=True,
)
def test_basic(app: SphinxTestApp) -> None:
    app.build()

    content = (app.outdir / 'index.html').read_text(encoding='utf8')
    assert '<p>– “Sphinx” is a tool that makes it easy …</p>' in content


@pytest.mark.sphinx(
    'html',
    testroot='smartquotes',
    freshenv=True,
)
def test_literals(app: SphinxTestApp) -> None:
    app.build()

    etree = etree_parse(app.outdir / 'literals.html')
    for code_element in etree.iter('code'):
        code_text = ''.join(code_element.itertext())

        if code_text.startswith('code role'):
            assert "'quotes'" in code_text
        elif code_text.startswith('{'):
            assert code_text == "{'code': 'role', 'with': 'quotes'}"
        elif code_text.startswith('literal'):
            assert code_text == "literal with 'quotes'"


@pytest.mark.sphinx(
    'text',
    testroot='smartquotes',
    freshenv=True,
)
def test_text_builder(app: SphinxTestApp) -> None:
    app.build()

    content = (app.outdir / 'index.txt').read_text(encoding='utf8')
    assert '-- "Sphinx" is a tool that makes it easy ...' in content


@pytest.mark.sphinx(
    'man',
    testroot='smartquotes',
    freshenv=True,
)
def test_man_builder(app: SphinxTestApp) -> None:
    app.build()

    content = (app.outdir / 'projectnamenotset.1').read_text(encoding='utf8')
    assert r'\-\- \(dqSphinx\(dq is a tool that makes it easy ...' in content


@pytest.mark.sphinx(
    'latex',
    testroot='smartquotes',
    freshenv=True,
)
def test_latex_builder(app: SphinxTestApp) -> None:
    app.build()

    content = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
    assert '\\textendash{} “Sphinx” is a tool that makes it easy …' in content


@pytest.mark.sphinx(
    'html',
    testroot='smartquotes',
    freshenv=True,
    confoverrides={'language': 'ja'},
)
def test_ja_html_builder(app: SphinxTestApp) -> None:
    app.build()

    content = (app.outdir / 'index.html').read_text(encoding='utf8')
    assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content


@pytest.mark.sphinx(
    'html',
    testroot='smartquotes',
    freshenv=True,
    confoverrides={'language': 'zh_CN'},
)
def test_zh_cn_html_builder(app: SphinxTestApp) -> None:
    app.build()

    content = (app.outdir / 'index.html').read_text(encoding='utf8')
    assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content


@pytest.mark.sphinx(
    'html',
    testroot='smartquotes',
    freshenv=True,
    confoverrides={'language': 'zh_TW'},
)
def test_zh_tw_html_builder(app: SphinxTestApp) -> None:
    app.build()

    content = (app.outdir / 'index.html').read_text(encoding='utf8')
    assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content


@pytest.mark.sphinx(
    'html',
    testroot='smartquotes',
    freshenv=True,
    confoverrides={'smartquotes': False},
)
def test_smartquotes_disabled(app: SphinxTestApp) -> None:
    app.build()

    content = (app.outdir / 'index.html').read_text(encoding='utf8')
    assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content


@pytest.mark.sphinx(
    'html',
    testroot='smartquotes',
    freshenv=True,
    confoverrides={'smartquotes_action': 'q'},
)
def test_smartquotes_action(app: SphinxTestApp) -> None:
    app.build()

    content = (app.outdir / 'index.html').read_text(encoding='utf8')
    assert '<p>-- “Sphinx” is a tool that makes it easy ...</p>' in content


@pytest.mark.sphinx(
    'html',
    testroot='smartquotes',
    freshenv=True,
    confoverrides={'language': 'ja', 'smartquotes_excludes': {}},
)
def test_smartquotes_excludes_language(app: SphinxTestApp) -> None:
    app.build()

    content = (app.outdir / 'index.html').read_text(encoding='utf8')
    assert '<p>– 「Sphinx」 is a tool that makes it easy …</p>' in content


@pytest.mark.sphinx(
    'man',
    testroot='smartquotes',
    freshenv=True,
    confoverrides={'smartquotes_excludes': {}},
)
def test_smartquotes_excludes_builders(app: SphinxTestApp) -> None:
    app.build()

    content = (app.outdir / 'projectnamenotset.1').read_text(encoding='utf8')
    assert '– “Sphinx” is a tool that makes it easy …' in content