summaryrefslogtreecommitdiff
path: root/tests/test_intl.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_intl.py')
-rw-r--r--tests/test_intl.py61
1 files changed, 56 insertions, 5 deletions
diff --git a/tests/test_intl.py b/tests/test_intl.py
index 73d94166e..3b54063ef 100644
--- a/tests/test_intl.py
+++ b/tests/test_intl.py
@@ -12,6 +12,7 @@
import os
import re
+import pygments
import pytest
from babel.messages import mofile, pofile
from babel.messages.catalog import Catalog
@@ -30,6 +31,8 @@ sphinx_intl = pytest.mark.sphinx(
},
)
+pygments_version = tuple(int(v) for v in pygments.__version__.split('.'))
+
def read_po(pathname):
with pathname.open() as f:
@@ -622,7 +625,7 @@ def test_html_meta(app):
assert expected_expr in result
expected_expr = '<meta content="I18N, SPHINX, MARKUP" name="keywords" />'
assert expected_expr in result
- expected_expr = '<p class="caption"><span class="caption-text">HIDDEN TOC</span></p>'
+ expected_expr = '<p class="caption" role="heading"><span class="caption-text">HIDDEN TOC</span></p>'
assert expected_expr in result
@@ -1060,8 +1063,13 @@ def test_additional_targets_should_not_be_translated(app):
assert_count(expected_expr, result, 1)
# C code block with lang should not be translated but be *C* highlighted
- expected_expr = ("""<span class="cp">#include</span> """
- """<span class="cpf">&lt;stdio.h&gt;</span>""")
+ if pygments_version < (2, 10, 0):
+ expected_expr = ("""<span class="cp">#include</span> """
+ """<span class="cpf">&lt;stdio.h&gt;</span>""")
+ else:
+ expected_expr = ("""<span class="cp">#include</span>"""
+ """<span class="w"> </span>"""
+ """<span class="cpf">&lt;stdio.h&gt;</span>""")
assert_count(expected_expr, result, 1)
# literal block in list item should not be translated
@@ -1138,8 +1146,13 @@ def test_additional_targets_should_be_translated(app):
assert_count(expected_expr, result, 1)
# C code block with lang should be translated and be *C* highlighted
- expected_expr = ("""<span class="cp">#include</span> """
- """<span class="cpf">&lt;STDIO.H&gt;</span>""")
+ if pygments_version < (2, 10, 0):
+ expected_expr = ("""<span class="cp">#include</span> """
+ """<span class="cpf">&lt;STDIO.H&gt;</span>""")
+ else:
+ expected_expr = ("""<span class="cp">#include</span>"""
+ """<span class="w"> </span>"""
+ """<span class="cpf">&lt;STDIO.H&gt;</span>""")
assert_count(expected_expr, result, 1)
# literal block in list item should be translated
@@ -1288,6 +1301,44 @@ def getwarning(warnings):
return strip_escseq(warnings.getvalue().replace(os.sep, '/'))
+@pytest.mark.sphinx('html', testroot='basic',
+ srcdir='gettext_allow_fuzzy_translations',
+ confoverrides={
+ 'language': 'de',
+ 'gettext_allow_fuzzy_translations': True
+ })
+def test_gettext_allow_fuzzy_translations(app):
+ locale_dir = app.srcdir / 'locales' / 'de' / 'LC_MESSAGES'
+ locale_dir.makedirs()
+ with (locale_dir / 'index.po').open('wb') as f:
+ catalog = Catalog()
+ catalog.add('features', 'FEATURES', flags=('fuzzy',))
+ pofile.write_po(f, catalog)
+
+ app.build()
+ content = (app.outdir / 'index.html').read_text()
+ assert 'FEATURES' in content
+
+
+@pytest.mark.sphinx('html', testroot='basic',
+ srcdir='gettext_disallow_fuzzy_translations',
+ confoverrides={
+ 'language': 'de',
+ 'gettext_allow_fuzzy_translations': False
+ })
+def test_gettext_disallow_fuzzy_translations(app):
+ locale_dir = app.srcdir / 'locales' / 'de' / 'LC_MESSAGES'
+ locale_dir.makedirs()
+ with (locale_dir / 'index.po').open('wb') as f:
+ catalog = Catalog()
+ catalog.add('features', 'FEATURES', flags=('fuzzy',))
+ pofile.write_po(f, catalog)
+
+ app.build()
+ content = (app.outdir / 'index.html').read_text()
+ assert 'FEATURES' not in content
+
+
@pytest.mark.sphinx('html', testroot='basic', confoverrides={'language': 'de'})
def test_customize_system_message(make_app, app_params, sphinx_test_tempdir):
try: