Skip to content
Open
Prev Previous commit
Next Next commit
Enhance test_build_changes: Update type hint for find_change_item and…
… improve assertions
  • Loading branch information
dariomesic committed Oct 28, 2025
commit bd68cd7d0799c76d6069599d39a766c498d62f14
12 changes: 5 additions & 7 deletions tests/test_builders/test_build_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

from __future__ import annotations

from typing import TYPE_CHECKING
import re
from typing import TYPE_CHECKING, Any

Check failure on line 6 in tests/test_builders/test_build_changes.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (TC003)

tests/test_builders/test_build_changes.py:6:35: TC003 Move standard library import `typing.Any` into a type-checking block

import pytest
from bs4 import BeautifulSoup # type: ignore[import-not-found]

if TYPE_CHECKING:
from sphinx.testing.util import SphinxTestApp

import re # <--- IMPORT ADDED

from bs4 import BeautifulSoup # <--- IMPORT ADDED


@pytest.mark.sphinx('changes', testroot='changes')
def test_build(app: SphinxTestApp) -> None:
Expand All @@ -22,7 +20,7 @@
htmltext = (app.outdir / 'changes.html').read_text(encoding='utf8')
soup = BeautifulSoup(htmltext, 'html.parser')

def find_change_item(type_text: str, version: str, content: str) -> dict:
def find_change_item(type_text: str, version: str, content: str) -> dict[str, Any]:
"""Helper to find and validate change items."""
# Use regex to find text content, ignoring surrounding whitespace/newlines
item = soup.find('li', string=re.compile(r'\s*' + re.escape(content) + r'\s*'))
Expand All @@ -32,7 +30,7 @@
assert type_elem is not None, f"Missing type indicator for '{content}'"
assert type_text in type_elem.text, f"Expected type '{type_text}' for '{content}'"

assert f"version {version}" in item.text, f"Version {version} not found in '{content}'"
assert f'version {version}' in item.text, f'Version {version} not found in {content!r}'

return {'item': item, 'type': type_elem}

Expand Down
Loading