2014-09-21 10:17:02 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_build_base
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test the base build process.
|
|
|
|
|
2016-01-14 15:54:04 -06:00
|
|
|
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
2014-09-21 10:17:02 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
import shutil
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
import pytest
|
2014-09-21 10:17:02 -05:00
|
|
|
|
|
|
|
from util import with_app, find_files, rootdir, tempdir
|
|
|
|
|
|
|
|
root = tempdir / 'test-intl'
|
|
|
|
build_dir = root / '_build'
|
|
|
|
locale_dir = build_dir / 'locale'
|
|
|
|
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.fixture
|
2014-09-21 10:17:02 -05:00
|
|
|
def setup_test():
|
|
|
|
# delete remnants left over after failed build
|
|
|
|
root.rmtree(True)
|
|
|
|
(rootdir / 'roots' / 'test-intl').copytree(root)
|
|
|
|
# copy all catalogs into locale layout directory
|
|
|
|
for po in find_files(root, '.po'):
|
|
|
|
copy_po = (locale_dir / 'en' / 'LC_MESSAGES' / po)
|
|
|
|
if not copy_po.parent.exists():
|
|
|
|
copy_po.parent.makedirs()
|
|
|
|
shutil.copy(root / po, copy_po)
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
yield
|
2014-09-21 10:17:02 -05:00
|
|
|
|
|
|
|
build_dir.rmtree(True)
|
|
|
|
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.mark.usefixtures('setup_test')
|
2014-09-21 10:17:02 -05:00
|
|
|
@with_app(buildername='html', testroot='intl',
|
|
|
|
confoverrides={'language': 'en', 'locale_dirs': [locale_dir]})
|
|
|
|
def test_compile_all_catalogs(app, status, warning):
|
|
|
|
app.builder.compile_all_catalogs()
|
|
|
|
|
|
|
|
catalog_dir = locale_dir / app.config.language / 'LC_MESSAGES'
|
|
|
|
expect = set([
|
|
|
|
x.replace('.po', '.mo')
|
|
|
|
for x in find_files(catalog_dir, '.po')
|
|
|
|
])
|
|
|
|
actual = set(find_files(catalog_dir, '.mo'))
|
|
|
|
assert actual # not empty
|
|
|
|
assert actual == expect
|
|
|
|
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.mark.usefixtures('setup_test')
|
2014-09-21 10:17:02 -05:00
|
|
|
@with_app(buildername='html', testroot='intl',
|
|
|
|
confoverrides={'language': 'en', 'locale_dirs': [locale_dir]})
|
|
|
|
def test_compile_specific_catalogs(app, status, warning):
|
|
|
|
catalog_dir = locale_dir / app.config.language / 'LC_MESSAGES'
|
2016-06-11 10:00:52 -05:00
|
|
|
|
2015-03-16 09:01:16 -05:00
|
|
|
def get_actual():
|
|
|
|
return set(find_files(catalog_dir, '.mo'))
|
|
|
|
|
|
|
|
actual_on_boot = get_actual() # sphinx.mo might be included
|
|
|
|
app.builder.compile_specific_catalogs(['admonitions'])
|
|
|
|
actual = get_actual() - actual_on_boot
|
2014-09-21 10:17:02 -05:00
|
|
|
assert actual == set(['admonitions.mo'])
|
|
|
|
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.mark.usefixtures('setup_test')
|
2014-09-21 10:17:02 -05:00
|
|
|
@with_app(buildername='html', testroot='intl',
|
|
|
|
confoverrides={'language': 'en', 'locale_dirs': [locale_dir]})
|
|
|
|
def test_compile_update_catalogs(app, status, warning):
|
|
|
|
app.builder.compile_update_catalogs()
|
|
|
|
|
|
|
|
catalog_dir = locale_dir / app.config.language / 'LC_MESSAGES'
|
|
|
|
expect = set([
|
|
|
|
x.replace('.po', '.mo')
|
|
|
|
for x in find_files(catalog_dir, '.po')
|
|
|
|
])
|
|
|
|
actual = set(find_files(catalog_dir, '.mo'))
|
|
|
|
assert actual # not empty
|
|
|
|
assert actual == expect
|