|
17 | 17 | SNIPPETS_PATH = Path(__file__).parent.parent / "docs" / "snippets" |
18 | 18 | SNIPPETS_GLOB_RST = list((SNIPPETS_PATH / "rst").glob("[!_]*")) |
19 | 19 | SNIPPETS_GLOB_MYST = list((SNIPPETS_PATH / "myst").glob("[!_]*")) |
| 20 | +EXPECTED_PATH = Path(__file__).parent / "test_snippets" |
| 21 | +I18N_GLOB_MYST = [ |
| 22 | + p |
| 23 | + for p in SNIPPETS_GLOB_MYST |
| 24 | + if (EXPECTED_PATH / f"snippet_i18n_{p.stem}.pot").exists() |
| 25 | +] |
20 | 26 |
|
21 | 27 |
|
22 | 28 | def write_assets(src_path: Path): |
@@ -205,3 +211,35 @@ def test_sd_custom_directives( |
205 | 211 | extension=".xml", |
206 | 212 | encoding="utf8", |
207 | 213 | ) |
| 214 | + |
| 215 | + |
| 216 | +@pytest.mark.parametrize("sphinx_builder", ["gettext"], indirect=True) |
| 217 | +@pytest.mark.parametrize( |
| 218 | + "path", |
| 219 | + I18N_GLOB_MYST, |
| 220 | + ids=[path.stem for path in I18N_GLOB_MYST], |
| 221 | +) |
| 222 | +@pytest.mark.skipif(not MYST_INSTALLED, reason="myst-parser not installed") |
| 223 | +def test_i18n_myst( |
| 224 | + sphinx_builder: Callable[..., SphinxBuilder], |
| 225 | + path: Path, |
| 226 | + normalize_doctree_xml, |
| 227 | + file_regression, |
| 228 | +): |
| 229 | + builder = sphinx_builder() |
| 230 | + content = path.read_text(encoding="utf8") |
| 231 | + builder.src_path.joinpath("index.md").write_text(content, encoding="utf8") |
| 232 | + write_assets(builder.src_path) |
| 233 | + builder.build() |
| 234 | + |
| 235 | + # strip metadata (that includes a constantly-varying timestamp) |
| 236 | + out_path = builder.out_path / "index.pot" |
| 237 | + out = out_path.read_text() |
| 238 | + out = out[out.find("#: ../../index") :] |
| 239 | + |
| 240 | + file_regression.check( |
| 241 | + out, |
| 242 | + basename=f"snippet_i18n_{path.stem}", |
| 243 | + extension=".pot", |
| 244 | + encoding="utf8", |
| 245 | + ) |
0 commit comments