clone

a browser-first diagram editor with live svg previews, local drafts and encrypted, accountless sharing

main
diagramzip / renderers / python / blockdiag-family / test / test_upstream_runtime.py
test_upstream_runtime.py 2.0K
1import importlib.metadata2import sys3from pathlib import Path45import pytest678SRC = Path(__file__).parents[1] / "src"9if str(SRC) not in sys.path:10 sys.path.insert(0, str(SRC))111213def test_registers_all_static_renderers_and_svg_without_entry_points(monkeypatch):14 """The vendored registry must not depend on installed distribution metadata."""1516 monkeypatch.setattr(17 importlib.metadata,18 "entry_points",19 lambda *args, **kwargs: pytest.fail("entry-point discovery was used"),20 )2122 from blockdiag import imagedraw, noderenderer23 import upstream_runtime2425 noderenderer.renderers.clear()26 imagedraw.drawers.clear()27 upstream_runtime.register()2829 assert "svg" in imagedraw.drawers30 for shape in (31 "actor",32 "beginpoint",33 "box",34 "circle",35 "cloud",36 "diamond",37 "dots",38 "ellipse",39 "endpoint",40 "flowchart.database",41 "flowchart.input",42 "flowchart.loopin",43 "flowchart.loopout",44 "flowchart.terminator",45 "mail",46 "minidiamond",47 "none",48 "note",49 "roundedbox",50 "square",51 "textbox",52 "_packet_node",53 ):54 assert noderenderer.get(shape) is not None, shape555657def test_static_plugin_loader_allowlists_builtins_without_entry_points(monkeypatch):58 monkeypatch.setattr(59 importlib.metadata,60 "entry_points",61 lambda *args, **kwargs: pytest.fail("entry-point discovery was used"),62 )6364 from blockdiag import plugins65 import upstream_runtime6667 upstream_runtime.register()68 plugins.loaded_plugins.clear()69 plugins.node_handlers.clear()7071 class DiagramNode:72 desctable = []73 attrname = {}7475 class Diagram:76 _DiagramNode = DiagramNode7778 plugins.load(["attributes"], diagram=Diagram())79 assert plugins.loaded_plugins == ["attributes"]80 assert plugins.node_handlers8182 with pytest.raises(AttributeError, match="unknown plugin: third_party"):83 plugins.load(["third_party"], diagram=Diagram())