2014-09-21 10:17:02 -05:00
|
|
|
"""Test the base build process."""
|
2024-08-11 08:58:56 -05:00
|
|
|
|
2024-11-22 15:54:26 -06:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
import shutil
|
2023-07-27 18:39:12 -05:00
|
|
|
from pathlib import Path
|
2014-09-21 10:17:02 -05:00
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
import pytest
|
2014-09-21 10:17:02 -05:00
|
|
|
|
|
|
|
|
2024-07-10 08:13:10 -05:00
|
|
|
@pytest.fixture
|
2023-02-17 17:46:31 -06:00
|
|
|
def _setup_test(app_params):
|
2023-07-27 18:39:12 -05:00
|
|
|
assert isinstance(app_params.kwargs['srcdir'], Path)
|
2017-05-07 02:46:44 -05:00
|
|
|
srcdir = app_params.kwargs['srcdir']
|
2019-02-27 00:19:58 -06:00
|
|
|
src_locale_dir = srcdir / 'xx' / 'LC_MESSAGES'
|
|
|
|
dest_locale_dir = srcdir / 'locale'
|
2014-09-21 10:17:02 -05:00
|
|
|
# copy all catalogs into locale layout directory
|
2023-07-27 18:39:12 -05:00
|
|
|
for po in src_locale_dir.rglob('*.po'):
|
2024-08-11 08:58:56 -05:00
|
|
|
copy_po = (
|
|
|
|
dest_locale_dir / 'en' / 'LC_MESSAGES' / po.relative_to(src_locale_dir)
|
|
|
|
)
|
2014-09-21 10:17:02 -05:00
|
|
|
if not copy_po.parent.exists():
|
2023-07-27 18:39:12 -05:00
|
|
|
copy_po.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
shutil.copy(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
|
2023-07-27 18:39:12 -05:00
|
|
|
shutil.rmtree(dest_locale_dir, ignore_errors=True)
|
|
|
|
shutil.rmtree(srcdir / '_build', ignore_errors=True)
|
2014-09-21 10:17:02 -05:00
|
|
|
|
|
|
|
|
2023-02-17 17:46:31 -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(
|
2024-08-11 08:58:56 -05:00
|
|
|
'html',
|
|
|
|
testroot='intl',
|
|
|
|
confoverrides={'language': 'en', 'locale_dirs': ['./locale']},
|
|
|
|
)
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_compile_all_catalogs(app):
|
2014-09-21 10:17:02 -05:00
|
|
|
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'
|
2023-07-27 18:39:12 -05:00
|
|
|
expect = {x.with_suffix('.mo') for x in catalog_dir.rglob('*.po')}
|
|
|
|
actual = set(catalog_dir.rglob('*.mo'))
|
2014-09-21 10:17:02 -05:00
|
|
|
assert actual # not empty
|
|
|
|
assert actual == expect
|
|
|
|
|
|
|
|
|
2023-02-17 17:46:31 -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(
|
2024-08-11 08:58:56 -05:00
|
|
|
'html',
|
|
|
|
testroot='intl',
|
|
|
|
confoverrides={'language': 'en', 'locale_dirs': ['./locale']},
|
|
|
|
)
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_compile_specific_catalogs(app):
|
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
|
|
|
|
2023-07-27 18:39:12 -05:00
|
|
|
actual_on_boot = set(catalog_dir.rglob('*.mo')) # sphinx.mo might be included
|
2018-02-06 22:56:17 -06:00
|
|
|
app.builder.compile_specific_catalogs([app.srcdir / 'admonitions.txt'])
|
2024-08-11 08:58:56 -05:00
|
|
|
actual = {
|
|
|
|
str(x.relative_to(catalog_dir))
|
|
|
|
for x in catalog_dir.rglob('*.mo')
|
|
|
|
if x not in actual_on_boot
|
|
|
|
}
|
2019-03-17 14:49:36 -05:00
|
|
|
assert actual == {'admonitions.mo'}
|
2014-09-21 10:17:02 -05:00
|
|
|
|
|
|
|
|
2023-02-17 17:46:31 -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(
|
2024-08-11 08:58:56 -05:00
|
|
|
'html',
|
|
|
|
testroot='intl',
|
|
|
|
confoverrides={'language': 'en', 'locale_dirs': ['./locale']},
|
|
|
|
)
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_compile_update_catalogs(app):
|
2014-09-21 10:17:02 -05:00
|
|
|
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'
|
2023-07-27 18:39:12 -05:00
|
|
|
expect = {x.with_suffix('.mo') for x in set(catalog_dir.rglob('*.po'))}
|
|
|
|
actual = set(catalog_dir.rglob('*.mo'))
|
2014-09-21 10:17:02 -05:00
|
|
|
assert actual # not empty
|
|
|
|
assert actual == expect
|