mirror of https://github.com/tiangolo/fastapi.git
Add tests for header and permalinks
This commit is contained in:
parent
8c5f21c83c
commit
5c50b3dd15
|
|
@ -173,3 +173,13 @@ This is an <a href="https://example.com" target="_blank" class="external-link">H
|
||||||
This is an <a href="https://fastapi.tiangolo.com">link to the main FastAPI site</a> - tool should add language code to the URL.
|
This is an <a href="https://fastapi.tiangolo.com">link to the main FastAPI site</a> - tool should add language code to the URL.
|
||||||
|
|
||||||
This is an <a href="https://fastapi.tiangolo.com/how-to/">link to one of the pages on FastAPI site</a> - tool should add language code to the URL.
|
This is an <a href="https://fastapi.tiangolo.com/how-to/">link to one of the pages on FastAPI site</a> - tool should add language code to the URL.
|
||||||
|
|
||||||
|
# Header (with HTML link to <a href="https://tiangolo.com">tiangolo.com</a>) { #header-with-html-link-to-tiangolo-com }
|
||||||
|
|
||||||
|
#Not a header
|
||||||
|
|
||||||
|
```Python
|
||||||
|
# Also not a header
|
||||||
|
```
|
||||||
|
|
||||||
|
Some text
|
||||||
|
|
@ -168,3 +168,13 @@ def hello_world():// Печать приветствия
|
||||||
Это <a href="https://fastapi.tiangolo.com">ссылка на основной сайт FastAPI</a> — инструмент должен добавить код языка в URL.
|
Это <a href="https://fastapi.tiangolo.com">ссылка на основной сайт FastAPI</a> — инструмент должен добавить код языка в URL.
|
||||||
|
|
||||||
Это <a href="https://fastapi.tiangolo.com/how-to/">ссылка на одну из страниц на сайте FastAPI</a> — инструмент должен добавить код языка в URL.
|
Это <a href="https://fastapi.tiangolo.com/how-to/">ссылка на одну из страниц на сайте FastAPI</a> — инструмент должен добавить код языка в URL.
|
||||||
|
|
||||||
|
# Заголовок (с HTML ссылкой на <a href="https://tiangolo.com">tiangolo.com</a>) { #header-5 }
|
||||||
|
|
||||||
|
#Не заголовок
|
||||||
|
|
||||||
|
```Python
|
||||||
|
# Также не заголовок
|
||||||
|
```
|
||||||
|
|
||||||
|
Немного текста
|
||||||
|
|
|
||||||
|
|
@ -168,3 +168,13 @@ def hello_world():// Print greeting
|
||||||
Это <a href="https://fastapi.tiangolo.com/lang">ссылка на основной сайт FastAPI</a> — инструмент должен добавить код языка в URL.
|
Это <a href="https://fastapi.tiangolo.com/lang">ссылка на основной сайт FastAPI</a> — инструмент должен добавить код языка в URL.
|
||||||
|
|
||||||
Это <a href="https://fastapi.tiangolo.com/lang/how-to/">ссылка на одну из страниц на сайте FastAPI</a> — инструмент должен добавить код языка в URL.
|
Это <a href="https://fastapi.tiangolo.com/lang/how-to/">ссылка на одну из страниц на сайте FastAPI</a> — инструмент должен добавить код языка в URL.
|
||||||
|
|
||||||
|
# Заголовок (с HTML ссылкой на <a href="https://tiangolo.com">tiangolo.com</a>) { #header-with-html-link-to-tiangolo-com }
|
||||||
|
|
||||||
|
#Не заголовок
|
||||||
|
|
||||||
|
```Python
|
||||||
|
# Также не заголовок
|
||||||
|
```
|
||||||
|
|
||||||
|
Немного текста
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Header 1 { #header-1 }
|
||||||
|
|
||||||
|
Some text
|
||||||
|
|
||||||
|
## Header 2 { #header-2 }
|
||||||
|
|
||||||
|
Some more text
|
||||||
|
|
||||||
|
### Header 3 { #header-3 }
|
||||||
|
|
||||||
|
Even more text
|
||||||
|
|
||||||
|
# Header 4 { #header-4 }
|
||||||
|
|
||||||
|
A bit more text
|
||||||
|
|
||||||
|
#Not a header
|
||||||
|
|
||||||
|
Final portion of text
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Header 1 { #header-1 }
|
||||||
|
|
||||||
|
Some text
|
||||||
|
|
||||||
|
# Header 2 { #header-2 }
|
||||||
|
|
||||||
|
Some more text
|
||||||
|
|
||||||
|
### Header 3 { #header-3 }
|
||||||
|
|
||||||
|
Even more text
|
||||||
|
|
||||||
|
# Header 4 { #header-4 }
|
||||||
|
|
||||||
|
A bit more text
|
||||||
|
|
||||||
|
#Not a header
|
||||||
|
|
||||||
|
Final portion of text
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Header 1 { #header-1 }
|
||||||
|
|
||||||
|
Some text
|
||||||
|
|
||||||
|
## Header 2 { #header-2 }
|
||||||
|
|
||||||
|
Some more text
|
||||||
|
|
||||||
|
### Header 3 { #header-3 }
|
||||||
|
|
||||||
|
Even more text
|
||||||
|
|
||||||
|
## Header 4 { #header-4 }
|
||||||
|
|
||||||
|
A bit more text
|
||||||
|
|
||||||
|
#Not a header
|
||||||
|
|
||||||
|
Final portion of text
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Header 1 { #header-1 }
|
||||||
|
|
||||||
|
Some text
|
||||||
|
|
||||||
|
## Header 2 { #header-2 }
|
||||||
|
|
||||||
|
Some more text
|
||||||
|
|
||||||
|
### Header 3 { #header-3 }
|
||||||
|
|
||||||
|
Even more text
|
||||||
|
|
||||||
|
# Header 4 { #header-4 }
|
||||||
|
|
||||||
|
A bit more text
|
||||||
|
|
||||||
|
# Extra header
|
||||||
|
|
||||||
|
Final portion of text
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Header 1 { #header-1 }
|
||||||
|
|
||||||
|
Some text
|
||||||
|
|
||||||
|
## Header 2 { #header-2 }
|
||||||
|
|
||||||
|
Some more text
|
||||||
|
|
||||||
|
### Header 3 { #header-3 }
|
||||||
|
|
||||||
|
Even more text
|
||||||
|
|
||||||
|
Header 4 is missing
|
||||||
|
|
||||||
|
A bit more text
|
||||||
|
|
||||||
|
#Not a header
|
||||||
|
|
||||||
|
Final portion of text
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from typer.testing import CliRunner
|
||||||
|
|
||||||
|
from scripts.translation_fixer import cli
|
||||||
|
|
||||||
|
data_path = Path(
|
||||||
|
"scripts/tests/test_translation_fixer/test_header_permalinks/data"
|
||||||
|
).absolute()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"copy_test_files",
|
||||||
|
[(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_level_mismatch_1.md")],
|
||||||
|
indirect=True,
|
||||||
|
)
|
||||||
|
def test_level_mismatch_1(runner: CliRunner, root_dir: Path, copy_test_files):
|
||||||
|
result = runner.invoke(
|
||||||
|
cli,
|
||||||
|
["fix-pages", "docs/lang/docs/doc.md"],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 1
|
||||||
|
|
||||||
|
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
|
||||||
|
expected_content = Path(
|
||||||
|
f"{data_path}/translated_doc_level_mismatch_1.md"
|
||||||
|
).read_text()
|
||||||
|
|
||||||
|
assert fixed_content == expected_content # Translated doc remains unchanged
|
||||||
|
assert "Error processing docs/lang/docs/doc.md" in result.output
|
||||||
|
assert (
|
||||||
|
"Header levels do not match between document and original document"
|
||||||
|
" (found #, expected ##) for header №2 in line 5"
|
||||||
|
) in result.output
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"copy_test_files",
|
||||||
|
[(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_level_mismatch_2.md")],
|
||||||
|
indirect=True,
|
||||||
|
)
|
||||||
|
def test_level_mismatch_2(runner: CliRunner, root_dir: Path, copy_test_files):
|
||||||
|
result = runner.invoke(
|
||||||
|
cli,
|
||||||
|
["fix-pages", "docs/lang/docs/doc.md"],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 1
|
||||||
|
|
||||||
|
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
|
||||||
|
expected_content = Path(
|
||||||
|
f"{data_path}/translated_doc_level_mismatch_2.md"
|
||||||
|
).read_text()
|
||||||
|
|
||||||
|
assert fixed_content == expected_content # Translated doc remains unchanged
|
||||||
|
assert "Error processing docs/lang/docs/doc.md" in result.output
|
||||||
|
assert (
|
||||||
|
"Header levels do not match between document and original document"
|
||||||
|
" (found ##, expected #) for header №4 in line 13"
|
||||||
|
) in result.output
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from typer.testing import CliRunner
|
||||||
|
|
||||||
|
from scripts.translation_fixer import cli
|
||||||
|
|
||||||
|
data_path = Path(
|
||||||
|
"scripts/tests/test_translation_fixer/test_header_permalinks/data"
|
||||||
|
).absolute()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"copy_test_files",
|
||||||
|
[(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_number_gt.md")],
|
||||||
|
indirect=True,
|
||||||
|
)
|
||||||
|
def test_gt(runner: CliRunner, root_dir: Path, copy_test_files):
|
||||||
|
result = runner.invoke(
|
||||||
|
cli,
|
||||||
|
["fix-pages", "docs/lang/docs/doc.md"],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 1
|
||||||
|
|
||||||
|
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
|
||||||
|
expected_content = Path(f"{data_path}/translated_doc_number_gt.md").read_text()
|
||||||
|
|
||||||
|
assert fixed_content == expected_content # Translated doc remains unchanged
|
||||||
|
assert "Error processing docs/lang/docs/doc.md" in result.output
|
||||||
|
assert (
|
||||||
|
"Number of headers with permalinks does not match the number "
|
||||||
|
"in the original document (5 vs 4)"
|
||||||
|
) in result.output
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"copy_test_files",
|
||||||
|
[(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_number_lt.md")],
|
||||||
|
indirect=True,
|
||||||
|
)
|
||||||
|
def test_lt(runner: CliRunner, root_dir: Path, copy_test_files):
|
||||||
|
result = runner.invoke(
|
||||||
|
cli,
|
||||||
|
["fix-pages", "docs/lang/docs/doc.md"],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 1
|
||||||
|
|
||||||
|
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
|
||||||
|
expected_content = Path(f"{data_path}/translated_doc_number_lt.md").read_text()
|
||||||
|
|
||||||
|
assert fixed_content == expected_content # Translated doc remains unchanged
|
||||||
|
assert "Error processing docs/lang/docs/doc.md" in result.output
|
||||||
|
assert (
|
||||||
|
"Number of headers with permalinks does not match the number "
|
||||||
|
"in the original document (3 vs 4)"
|
||||||
|
) in result.output
|
||||||
Loading…
Reference in New Issue