2014-09-21 10:17:02 -05:00
|
|
|
"""
|
|
|
|
test_build_base
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test the base build process.
|
|
|
|
|
2019-01-02 01:00:30 -06:00
|
|
|
:copyright: Copyright 2007-2019 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
|
|
|
|
2017-05-07 02:46:44 -05:00
|
|
|
from sphinx.testing.util import find_files
|
2014-09-21 10:17:02 -05:00
|
|
|
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.fixture
|
2017-05-07 02:46:44 -05:00
|
|
|
def setup_test(app_params):
|
|
|
|
srcdir = app_params.kwargs['srcdir']
|
|
|
|
locale_dir = srcdir / 'locale'
|
2014-09-21 10:17:02 -05:00
|
|
|
# copy all catalogs into locale layout directory
|
2017-05-07 02:46:44 -05:00
|
|
|
for po in find_files(srcdir, '.po'):
|
2014-09-21 10:17:02 -05:00
|
|
|
copy_po = (locale_dir / 'en' / 'LC_MESSAGES' / po)
|
|
|
|
if not copy_po.parent.exists():
|
|
|
|
copy_po.parent.makedirs()
|
2017-05-07 02:46:44 -05:00
|
|
|
shutil.copy(srcdir / po, copy_po)
|
2014-09-21 10:17:02 -05:00
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
yield
|
2014-09-21 10:17:02 -05:00
|
|
|
|
2017-05-07 02:46:44 -05:00
|
|
|
# delete remnants left over after failed build
|
|
|
|
locale_dir.rmtree(True)
|
|
|
|
(srcdir / '_build').rmtree(True)
|
2014-09-21 10:17:02 -05:00
|
|
|
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.mark.usefixtures('setup_test')
|
2017-05-07 02:46:44 -05:00
|
|
|
@pytest.mark.test_params(shared_result='test-catalogs')
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx(
|
|
|
|
'html', testroot='intl',
|
2017-05-07 02:46:44 -05:00
|
|
|
confoverrides={'language': 'en', 'locale_dirs': ['./locale']})
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_compile_all_catalogs(app, status, warning):
|
|
|
|
app.builder.compile_all_catalogs()
|
|
|
|
|
2017-05-07 02:46:44 -05:00
|
|
|
locale_dir = app.srcdir / 'locale'
|
2014-09-21 10:17:02 -05:00
|
|
|
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')
|
2017-05-07 02:46:44 -05:00
|
|
|
@pytest.mark.test_params(shared_result='test-catalogs')
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx(
|
2017-05-07 02:46:44 -05:00
|
|
|
'html', testroot='intl',
|
|
|
|
confoverrides={'language': 'en', 'locale_dirs': ['./locale']})
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_compile_specific_catalogs(app, status, warning):
|
2017-05-07 02:46:44 -05:00
|
|
|
locale_dir = app.srcdir / 'locale'
|
2014-09-21 10:17:02 -05:00
|
|
|
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
|
2018-02-06 22:56:17 -06:00
|
|
|
app.builder.compile_specific_catalogs([app.srcdir / 'admonitions.txt'])
|
2015-03-16 09:01:16 -05:00
|
|
|
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')
|
2017-05-07 02:46:44 -05:00
|
|
|
@pytest.mark.test_params(shared_result='test-catalogs')
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx(
|
2017-05-07 02:46:44 -05:00
|
|
|
'html', testroot='intl',
|
|
|
|
confoverrides={'language': 'en', 'locale_dirs': ['./locale']})
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_compile_update_catalogs(app, status, warning):
|
|
|
|
app.builder.compile_update_catalogs()
|
|
|
|
|
2017-05-07 02:46:44 -05:00
|
|
|
locale_dir = app.srcdir / 'locale'
|
2014-09-21 10:17:02 -05:00
|
|
|
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
|