sphinx/tests/test_intl/test_catalogs.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
2.6 KiB
Python
Raw Normal View History

"""Test the base build process."""
import shutil
from pathlib import Path
2017-01-03 07:24:00 -06:00
import pytest
2024-07-10 08:13:10 -05:00
@pytest.fixture
2023-02-17 17:46:31 -06:00
def _setup_test(app_params):
assert isinstance(app_params.kwargs['srcdir'], Path)
srcdir = app_params.kwargs['srcdir']
src_locale_dir = srcdir / 'xx' / 'LC_MESSAGES'
dest_locale_dir = srcdir / 'locale'
# copy all catalogs into locale layout directory
for po in src_locale_dir.rglob('*.po'):
copy_po = (dest_locale_dir / 'en' / 'LC_MESSAGES' / po.relative_to(src_locale_dir))
if not copy_po.parent.exists():
copy_po.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(po, copy_po)
2017-01-03 07:24:00 -06:00
yield
# delete remnants left over after failed build
shutil.rmtree(dest_locale_dir, ignore_errors=True)
shutil.rmtree(srcdir / '_build', ignore_errors=True)
2023-02-17 17:46:31 -06:00
@pytest.mark.usefixtures('_setup_test')
@pytest.mark.test_params(shared_result='test-catalogs')
@pytest.mark.sphinx(
'html', testroot='intl',
confoverrides={'language': 'en', 'locale_dirs': ['./locale']})
def test_compile_all_catalogs(app):
app.builder.compile_all_catalogs()
locale_dir = app.srcdir / 'locale'
catalog_dir = locale_dir / app.config.language / 'LC_MESSAGES'
expect = {x.with_suffix('.mo') for x in catalog_dir.rglob('*.po')}
actual = set(catalog_dir.rglob('*.mo'))
assert actual # not empty
assert actual == expect
2023-02-17 17:46:31 -06:00
@pytest.mark.usefixtures('_setup_test')
@pytest.mark.test_params(shared_result='test-catalogs')
@pytest.mark.sphinx(
'html', testroot='intl',
confoverrides={'language': 'en', 'locale_dirs': ['./locale']})
def test_compile_specific_catalogs(app):
locale_dir = app.srcdir / 'locale'
catalog_dir = locale_dir / app.config.language / 'LC_MESSAGES'
2016-06-11 10:00:52 -05:00
actual_on_boot = set(catalog_dir.rglob('*.mo')) # sphinx.mo might be included
app.builder.compile_specific_catalogs([app.srcdir / 'admonitions.txt'])
actual = {str(x.relative_to(catalog_dir))
for x in catalog_dir.rglob('*.mo')
if x not in actual_on_boot}
assert actual == {'admonitions.mo'}
2023-02-17 17:46:31 -06:00
@pytest.mark.usefixtures('_setup_test')
@pytest.mark.test_params(shared_result='test-catalogs')
@pytest.mark.sphinx(
'html', testroot='intl',
confoverrides={'language': 'en', 'locale_dirs': ['./locale']})
def test_compile_update_catalogs(app):
app.builder.compile_update_catalogs()
locale_dir = app.srcdir / 'locale'
catalog_dir = locale_dir / app.config.language / 'LC_MESSAGES'
expect = {x.with_suffix('.mo') for x in set(catalog_dir.rglob('*.po'))}
actual = set(catalog_dir.rglob('*.mo'))
assert actual # not empty
assert actual == expect