summaryrefslogtreecommitdiffstats
path: root/tests/test_intl/test_catalogs.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_intl/test_catalogs.py')
-rw-r--r--tests/test_intl/test_catalogs.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/test_intl/test_catalogs.py b/tests/test_intl/test_catalogs.py
new file mode 100644
index 0000000..b7fd7be
--- /dev/null
+++ b/tests/test_intl/test_catalogs.py
@@ -0,0 +1,74 @@
+"""Test the base build process."""
+import shutil
+from pathlib import Path
+
+import pytest
+
+
+@pytest.fixture()
+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)
+
+ yield
+
+ # delete remnants left over after failed build
+ shutil.rmtree(dest_locale_dir, ignore_errors=True)
+ shutil.rmtree(srcdir / '_build', ignore_errors=True)
+
+
+@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, status, warning):
+ 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
+
+
+@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, status, warning):
+ locale_dir = app.srcdir / 'locale'
+ catalog_dir = locale_dir / app.config.language / 'LC_MESSAGES'
+
+ 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'}
+
+
+@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, status, warning):
+ 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