sphinx/tests/test_markup/test_smartquotes.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

167 lines
4.1 KiB
Python
Raw Normal View History

2018-01-09 07:21:49 -06:00
"""Test smart quotes."""
from __future__ import annotations
2018-01-09 07:21:49 -06:00
import pytest
from sphinx.testing.util import etree_parse
2018-02-19 07:39:14 -06:00
2018-01-09 07:21:49 -06:00
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'html',
testroot='smartquotes',
freshenv=True,
)
def test_basic(app):
2018-01-09 07:21:49 -06:00
app.build()
content = (app.outdir / 'index.html').read_text(encoding='utf8')
2018-12-15 08:02:28 -06:00
assert '<p> “Sphinx” is a tool that makes it easy …</p>' in content
2018-01-09 07:21:49 -06:00
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'html',
testroot='smartquotes',
freshenv=True,
)
def test_literals(app):
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'"
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'text',
testroot='smartquotes',
freshenv=True,
)
def test_text_builder(app):
2018-01-09 07:21:49 -06:00
app.build()
content = (app.outdir / 'index.txt').read_text(encoding='utf8')
2018-12-15 08:02:28 -06:00
assert '-- "Sphinx" is a tool that makes it easy ...' in content
2018-01-09 07:21:49 -06:00
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'man',
testroot='smartquotes',
freshenv=True,
)
def test_man_builder(app):
2018-01-09 07:21:49 -06:00
app.build()
content = (app.outdir / 'projectnamenotset.1').read_text(encoding='utf8')
2022-05-22 15:09:39 -05:00
assert r'\-\- \(dqSphinx\(dq is a tool that makes it easy ...' in content
2018-01-09 07:21:49 -06:00
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='smartquotes',
freshenv=True,
)
def test_latex_builder(app):
2018-01-09 07:21:49 -06:00
app.build()
content = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2018-12-15 08:02:28 -06:00
assert '\\textendash{} “Sphinx” is a tool that makes it easy …' in content
2018-01-09 07:21:49 -06:00
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'html',
testroot='smartquotes',
freshenv=True,
confoverrides={'language': 'ja'},
)
def test_ja_html_builder(app):
2018-01-09 07:21:49 -06:00
app.build()
content = (app.outdir / 'index.html').read_text(encoding='utf8')
2018-12-15 08:02:28 -06:00
assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content
2018-01-09 07:21:49 -06:00
@pytest.mark.sphinx(
'html',
testroot='smartquotes',
freshenv=True,
confoverrides={'language': 'zh_CN'},
)
def test_zh_cn_html_builder(app):
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):
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
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'html',
testroot='smartquotes',
freshenv=True,
confoverrides={'smartquotes': False},
)
def test_smartquotes_disabled(app):
2018-01-09 07:21:49 -06:00
app.build()
content = (app.outdir / 'index.html').read_text(encoding='utf8')
2018-12-15 08:02:28 -06:00
assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content
2018-01-09 07:21:49 -06:00
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'html',
testroot='smartquotes',
freshenv=True,
confoverrides={'smartquotes_action': 'q'},
)
def test_smartquotes_action(app):
2018-01-09 07:21:49 -06:00
app.build()
content = (app.outdir / 'index.html').read_text(encoding='utf8')
2018-12-15 08:02:28 -06:00
assert '<p>-- “Sphinx” is a tool that makes it easy ...</p>' in content
2018-01-09 07:21:49 -06:00
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'html',
testroot='smartquotes',
freshenv=True,
confoverrides={'language': 'ja', 'smartquotes_excludes': {}},
)
def test_smartquotes_excludes_language(app):
2018-01-09 07:21:49 -06:00
app.build()
content = (app.outdir / 'index.html').read_text(encoding='utf8')
2018-12-15 08:02:28 -06:00
assert '<p> 「Sphinx」 is a tool that makes it easy …</p>' in content
2018-01-09 07:21:49 -06:00
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'man',
testroot='smartquotes',
freshenv=True,
confoverrides={'smartquotes_excludes': {}},
)
def test_smartquotes_excludes_builders(app):
2018-01-09 07:21:49 -06:00
app.build()
content = (app.outdir / 'projectnamenotset.1').read_text(encoding='utf8')
2018-12-15 08:02:28 -06:00
assert ' “Sphinx” is a tool that makes it easy …' in content