1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
|