| 1 |
from pathlib import Path |
| 2 |
|
| 3 |
import pytest |
| 4 |
from typer.testing import CliRunner |
| 5 |
|
| 6 |
from scripts.translation_fixer import cli |
| 7 |
|
| 8 |
data_path = Path( |
| 9 |
"scripts/tests/test_translation_fixer/test_code_blocks/data" |
| 10 |
).absolute() |
| 11 |
|
| 12 |
|
| 13 |
@pytest.mark.parametrize( |
| 14 |
"copy_test_files", |
| 15 |
[(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_mermaid_translated.md")], |
| 16 |
indirect=True, |
| 17 |
) |
| 18 |
def test_translated(runner: CliRunner, root_dir: Path, copy_test_files): |
| 19 |
result = runner.invoke( |
| 20 |
cli, |
| 21 |
["fix-pages", "docs/lang/docs/doc.md"], |
| 22 |
) |
| 23 |
assert result.exit_code == 0, result.output |
| 24 |
|
| 25 |
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8") |
| 26 |
expected_content = Path( |
| 27 |
f"{data_path}/translated_doc_mermaid_translated.md" |
| 28 |
).read_text("utf-8") |
| 29 |
|
| 30 |
assert fixed_content == expected_content # Translated doc remains unchanged |
| 31 |
assert ( |
| 32 |
"Skipping mermaid code block replacement (lines 41-44). This should be checked manually." |
| 33 |
) in result.output |
| 34 |
|
| 35 |
|
| 36 |
@pytest.mark.parametrize( |
| 37 |
"copy_test_files", |
| 38 |
[ |
| 39 |
( |
| 40 |
f"{data_path}/en_doc.md", |
| 41 |
f"{data_path}/translated_doc_mermaid_not_translated.md", |
| 42 |
) |
| 43 |
], |
| 44 |
indirect=True, |
| 45 |
) |
| 46 |
def test_not_translated(runner: CliRunner, root_dir: Path, copy_test_files): |
| 47 |
result = runner.invoke( |
| 48 |
cli, |
| 49 |
["fix-pages", "docs/lang/docs/doc.md"], |
| 50 |
) |
| 51 |
assert result.exit_code == 0, result.output |
| 52 |
|
| 53 |
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8") |
| 54 |
expected_content = Path( |
| 55 |
f"{data_path}/translated_doc_mermaid_not_translated.md" |
| 56 |
).read_text("utf-8") |
| 57 |
|
| 58 |
assert fixed_content == expected_content # Translated doc remains unchanged |
| 59 |
assert ("Skipping mermaid code block replacement") not in result.output |