summaryrefslogtreecommitdiffstats
path: root/tests/test_catalogs.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 11:31:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 11:31:33 +0000
commite863fd965dd6253243c3342bd6f0adc4fc8aec4d (patch)
treea4c1b6491a82593950043c3f8b2530e80664d768 /tests/test_catalogs.py
parentInitial commit. (diff)
downloadsphinx-upstream.tar.xz
sphinx-upstream.zip
Adding upstream version 5.3.0.upstream/5.3.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_catalogs.py')
-rw-r--r--tests/test_catalogs.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/test_catalogs.py b/tests/test_catalogs.py
new file mode 100644
index 0000000..74aa707
--- /dev/null
+++ b/tests/test_catalogs.py
@@ -0,0 +1,81 @@
+"""Test the base build process."""
+import shutil
+
+import pytest
+
+from sphinx.testing.util import find_files
+
+
+@pytest.fixture
+def setup_test(app_params):
+ 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 find_files(src_locale_dir, '.po'):
+ copy_po = (dest_locale_dir / 'en' / 'LC_MESSAGES' / po)
+ if not copy_po.parent.exists():
+ copy_po.parent.makedirs()
+ shutil.copy(src_locale_dir / po, copy_po)
+
+ yield
+
+ # delete remnants left over after failed build
+ dest_locale_dir.rmtree(True)
+ (srcdir / '_build').rmtree(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.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
+
+
+@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'
+
+ def get_actual():
+ return set(find_files(catalog_dir, '.mo'))
+
+ actual_on_boot = get_actual() # sphinx.mo might be included
+ app.builder.compile_specific_catalogs([app.srcdir / 'admonitions.txt'])
+ actual = get_actual() - 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.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