generated from funnyzak/pyproject-starter
-
Notifications
You must be signed in to change notification settings - Fork 12
/
test_d2_diagram.py
63 lines (49 loc) · 1.99 KB
/
test_d2_diagram.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
from py_d2.connection import D2Connection
from py_d2.diagram import D2Diagram
from py_d2.shape import D2Shape
from py_d2.style import D2Style
def test_d2_diagram():
diagram = D2Diagram()
assert str(diagram) == ""
def test_d2_diagram_one_shape():
diagram = D2Diagram()
diagram.add_shape(D2Shape(name="shape_name"))
assert str(diagram) == "shape_name"
def test_d2_diagram_two_shapes():
shapes = [D2Shape(name="shape_name1"), D2Shape(name="shape_name2")]
diagram = D2Diagram(shapes=shapes)
assert str(diagram) == "\n".join(["shape_name1", "shape_name2"])
def test_d2_diagram_one_connection():
shapes = [D2Shape(name="shape_name1"), D2Shape(name="shape_name2")]
connections = [D2Connection(shape_1="shape_name1", shape_2="shape_name2")]
diagram = D2Diagram(shapes=shapes, connections=connections)
assert str(diagram) == "\n".join(["shape_name1", "shape_name2", "shape_name1 -> shape_name2"])
def test_d2_diagram_one_connection_imperative_connection():
diagram = D2Diagram()
diagram.add_shape(D2Shape(name="shape_name1"))
diagram.add_shape(D2Shape(name="shape_name2"))
diagram.add_connection(D2Connection(shape_1="shape_name1", shape_2="shape_name2"))
assert str(diagram) == "\n".join(["shape_name1", "shape_name2", "shape_name1 -> shape_name2"])
def test_d2_diagram_one_connection_with_style():
shapes = [
D2Shape(name="shape_name1", style=D2Style(fill="red")),
D2Shape(name="shape_name2", style=D2Style(fill="blue")),
]
connections = [D2Connection(shape_1="shape_name1", shape_2="shape_name2")]
diagram = D2Diagram(shapes=shapes, connections=connections)
assert str(diagram) == "\n".join(
[
"shape_name1: {",
" style: {",
" fill: red",
" }",
"}",
"shape_name2: {",
" style: {",
" fill: blue",
" }",
"}",
"shape_name1 -> shape_name2",
]
)