2018-01-09 07:21:49 -06:00
|
|
|
|
"""
|
|
|
|
|
test_smartquotes
|
|
|
|
|
~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Test smart quotes.
|
|
|
|
|
|
2022-01-01 03:45:03 -06:00
|
|
|
|
:copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS.
|
2018-01-09 07:21:49 -06:00
|
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import pytest
|
2021-08-20 03:38:30 -05:00
|
|
|
|
from html5lib import HTMLParser
|
2018-02-19 07:39:14 -06:00
|
|
|
|
|
2022-01-02 11:01:44 -06:00
|
|
|
|
from sphinx.util import docutils
|
|
|
|
|
|
2018-01-09 07:21:49 -06:00
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx(buildername='html', testroot='smartquotes', freshenv=True)
|
|
|
|
|
def test_basic(app, status, warning):
|
|
|
|
|
app.build()
|
|
|
|
|
|
2020-01-31 20:58:51 -06:00
|
|
|
|
content = (app.outdir / 'index.html').read_text()
|
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
|
|
|
|
|
|
|
|
|
|
2021-08-20 03:38:30 -05:00
|
|
|
|
@pytest.mark.sphinx(buildername='html', testroot='smartquotes', freshenv=True)
|
|
|
|
|
def test_literals(app, status, warning):
|
|
|
|
|
app.build()
|
|
|
|
|
|
|
|
|
|
with (app.outdir / 'literals.html').open() as html_file:
|
|
|
|
|
etree = HTMLParser(namespaceHTMLElements=False).parse(html_file)
|
|
|
|
|
|
|
|
|
|
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'"
|
|
|
|
|
|
|
|
|
|
|
2018-01-09 07:21:49 -06:00
|
|
|
|
@pytest.mark.sphinx(buildername='text', testroot='smartquotes', freshenv=True)
|
|
|
|
|
def test_text_builder(app, status, warning):
|
|
|
|
|
app.build()
|
|
|
|
|
|
2020-01-31 20:58:51 -06:00
|
|
|
|
content = (app.outdir / 'index.txt').read_text()
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx(buildername='man', testroot='smartquotes', freshenv=True)
|
|
|
|
|
def test_man_builder(app, status, warning):
|
|
|
|
|
app.build()
|
|
|
|
|
|
2021-05-15 08:17:20 -05:00
|
|
|
|
content = (app.outdir / 'python.1').read_text()
|
2022-01-02 11:01:44 -06:00
|
|
|
|
if docutils.__version_info__ > (0, 18):
|
|
|
|
|
assert r'\-\- \(dqSphinx\(dq is a tool that makes it easy ...' in content
|
|
|
|
|
else:
|
|
|
|
|
assert r'\-\- "Sphinx" is a tool that makes it easy ...' in content
|
2018-01-09 07:21:49 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx(buildername='latex', testroot='smartquotes', freshenv=True)
|
|
|
|
|
def test_latex_builder(app, status, warning):
|
|
|
|
|
app.build()
|
|
|
|
|
|
2020-01-31 20:58:51 -06:00
|
|
|
|
content = (app.outdir / 'python.tex').read_text()
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx(buildername='html', testroot='smartquotes', freshenv=True,
|
|
|
|
|
confoverrides={'language': 'ja'})
|
|
|
|
|
def test_ja_html_builder(app, status, warning):
|
|
|
|
|
app.build()
|
|
|
|
|
|
2020-01-31 20:58:51 -06:00
|
|
|
|
content = (app.outdir / 'index.html').read_text()
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx(buildername='html', testroot='smartquotes', freshenv=True,
|
|
|
|
|
confoverrides={'smartquotes': False})
|
|
|
|
|
def test_smartquotes_disabled(app, status, warning):
|
|
|
|
|
app.build()
|
|
|
|
|
|
2020-01-31 20:58:51 -06:00
|
|
|
|
content = (app.outdir / 'index.html').read_text()
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx(buildername='html', testroot='smartquotes', freshenv=True,
|
|
|
|
|
confoverrides={'smartquotes_action': 'q'})
|
|
|
|
|
def test_smartquotes_action(app, status, warning):
|
|
|
|
|
app.build()
|
|
|
|
|
|
2020-01-31 20:58:51 -06:00
|
|
|
|
content = (app.outdir / 'index.html').read_text()
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx(buildername='html', testroot='smartquotes', freshenv=True,
|
|
|
|
|
confoverrides={'language': 'ja', 'smartquotes_excludes': {}})
|
|
|
|
|
def test_smartquotes_excludes_language(app, status, warning):
|
|
|
|
|
app.build()
|
|
|
|
|
|
2020-01-31 20:58:51 -06:00
|
|
|
|
content = (app.outdir / 'index.html').read_text()
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx(buildername='man', testroot='smartquotes', freshenv=True,
|
|
|
|
|
confoverrides={'smartquotes_excludes': {}})
|
|
|
|
|
def test_smartquotes_excludes_builders(app, status, warning):
|
|
|
|
|
app.build()
|
|
|
|
|
|
2021-05-15 08:17:20 -05:00
|
|
|
|
content = (app.outdir / 'python.1').read_text()
|
2018-12-15 08:02:28 -06:00
|
|
|
|
assert '– “Sphinx” is a tool that makes it easy …' in content
|