]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
✅ Enable tests in CI for scripts (#14684)
authorSebastián Ramírez <tiangolo@gmail.com>
Sat, 10 Jan 2026 22:43:44 +0000 (14:43 -0800)
committerGitHub <noreply@github.com>
Sat, 10 Jan 2026 22:43:44 +0000 (23:43 +0100)
15 files changed:
scripts/doc_parsing_utils.py
scripts/docs.py
scripts/notify_translations.py
scripts/test.sh
scripts/tests/test_translation_fixer/conftest.py
scripts/tests/test_translation_fixer/test_code_blocks/test_code_blocks_lines_number_mismatch.py
scripts/tests/test_translation_fixer/test_code_blocks/test_code_blocks_mermaid.py
scripts/tests/test_translation_fixer/test_code_blocks/test_code_blocks_number_mismatch.py
scripts/tests/test_translation_fixer/test_code_blocks/test_code_blocks_wrong_lang_code.py
scripts/tests/test_translation_fixer/test_code_includes/test_number_mismatch.py
scripts/tests/test_translation_fixer/test_complex_doc/test_compex_doc.py
scripts/tests/test_translation_fixer/test_header_permalinks/test_header_level_mismatch.py
scripts/tests/test_translation_fixer/test_header_permalinks/test_header_number_mismatch.py
scripts/tests/test_translation_fixer/test_html_links/test_html_links_number_mismatch.py
scripts/tests/test_translation_fixer/test_markdown_links/test_mkd_links_number_mismatch.py

index 857d808aaa2e8422dbaaecd684298224530c348f..79f2e9ec0a558adb0fc80491cb44e1934be011bb 100644 (file)
@@ -1,5 +1,5 @@
 import re
-from typing import TypedDict
+from typing import TypedDict, Union
 
 CODE_INCLUDE_RE = re.compile(r"^\{\*\s*(\S+)\s*(.*)\*\}$")
 CODE_INCLUDE_PLACEHOLDER = "<CODE_INCLUDE>"
@@ -50,8 +50,8 @@ class MarkdownLinkInfo(TypedDict):
     line_no: int
     url: str
     text: str
-    title: str | None
-    attributes: str | None
+    title: Union[str, None]
+    attributes: Union[str, None]
     full_match: str
 
 
@@ -285,7 +285,11 @@ def _add_lang_code_to_url(url: str, lang_code: str) -> str:
 
 
 def _construct_markdown_link(
-    url: str, text: str, title: str | None, attributes: str | None, lang_code: str
+    url: str,
+    text: str,
+    title: Union[str, None],
+    attributes: Union[str, None],
+    lang_code: str,
 ) -> str:
     """
     Construct a markdown link, adjusting the URL for the given language code if needed.
@@ -545,7 +549,7 @@ def extract_multiline_code_blocks(text: list[str]) -> list[MultilineCodeBlockInf
     return blocks
 
 
-def _split_hash_comment(line: str) -> tuple[str, str | None]:
+def _split_hash_comment(line: str) -> tuple[str, Union[str, None]]:
     match = HASH_COMMENT_RE.match(line)
     if match:
         code = match.group("code").rstrip()
@@ -554,7 +558,7 @@ def _split_hash_comment(line: str) -> tuple[str, str | None]:
     return line.rstrip(), None
 
 
-def _split_slashes_comment(line: str) -> tuple[str, str | None]:
+def _split_slashes_comment(line: str) -> tuple[str, Union[str, None]]:
     match = SLASHES_COMMENT_RE.match(line)
     if match:
         code = match.group("code").rstrip()
@@ -600,8 +604,8 @@ def replace_multiline_code_block(
 
     code_block: list[str] = []
     for line_a, line_b in zip(block_a["content"], block_b["content"]):
-        line_a_comment: str | None = None
-        line_b_comment: str | None = None
+        line_a_comment: Union[str, None] = None
+        line_b_comment: Union[str, None] = None
 
         # Handle comments based on language
         if block_language in {
index fbde1eca4f9751bec90b3006c21c0d9dd8672de5..84cf01c72439c50983af6221788f68e272437a26 100644 (file)
@@ -239,7 +239,7 @@ def generate_readme() -> None:
     Generate README.md content from main index.md
     """
     readme_path = Path("README.md")
-    old_content = readme_path.read_text()
+    old_content = readme_path.read_text("utf-8")
     new_content = generate_readme_content()
     if new_content != old_content:
         print("README.md outdated from the latest index.md")
index 2ca740a607e98278b550bef52261010d9594ae7d..74cdf0dffefd0321178d473c62ea4a39fc66c6a2 100644 (file)
@@ -316,7 +316,7 @@ def main() -> None:
         raise RuntimeError(
             f"No github event file available at: {settings.github_event_path}"
         )
-    contents = settings.github_event_path.read_text()
+    contents = settings.github_event_path.read_text("utf-8")
     github_event = PartialGitHubEvent.model_validate_json(contents)
     logging.info(f"Using GitHub event: {github_event}")
     number = (
index 7d17add8fa4b88fa1fa7c12142a2f384dfa9572e..0bffcd1cdd6e784ad29b97bc26fc2622064d360d 100755 (executable)
@@ -4,4 +4,4 @@ set -e
 set -x
 
 export PYTHONPATH=./docs_src
-coverage run -m pytest tests ${@}
+coverage run -m pytest tests scripts/tests/ ${@}
index b2c745de118626c3c5be0bb0ad9b9373bbbd1e80..006f519f465f4c3b607c2f926c434bb6ec86e885 100644 (file)
@@ -1,9 +1,19 @@
 import shutil
+import sys
 from pathlib import Path
 
 import pytest
 from typer.testing import CliRunner
 
+skip_on_windows = pytest.mark.skipif(
+    sys.platform == "win32", reason="Skipping on Windows"
+)
+
+
+def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
+    for item in items:
+        item.add_marker(skip_on_windows)
+
 
 @pytest.fixture(name="runner")
 def get_runner():
index 906c8a560a08ef7fa68cccff2fb3cbddf302f694..9cdbe8323ace26f98cccb8995ce65064a9c15909 100644 (file)
@@ -22,10 +22,10 @@ def test_gt(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     assert result.exit_code == 1, result.output
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
-    expected_content = Path(
-        f"{data_path}/translated_doc_lines_number_gt.md"
-    ).read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = Path(f"{data_path}/translated_doc_lines_number_gt.md").read_text(
+        "utf-8"
+    )
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
@@ -46,10 +46,10 @@ def test_lt(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     # assert result.exit_code == 1, result.output
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
-    expected_content = Path(
-        f"{data_path}/translated_doc_lines_number_lt.md"
-    ).read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = Path(f"{data_path}/translated_doc_lines_number_lt.md").read_text(
+        "utf-8"
+    )
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
index 75c589fb50946bac07c1b3b94ff6ad441fba9d7d..8b80c70f348731c50f6098de932fbaa9df1255ad 100644 (file)
@@ -22,10 +22,10 @@ def test_translated(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     assert result.exit_code == 0, result.output
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
     expected_content = Path(
         f"{data_path}/translated_doc_mermaid_translated.md"
-    ).read_text()
+    ).read_text("utf-8")
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert (
@@ -50,10 +50,10 @@ def test_not_translated(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     assert result.exit_code == 0, result.output
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
     expected_content = Path(
         f"{data_path}/translated_doc_mermaid_not_translated.md"
-    ).read_text()
+    ).read_text("utf-8")
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert ("Skipping mermaid code block replacement") not in result.output
index b05dac900e1cfaef6afb634f4202a9b713d5d65f..ad5767c1cb450b73455c52561118313373d62a52 100644 (file)
@@ -22,8 +22,10 @@ def test_gt(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     assert result.exit_code == 1, result.output
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
-    expected_content = Path(f"{data_path}/translated_doc_number_gt.md").read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = Path(f"{data_path}/translated_doc_number_gt.md").read_text(
+        "utf-8"
+    )
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
@@ -45,8 +47,10 @@ def test_lt(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     # assert result.exit_code == 1, result.output
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
-    expected_content = Path(f"{data_path}/translated_doc_number_lt.md").read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = Path(f"{data_path}/translated_doc_number_lt.md").read_text(
+        "utf-8"
+    )
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
index 6c2b18c89a0abb4b6cefecb2738a93c2cacef8fa..85d73e3b4af72d7cd020ca2153368e2272281da4 100644 (file)
@@ -22,10 +22,10 @@ def test_wrong_lang_code_1(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     assert result.exit_code == 1, result.output
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
-    expected_content = Path(
-        f"{data_path}/translated_doc_wrong_lang_code.md"
-    ).read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = Path(f"{data_path}/translated_doc_wrong_lang_code.md").read_text(
+        "utf-8"
+    )
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
@@ -46,10 +46,10 @@ def test_wrong_lang_code_2(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     assert result.exit_code == 1, result.output
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
     expected_content = Path(
         f"{data_path}/translated_doc_wrong_lang_code_2.md"
-    ).read_text()
+    ).read_text("utf-8")
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
index 5e3eee51af4ce16b228d89866df05302051a8a6a..1020b890cf8ba5d86882197b68a710db4f66874f 100644 (file)
@@ -22,8 +22,10 @@ def test_gt(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     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()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = Path(f"{data_path}/translated_doc_number_gt.md").read_text(
+        "utf-8"
+    )
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
@@ -45,8 +47,10 @@ def test_lt(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     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()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = Path(f"{data_path}/translated_doc_number_lt.md").read_text(
+        "utf-8"
+    )
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
index 86cc4d5eb492cecf172f26b6bf124a7d2c290c85..cc7bcadda804f7d6bb90514b745dd85e3609dcd0 100644 (file)
@@ -22,8 +22,8 @@ def test_fix(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     assert result.exit_code == 0, result.output
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
-    expected_content = (data_path / "translated_doc_expected.md").read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = (data_path / "translated_doc_expected.md").read_text("utf-8")
     assert fixed_content == expected_content
 
     assert "Fixing multiline code blocks in" in result.output
index 9fe2f7ba70a74a5dd27a0cfe4b92495cbaaccdb0..99d27db95368101114ac0bfb1dd7115a0191c969 100644 (file)
@@ -22,10 +22,10 @@ def test_level_mismatch_1(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     assert result.exit_code == 1
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
     expected_content = Path(
         f"{data_path}/translated_doc_level_mismatch_1.md"
-    ).read_text()
+    ).read_text("utf-8")
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
@@ -47,10 +47,10 @@ def test_level_mismatch_2(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     assert result.exit_code == 1
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
     expected_content = Path(
         f"{data_path}/translated_doc_level_mismatch_2.md"
-    ).read_text()
+    ).read_text("utf-8")
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
index c0e78d0302c37b24dc2819915bccd3e61fad6dd7..c4d0346171df09d82119b12cf4349f8c93e91c98 100644 (file)
@@ -22,8 +22,10 @@ def test_gt(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     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()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = Path(f"{data_path}/translated_doc_number_gt.md").read_text(
+        "utf-8"
+    )
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
@@ -45,8 +47,10 @@ def test_lt(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     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()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = Path(f"{data_path}/translated_doc_number_lt.md").read_text(
+        "utf-8"
+    )
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
index 271e5d2058e3cdd4e1ad2b0a07837cfd47c5fc83..11dcea154187b70d69e0cf009a327dc771f13209 100644 (file)
@@ -20,8 +20,10 @@ def test_gt(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     assert result.exit_code == 1, result.output
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
-    expected_content = Path(f"{data_path}/translated_doc_number_gt.md").read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = Path(f"{data_path}/translated_doc_number_gt.md").read_text(
+        "utf-8"
+    )
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
@@ -43,8 +45,10 @@ def test_lt(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     # assert result.exit_code == 1, result.output
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
-    expected_content = Path(f"{data_path}/translated_doc_number_lt.md").read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = Path(f"{data_path}/translated_doc_number_lt.md").read_text(
+        "utf-8"
+    )
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
index 0f4952f35dc3131d88ecf9c3acdd182f2285653e..c72e012543b2f90e9109637dc1345e8c7472aa0f 100644 (file)
@@ -22,8 +22,10 @@ def test_gt(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     assert result.exit_code == 1, result.output
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
-    expected_content = Path(f"{data_path}/translated_doc_number_gt.md").read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = Path(f"{data_path}/translated_doc_number_gt.md").read_text(
+        "utf-8"
+    )
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output
@@ -45,8 +47,10 @@ def test_lt(runner: CliRunner, root_dir: Path, copy_test_files):
     )
     # assert result.exit_code == 1, result.output
 
-    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text()
-    expected_content = Path(f"{data_path}/translated_doc_number_lt.md").read_text()
+    fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text("utf-8")
+    expected_content = Path(f"{data_path}/translated_doc_number_lt.md").read_text(
+        "utf-8"
+    )
 
     assert fixed_content == expected_content  # Translated doc remains unchanged
     assert "Error processing docs/lang/docs/doc.md" in result.output