Skip to content

Commit 2bcdd71

Browse files
committed
Update type hints for newer beautifulsoup.
1 parent 296203c commit 2bcdd71

File tree

2 files changed

+14
-54
lines changed

2 files changed

+14
-54
lines changed

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# 3rd party
66
import pytest
7-
from bs4 import BeautifulSoup # type: ignore[import]
7+
from bs4 import BeautifulSoup
88
from domdf_python_tools.paths import PathPlus
99

1010
if sys.version_info >= (3, 10):
@@ -28,7 +28,7 @@ def rootdir() -> path:
2828

2929
@pytest.fixture()
3030
def the_app(app: Sphinx) -> Sphinx:
31-
fake_repo_root = PathPlus(app.env.srcdir).parent # type: ignore[union-attr]
31+
fake_repo_root = PathPlus(app.env.srcdir).parent
3232

3333
PathPlus(fake_repo_root / "__pkginfo__.py").write_lines([
3434
"extras_require = {",

tests/test_directive.py

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
# stdlib
44
import sys
55
import warnings
6-
from typing import Dict, List
6+
from typing import Dict, List, cast
77

88
# 3rd party
99
import pytest
10-
from bs4 import BeautifulSoup # type: ignore[import]
11-
from bs4.element import Tag # type: ignore[import]
10+
from bs4 import BeautifulSoup
11+
from bs4.element import Tag
1212
from sphinx.application import Sphinx
1313
from sphinx_toolbox.testing import HTMLRegressionFixture
1414

@@ -181,52 +181,6 @@ def test(the_app: Sphinx) -> None:
181181
the_app.build()
182182

183183

184-
def _do_test_directive(
185-
page: BeautifulSoup,
186-
requirements: List[str],
187-
extra: str,
188-
html_regression: HTMLRegressionFixture,
189-
) -> None:
190-
191-
div_count = 0
192-
193-
for div in page.find_all("div"):
194-
if not div.get("id", '').startswith("extras_require"):
195-
continue
196-
197-
assert div.find_all('p')[0].contents == ["Attention"]
198-
assert div.find_all('p')[0]["class"] == ["admonition-title"]
199-
assert div.find_all('p')[1].contents == ["This module has the following additional requirements:"]
200-
201-
assert div.div["class"] == ["highlight-text", "notranslate"]
202-
assert div.div.div["class"] == ["highlight"]
203-
assert div.div.div.pre.contents[1:] == ['\n'.join(requirements) + '\n']
204-
205-
assert div.find_all('p')[2].contents == ["These can be installed as follows:"]
206-
207-
assert div.blockquote.div.div["class"] == ["highlight-default", "notranslate"]
208-
assert div.blockquote.div.div.div["class"] == ["highlight"]
209-
210-
expected_instructions = [
211-
Tag(name="span"),
212-
"$ python -m pip install Python",
213-
Tag(name="span", attrs={"class": ['o']}),
214-
extra,
215-
Tag(name="span", attrs={"class": ['o']}),
216-
'\n'
217-
]
218-
expected_instructions[2].string = '['
219-
expected_instructions[4].string = ']'
220-
221-
assert div.blockquote.div.div.div.pre.contents == expected_instructions
222-
223-
div_count += 1
224-
225-
assert div_count == 1
226-
227-
html_regression.check(page, jinja2=True)
228-
229-
230184
@pytest.mark.parametrize(
231185
"page",
232186
[
@@ -242,7 +196,9 @@ def _do_test_directive(
242196
def test_output(page: BeautifulSoup, html_regression: HTMLRegressionFixture) -> None:
243197

244198
for div in page.find_all("script"):
199+
assert isinstance(div, Tag)
245200
if div.get("src"):
201+
assert isinstance(div["src"], str)
246202
div["src"] = div["src"].split("?v=")[0]
247203
print(div["src"])
248204

@@ -255,16 +211,20 @@ def test_no_requirements_demo(
255211
html_regression: HTMLRegressionFixture,
256212
) -> None:
257213
# Make sure the page title is what you expect
258-
title = page.find("h1").contents[0].strip()
214+
h1 = page.find("h1")
215+
assert isinstance(h1, Tag)
216+
title = cast(str, h1.contents[0]).strip()
259217
assert "No Requirements Demo" == title
260218

261219
# Now test the directive
262220
for div in page.find_all("div"):
263-
assert not div.get("id", '').startswith("extras_require")
221+
assert isinstance(div, Tag)
222+
assert not cast(str, div.get("id", '')).startswith("extras_require")
264223

265224
for div in page.find_all("script"):
225+
assert isinstance(div, Tag)
266226
if div.get("src"):
267-
div["src"] = div["src"].split("?v=")[0]
227+
div["src"] = cast(str, div["src"]).split("?v=")[0]
268228
print(div["src"])
269229

270230
html_regression.check(page, jinja2=True)

0 commit comments

Comments
 (0)