summaryrefslogtreecommitdiff
path: root/tests/test_build_gettext.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_build_gettext.py')
-rw-r--r--tests/test_build_gettext.py107
1 files changed, 61 insertions, 46 deletions
diff --git a/tests/test_build_gettext.py b/tests/test_build_gettext.py
index 9bde44b5..677f3505 100644
--- a/tests/test_build_gettext.py
+++ b/tests/test_build_gettext.py
@@ -8,47 +8,32 @@
:copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
+from __future__ import print_function
-import gettext
import os
import re
+import gettext
from subprocess import Popen, PIPE
-from util import test_root, test_roots, with_app, SkipTest
-
+from nose.tools import assert_true, assert_equal
-def teardown_module():
- (test_root / '_build').rmtree(True)
- (test_roots / 'test-intl' / '_build').rmtree(True),
+from util import with_app, gen_with_app, SkipTest, assert_in
-@with_app(buildername='gettext')
-def test_all(app):
+@gen_with_app('gettext', srcdir='root-gettext')
+def test_all(app, status, warning):
# Generic build; should fail only when the builder is horribly broken.
app.builder.build_all()
-
-@with_app(buildername='gettext')
-def test_build(app):
# Do messages end up in the correct location?
- app.builder.build(['extapi', 'subdir/includes'])
# top-level documents end up in a message catalog
- assert (app.outdir / 'extapi.pot').isfile()
+ yield assert_true, (app.outdir / 'extapi.pot').isfile()
# directory items are grouped into sections
- assert (app.outdir / 'subdir.pot').isfile()
-
+ yield assert_true, (app.outdir / 'subdir.pot').isfile()
-@with_app(buildername='gettext')
-def test_seealso(app):
# regression test for issue #960
- app.builder.build(['markup'])
catalog = (app.outdir / 'markup.pot').text(encoding='utf-8')
- assert 'msgid "something, something else, something more"' in catalog
-
-
-@with_app(buildername='gettext')
-def test_gettext(app):
- app.builder.build(['markup'])
+ yield assert_in, 'msgid "something, something else, something more"', catalog
(app.outdir / 'en' / 'LC_MESSAGES').makedirs()
cwd = os.getcwd()
@@ -57,48 +42,48 @@ def test_gettext(app):
try:
p = Popen(['msginit', '--no-translator', '-i', 'markup.pot',
'--locale', 'en_US'],
- stdout=PIPE, stderr=PIPE)
+ stdout=PIPE, stderr=PIPE)
except OSError:
raise SkipTest # most likely msginit was not found
else:
stdout, stderr = p.communicate()
if p.returncode != 0:
- print stdout
- print stderr
+ print(stdout)
+ print(stderr)
assert False, 'msginit exited with return code %s' % \
- p.returncode
- assert (app.outdir / 'en_US.po').isfile(), 'msginit failed'
+ p.returncode
+ yield assert_true, (app.outdir / 'en_US.po').isfile(), 'msginit failed'
try:
p = Popen(['msgfmt', 'en_US.po', '-o',
- os.path.join('en', 'LC_MESSAGES', 'test_root.mo')],
- stdout=PIPE, stderr=PIPE)
+ os.path.join('en', 'LC_MESSAGES', 'test_root.mo')],
+ stdout=PIPE, stderr=PIPE)
except OSError:
raise SkipTest # most likely msgfmt was not found
else:
stdout, stderr = p.communicate()
if p.returncode != 0:
- print stdout
- print stderr
+ print(stdout)
+ print(stderr)
assert False, 'msgfmt exited with return code %s' % \
- p.returncode
- assert (app.outdir / 'en' / 'LC_MESSAGES' / 'test_root.mo').isfile(), \
- 'msgfmt failed'
+ p.returncode
+ yield (assert_true,
+ (app.outdir / 'en' / 'LC_MESSAGES' / 'test_root.mo').isfile(),
+ 'msgfmt failed')
finally:
os.chdir(cwd)
_ = gettext.translation('test_root', app.outdir, languages=['en']).gettext
- assert _("Testing various markup") == u"Testing various markup"
+ yield assert_equal, _("Testing various markup"), u"Testing various markup"
-@with_app(buildername='gettext',
- srcdir=(test_roots / 'test-intl'),
- doctreedir=(test_roots / 'test-intl' / '_build' / 'doctree'),
+@with_app('gettext', testroot='intl',
confoverrides={'gettext_compact': False})
-def test_gettext_index_entries(app):
+def test_gettext_index_entries(app, status, warning):
# regression test for #976
app.builder.build(['index_entries'])
_msgid_getter = re.compile(r'msgid "(.*)"').search
+
def msgid_getter(msgid):
m = _msgid_getter(msgid)
if m:
@@ -106,7 +91,7 @@ def test_gettext_index_entries(app):
return None
pot = (app.outdir / 'index_entries.pot').text(encoding='utf-8')
- msgids = filter(None, map(msgid_getter, pot.splitlines()))
+ msgids = [_f for _f in map(msgid_getter, pot.splitlines()) if _f]
expected_msgids = [
"i18n with index entries",
@@ -129,6 +114,38 @@ def test_gettext_index_entries(app):
"Exception",
"Statement",
"Builtin",
+ ]
+ for expect in expected_msgids:
+ assert expect in msgids
+ msgids.remove(expect)
+
+ # unexpected msgid existent
+ assert msgids == []
+
+
+@with_app('gettext', testroot='intl',
+ confoverrides={'gettext_compact': False, 'gettext_enables': []})
+def test_gettext_disable_index_entries(app, status, warning):
+ # regression test for #976
+ app.builder.build(['index_entries'])
+
+ _msgid_getter = re.compile(r'msgid "(.*)"').search
+
+ def msgid_getter(msgid):
+ m = _msgid_getter(msgid)
+ if m:
+ return m.groups()[0]
+ return None
+
+ pot = (app.outdir / 'index_entries.pot').text(encoding='utf-8')
+ msgids = [_f for _f in map(msgid_getter, pot.splitlines()) if _f]
+
+ expected_msgids = [
+ "i18n with index entries",
+ "index target section",
+ "this is :index:`Newsletter` target paragraph.",
+ "various index entries",
+ "That's all.",
]
for expect in expected_msgids:
assert expect in msgids
@@ -138,10 +155,8 @@ def test_gettext_index_entries(app):
assert msgids == []
-@with_app(buildername='gettext',
- srcdir=(test_roots / 'test-intl'),
- doctreedir=(test_roots / 'test-intl' / '_build' / 'doctree'))
-def test_gettext_template(app):
+@with_app(buildername='gettext', testroot='intl')
+def test_gettext_template(app, status, warning):
app.builder.build_all()
assert (app.outdir / 'sphinx.pot').isfile()