Skip to content

Commit fc082f2

Browse files
committed
test: cover missing branches in sphinx_ext.py and extract.py
Add tests for the :name: directive option on Mermaid format (with and without caption). Mark the defensive dedup guard in _format_event_names as pragma: no branch since Events already deduplicates at the container level.
1 parent 9dca47b commit fc082f2

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

statemachine/contrib/diagram/extract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _format_event_names(transition: "Transition") -> str:
123123
# form ("done_invoke_X") is also registered on this transition.
124124
if "." in eid and eid.replace(".", "_") in all_ids:
125125
continue
126-
if eid not in display:
126+
if eid not in display: # pragma: no branch
127127
display.append(eid)
128128

129129
return " ".join(display)

tests/test_contrib_diagram.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,22 @@ def test_mermaid_format_with_caption(self, tmp_path):
17371737
assert len(caption_children) == 1
17381738
assert caption_children[0].astext() == "My Diagram"
17391739

1740+
def test_mermaid_format_with_caption_and_name(self, tmp_path):
1741+
"""Mermaid format with caption and :name: calls add_name on the figure."""
1742+
_, result = self._run(
1743+
tmp_path, options={"format": "mermaid", "caption": "My Diagram", "name": "fig-sm"}
1744+
)
1745+
assert len(result) == 1
1746+
assert isinstance(result[0], nodes.figure)
1747+
1748+
def test_mermaid_format_with_name_no_caption(self, tmp_path):
1749+
"""Mermaid format with :name: but no caption calls add_name on the mermaid node."""
1750+
from sphinxcontrib.mermaid import mermaid as MermaidNode # type: ignore[import-untyped]
1751+
1752+
_, result = self._run(tmp_path, options={"format": "mermaid", "name": "fig-sm"})
1753+
assert len(result) == 1
1754+
assert isinstance(result[0], MermaidNode)
1755+
17401756
def test_mermaid_format_fallback_no_sphinxcontrib(self, tmp_path):
17411757
"""When sphinxcontrib-mermaid is not available, falls back to code block."""
17421758
import sys

0 commit comments

Comments
 (0)