Skip to content

Commit 56e52fc

Browse files
authored
Fix type error in mocking _fetch_inventory (sphinx-doc#13274)
1 parent 25d4ae5 commit 56e52fc

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

tests/test_extensions/test_ext_intersphinx.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
)
3838
from tests.utils import http_server
3939

40+
if TYPE_CHECKING:
41+
from typing import NoReturn
42+
43+
from sphinx.ext.intersphinx._shared import InventoryCacheEntry
44+
from sphinx.util.typing import Inventory
45+
4046

4147
class FakeList(list[str]):
4248
def __iter__(self) -> NoReturn:
@@ -739,20 +745,14 @@ def test_intersphinx_role(app):
739745
assert html.format('index.html#foons') in content
740746

741747

742-
if TYPE_CHECKING:
743-
from typing import NoReturn
744-
745-
from sphinx.ext.intersphinx._shared import InventoryCacheEntry
746-
747-
748748
@pytest.mark.sphinx('html', testroot='root')
749749
@pytest.mark.parametrize(
750750
('cache_limit', 'expected_expired'),
751751
[
752-
(5, False),
753-
(1, True),
754-
(0, True),
755-
(-1, False),
752+
(5, False), # cache for 5 days
753+
(1, True), # cache for 1 day
754+
(0, True), # cache for 0 days
755+
(-1, False), # cache forever
756756
],
757757
)
758758
def test_intersphinx_cache_limit(app, monkeypatch, cache_limit, expected_expired):
@@ -775,7 +775,8 @@ def test_intersphinx_cache_limit(app, monkeypatch, cache_limit, expected_expired
775775
# `_fetch_inventory_group` calls `_fetch_inventory`.
776776
# We replace it with a mock to test whether it has been called.
777777
# If it has been called, it means the cache had expired.
778-
mock_fetch_inventory = mock.Mock(return_value=('inv', now, {}))
778+
mock_fake_inventory: Inventory = {'std:label': {}} # must be truthy
779+
mock_fetch_inventory = mock.Mock(return_value=mock_fake_inventory)
779780
monkeypatch.setattr(
780781
'sphinx.ext.intersphinx._load._fetch_inventory', mock_fetch_inventory
781782
)

0 commit comments

Comments
 (0)