Skip to content

Commit

Permalink
Fix coverage (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep authored Jan 21, 2025
1 parent eeb1db1 commit e07fb09
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/scanpydoc/elegant_typehints/_role_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __getitem__(self, key: tuple[str | None, str]) -> tuple[str | None, str]:
raise KeyError(key)

def __contains__(self, key: object) -> bool:
if not isinstance(key, tuple):
if not isinstance(key, tuple): # pragma: no cover
raise TypeError
try:
self[key]
Expand All @@ -69,5 +69,5 @@ def __delitem__(self, key: tuple[str | None, str]) -> None:
def __iter__(self) -> Iterator[tuple[str | None, str]]:
return self.data.__iter__()

def __len__(self) -> int:
def __len__(self) -> int: # pragma: no cover
return len(self.data)
12 changes: 8 additions & 4 deletions tests/test_elegant_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def app(make_app_setup: MakeApp) -> Sphinx:
"testmod.Class": "test.Class",
"testmod.SubCl": "test.SubCl",
"testmod.Excep": "test.Excep",
"testmod.Excep2": "test.Excep2",
"testmod.Excep2": ("py:exc", "test.Excep2"),
"testmod.Gen": "test.Gen",
},
)
Expand Down Expand Up @@ -248,7 +248,11 @@ def fn_test(m: object) -> None: # pragma: no cover
]


def test_resolve(app: Sphinx) -> None:
@pytest.mark.parametrize(
("qualname", "docname"),
[("testmod.Class", "test.Class"), ("testmod.Excep2", "test.Excep2")],
)
def test_resolve(app: Sphinx, qualname: str, docname: str) -> None:
"""Test that qualname_overrides affects _last_resolve as expected."""
from docutils.nodes import TextElement, reference
from sphinx.addnodes import pending_xref
Expand All @@ -258,10 +262,10 @@ def test_resolve(app: Sphinx) -> None:

# Inventory contains documented name
InventoryAdapter(app.env).main_inventory["py:class"] = {
"test.Class": ("TestProj", "1", "https://x.com", "Class"),
docname: ("TestProj", "1", "https://x.com", docname.split(".")[-1]),
}
# Node contains name from code
node = pending_xref(refdomain="py", reftarget="testmod.Class", reftype="class")
node = pending_xref(refdomain="py", reftarget=qualname, reftype="class")

resolved = _last_resolve(app, app.env, node, TextElement())
assert isinstance(resolved, reference)
Expand Down

0 comments on commit e07fb09

Please sign in to comment.