Skip to content

Commit d6b78aa

Browse files
committed
[#1397] allow graphviz tests without dot installed
Update the Graphviz message-flow tests so CI environments without the Graphviz dot executable still exercise a positive code path instead of skipping. The renderer test now validates DOT output when dot is absent, and the scenario helper tests explicitly cover both the available and unavailable Graphviz paths. This avoids pytest-error-for-skips turning optional Graphviz coverage into CI failures on platforms where dot is not installed.
1 parent 219faa4 commit d6b78aa

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

src/utilities/tests/test_SimulationBaseClass.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,7 @@ def test_GetMessageConnectionDot_contains_graphviz_edges():
204204

205205

206206
def test_ShowMessageConnectionFigure_graphviz_writes_file(tmp_path):
207-
"""Check that the Graphviz renderer writes a rendered file when available."""
208-
if shutil.which("dot") is None:
209-
pytest.skip("Graphviz dot executable is not available.")
210-
207+
"""Check that the Graphviz renderer writes an output file."""
211208
scSim = SimulationBaseClass.SimBaseClass()
212209
testProcess = scSim.CreateNewProcess("testProcess")
213210
simulationTimeStep = macros.sec2nano(1.0) # [ns]
@@ -222,23 +219,28 @@ def test_ShowMessageConnectionFigure_graphviz_writes_file(tmp_path):
222219
scSim.AddModelToTask("testTask", cModule)
223220
scSim.AddModelToTask("testTask", cppModule)
224221

225-
outputPath = tmp_path / "messageConnections.svg"
222+
graphvizIsAvailable = shutil.which("dot") is not None
223+
outputPath = tmp_path / (
224+
"messageConnections.svg" if graphvizIsAvailable else "messageConnections.dot"
225+
)
226226
renderedPath = scSim.ShowMessageConnectionFigure(
227227
renderer="graphviz",
228228
fileName=str(outputPath),
229+
graphvizFormat="svg" if graphvizIsAvailable else "dot",
229230
includeUnlinked=False,
230231
)
231232

232233
assert renderedPath == str(outputPath)
233234
assert outputPath.exists()
234-
assert outputPath.read_text().lstrip().startswith("<?xml")
235+
outputText = outputPath.read_text()
236+
if graphvizIsAvailable:
237+
assert outputText.lstrip().startswith("<?xml")
238+
else:
239+
assert "digraph BSKMessageConnections" in outputText
235240

236241

237242
def test_saveScenarioGraphvizFigure_uses_documentation_image_path(tmp_path):
238243
"""Check that Graphviz scenario figures are saved to the docs image path."""
239-
if shutil.which("dot") is None:
240-
pytest.skip("Graphviz dot executable is not available.")
241-
242244
docsPath = tmp_path / "docs" / "source"
243245
docsPath.mkdir(parents=True)
244246
scenarioPath = tmp_path / "examples"
@@ -247,12 +249,13 @@ def test_saveScenarioGraphvizFigure_uses_documentation_image_path(tmp_path):
247249
scSim = MagicMock()
248250
scSim.ShowMessageConnectionFigure.return_value = str(expectedPath)
249251

250-
renderedPath = unitTestSupport.saveScenarioGraphvizFigure(
251-
"messageFlow",
252-
scSim,
253-
str(scenarioPath),
254-
includeUnlinked=False,
255-
)
252+
with patch("Basilisk.utilities.unitTestSupport.shutil.which", return_value="dot"):
253+
renderedPath = unitTestSupport.saveScenarioGraphvizFigure(
254+
"messageFlow",
255+
scSim,
256+
str(scenarioPath),
257+
includeUnlinked=False,
258+
)
256259

257260
assert renderedPath == str(expectedPath)
258261
assert expectedPath.parent.exists()
@@ -265,7 +268,7 @@ def test_saveScenarioGraphvizFigure_uses_documentation_image_path(tmp_path):
265268
)
266269

267270

268-
def test_saveScenarioGraphvizFigure_skips_without_graphviz(tmp_path):
271+
def test_saveScenarioGraphvizFigure_returns_none_without_graphviz(tmp_path):
269272
"""Check that optional Graphviz scenario figures do not require Graphviz."""
270273
docsPath = tmp_path / "docs" / "source"
271274
docsPath.mkdir(parents=True)

0 commit comments

Comments
 (0)