summaryrefslogtreecommitdiffstats
path: root/tests/test_catalogs.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:25:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:25:40 +0000
commitcf7da1843c45a4c2df7a749f7886a2d2ba0ee92a (patch)
tree18dcde1a8d1f5570a77cd0c361de3b490d02c789 /tests/test_catalogs.py
parentInitial commit. (diff)
downloadsphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.tar.xz
sphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.zip
Adding upstream version 7.2.6.upstream/7.2.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_catalogs.py')
-rw-r--r--tests/test_catalogs.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/test_catalogs.py b/tests/test_catalogs.py
new file mode 100644
index 0000000..b7fd7be
--- /dev/null
+++ b/tests/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