sphinx/tests/test_build_gettext.py

65 lines
2.0 KiB
Python
Raw Normal View History

2010-06-07 07:04:16 -05:00
# -*- coding: utf-8 -*-
"""
test_build_gettext
~~~~~~~~~~~~~~~~
Test the build process with gettext builder with the test root.
:copyright: Copyright 2010 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
2010-06-08 23:46:30 -05:00
import os
from subprocess import Popen, PIPE
2010-06-07 07:04:16 -05:00
from util import *
def teardown_module():
(test_root / '_build').rmtree(True)
@with_app(buildername='gettext', cleanenv=True)
2010-06-17 04:46:49 -05:00
def test_build(app):
2010-06-07 07:04:16 -05:00
app.builder.build_all()
2010-06-17 04:46:49 -05:00
# documents end up in a message catalog
2010-06-07 07:04:16 -05:00
assert (app.outdir / 'contents.pot').isfile()
2010-06-17 04:46:49 -05:00
# ..and are grouped into sections
2010-06-07 07:04:16 -05:00
assert (app.outdir / 'subdir.pot').isfile()
2010-06-08 23:46:30 -05:00
2010-06-17 04:46:49 -05:00
@with_app(buildername='gettext', cleanenv=True)
def test_gettext(app):
app.builder.build_all()
(app.outdir / 'en' / 'LC_MESSAGES').makedirs()
2010-06-08 23:46:30 -05:00
cwd = os.getcwd()
os.chdir(app.outdir)
try:
try:
p = Popen(['msginit', '--no-translator', '-i', 'contents.pot'],
stdout=PIPE, stderr=PIPE)
except OSError:
return # most likely msginit was not found
else:
stdout, stderr = p.communicate()
if p.returncode != 0:
print stdout
print stderr
assert False, 'msginit exited with return code %s' % p.returncode
assert (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)
except OSError:
return # most likely msgfmt was not found
else:
stdout, stderr = p.communicate()
if p.returncode != 0:
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'
2010-06-08 23:46:30 -05:00
finally:
os.chdir(cwd)