Debian Codegraph @

scripts/tests/test_translation_fixer/test_header_permalinks/test_header_level_mismatch.py

raw
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_header_permalinks/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_level_mismatch_1.md")],
16 indirect=True,
17 )
18 def test_level_mismatch_1(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 == 1
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_level_mismatch_1.md"
28 ).read_text("utf-8")
29
30 assert fixed_content == expected_content # Translated doc remains unchanged
31 assert "Error processing docs/lang/docs/doc.md" in result.output
32 assert (
33 "Header levels do not match between document and original document"
34 " (found #, expected ##) for header №2 in line 5"
35 ) in result.output
36
37
38 @pytest.mark.parametrize(
39 "copy_test_files",
40 [(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_level_mismatch_2.md")],
41 indirect=True,
42 )
43 def test_level_mismatch_2(runner: CliRunner, root_dir: Path, copy_test_files):
44 result = runner.invoke(
45 cli,
46 ["fix-pages", "docs/lang/docs/doc.md"],
47 )
48 assert result.exit_code == 1
49
50 fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
51 expected_content = Path(
52 f"{data_path}/translated_doc_level_mismatch_2.md"
53 ).read_text("utf-8")
54
55 assert fixed_content == expected_content # Translated doc remains unchanged
56 assert "Error processing docs/lang/docs/doc.md" in result.output
57 assert (
58 "Header levels do not match between document and original document"
59 " (found ##, expected #) for header №4 in line 13"
60 ) in result.output