v0.5.3
- Мелкие исправления увеличивающие работу конвертера
This commit is contained in:
@@ -112,6 +112,7 @@ def test_write_dfd_outputs_uses_local_or_kroki(tmp_path):
|
||||
return True
|
||||
|
||||
with patch("md2gost.dfd._compile_dot", return_value=(fake_dot, False)), \
|
||||
patch("md2gost.dfd._render_dot_local_combined", return_value=set()), \
|
||||
patch("md2gost.dfd._render_dot_local", side_effect=fake_local), \
|
||||
patch("md2gost.dfd._render_dot_kroki", return_value=False):
|
||||
assert write_dfd_outputs(SAMPLE_LEVEL0, png, svg, scale=1)
|
||||
@@ -119,6 +120,64 @@ def test_write_dfd_outputs_uses_local_or_kroki(tmp_path):
|
||||
assert "Клиент" in svg.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_write_dfd_outputs_one_graphviz_run_for_both_formats(tmp_path):
|
||||
"""PNG + SVG come from a single Graphviz process; no per-format retry."""
|
||||
png = tmp_path / "a.png"
|
||||
svg = tmp_path / "a.svg"
|
||||
single = []
|
||||
|
||||
def fake_combined(dot, targets, *, context):
|
||||
for out_path, fmt in targets:
|
||||
Path(out_path).write_bytes(
|
||||
b"\x89PNG\r\n\x1a\n" + b"\x00" * 32 if fmt == "png" else b"<svg/>"
|
||||
)
|
||||
return {fmt for _, fmt in targets}
|
||||
|
||||
with patch("md2gost.dfd._compile_dot", return_value=("digraph G {}", False)), \
|
||||
patch("md2gost.dfd._render_dot_local_combined", side_effect=fake_combined), \
|
||||
patch("md2gost.dfd._render_dot_local", side_effect=lambda *a, **k: single.append(a) or True), \
|
||||
patch("md2gost.dfd._render_dot_kroki", return_value=False):
|
||||
assert write_dfd_outputs(SAMPLE_LEVEL0, png, svg, scale=1)
|
||||
assert single == []
|
||||
assert png.read_bytes().startswith(b"\x89PNG")
|
||||
assert svg.read_bytes().startswith(b"<svg")
|
||||
|
||||
|
||||
def test_write_dfd_outputs_retries_format_missed_by_combined(tmp_path):
|
||||
"""If the combined run only produced PNG, SVG still goes through the old path."""
|
||||
png = tmp_path / "a.png"
|
||||
svg = tmp_path / "a.svg"
|
||||
retried = []
|
||||
|
||||
def fake_combined(dot, targets, *, context):
|
||||
for out_path, fmt in targets:
|
||||
if fmt == "png":
|
||||
Path(out_path).write_bytes(b"\x89PNG\r\n\x1a\n" + b"\x00" * 32)
|
||||
return {"png"}
|
||||
|
||||
def fake_local(dot, out_path, fmt, *, context):
|
||||
retried.append(fmt)
|
||||
Path(out_path).write_bytes(b"<svg/>")
|
||||
return True
|
||||
|
||||
with patch("md2gost.dfd._compile_dot", return_value=("digraph G {}", False)), \
|
||||
patch("md2gost.dfd._render_dot_local_combined", side_effect=fake_combined), \
|
||||
patch("md2gost.dfd._render_dot_local", side_effect=fake_local), \
|
||||
patch("md2gost.dfd._render_dot_kroki", return_value=False):
|
||||
assert write_dfd_outputs(SAMPLE_LEVEL0, png, svg, scale=1)
|
||||
assert retried == ["svg"]
|
||||
assert svg.read_bytes().startswith(b"<svg")
|
||||
|
||||
|
||||
def test_render_dot_local_combined_single_target_is_noop():
|
||||
from md2gost.dfd import _render_dot_local_combined
|
||||
|
||||
with patch("md2gost.dfd.resolve_graphviz_engine") as resolve:
|
||||
assert _render_dot_local_combined("digraph G {}", [(Path("a.png"), "png")],
|
||||
context=False) == set()
|
||||
resolve.assert_not_called()
|
||||
|
||||
|
||||
def test_write_dfd_outputs_falls_back_to_kroki(tmp_path):
|
||||
png = tmp_path / "a.png"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user