Passed
Push — main ( 162760...d261f2 )
by Eran
01:41
created

test_mermaid_builder__with_all_parameters()   A

Complexity

Conditions 1

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 26
rs 9.55
c 0
b 0
f 0
cc 1
nop 0
1
import networkx_mermaid as nxm
2
3
import graphinate
4
from graphinate import GraphType
5
from graphinate.builders import MermaidBuilder
6
7
8
def test_mermaid_builder__empty_model():
9
    """Test MermaidBuilder with empty model"""
10
    # arrange
11
    name = "Empty Mermaid"
12
    graph_model = graphinate.model(name=name)
13
14
    # act
15
    builder = MermaidBuilder(graph_model)
16
    result = builder.build()
17
18
    # assert
19
    assert isinstance(result, str)
20
    assert name in result
21
22
23
def test_mermaid_builder__with_graph_type():
24
    """Test MermaidBuilder with specific graph type"""
25
    # arrange
26
    name = "DiGraph Mermaid"
27
    graph_model = graphinate.model(name=name)
28
29
    @graph_model.edge()
30
    def edge():
31
        for i in range(3):
32
            yield {'source': i, 'target': i + 1}
33
34
    # act
35
    builder = MermaidBuilder(graph_model, graph_type=GraphType.DiGraph)
36
    result = builder.build()
37
38
    # assert
39
    assert isinstance(result, str)
40
    assert name in result
41
42
43
def test_mermaid_builder__with_orientation():
44
    """Test MermaidBuilder with different orientations"""
45
    # arrange
46
    graph_model = graphinate.model(name="Oriented")
47
48
    @graph_model.edge()
49
    def edge():
50
        yield {'source': 'A', 'target': 'B'}
51
52
    # act
53
    builder = MermaidBuilder(graph_model)
54
    result_lr = builder.build(orientation=nxm.DiagramOrientation.LEFT_RIGHT)
55
    result_td = builder.build(orientation=nxm.DiagramOrientation.TOP_DOWN)
56
57
    # assert
58
    assert isinstance(result_lr, str)
59
    assert isinstance(result_td, str)
60
61
62
def test_mermaid_builder__with_node_shape():
63
    """Test MermaidBuilder with different node shapes"""
64
    # arrange
65
    graph_model = graphinate.model(name="Shaped")
66
67
    @graph_model.node()
68
    def node():
69
        yield 'A'
70
        yield 'B'
71
72
    # act
73
    builder = MermaidBuilder(graph_model)
74
    result_default = builder.build(node_shape=nxm.DiagramNodeShape.DEFAULT)
75
    result_circle = builder.build(node_shape=nxm.DiagramNodeShape.CIRCLE)
76
77
    # assert
78
    assert isinstance(result_default, str)
79
    assert isinstance(result_circle, str)
80
81
82
def test_mermaid_builder__with_title():
83
    """Test MermaidBuilder with custom title"""
84
    # arrange
85
    graph_model = graphinate.model(name="Graph")
86
87
    @graph_model.node()
88
    def node():
89
        yield 'X'
90
91
    # act
92
    builder = MermaidBuilder(graph_model)
93
    result_with_title = builder.build(title="Custom Title")
94
    result_empty_title = builder.build(title="")
95
    result_no_title = builder.build(title=None)
96
97
    # assert
98
    assert isinstance(result_with_title, str)
99
    assert "Custom Title" in result_with_title
100
    assert isinstance(result_empty_title, str)
101
    assert isinstance(result_no_title, str)
102
103
104
def test_mermaid_builder__with_edge_labels():
105
    """Test MermaidBuilder with edge labels"""
106
    # arrange
107
    graph_model = graphinate.model(name="Labeled")
108
109
    @graph_model.edge()
110
    def edge():
111
        yield {'source': 'A', 'target': 'B', 'label': 'edge1'}
112
113
    # act
114
    builder = MermaidBuilder(graph_model)
115
    result_without_labels = builder.build(with_edge_labels=False)
116
    result_with_labels = builder.build(with_edge_labels=True)
117
118
    # assert
119
    assert isinstance(result_without_labels, str)
120
    assert isinstance(result_with_labels, str)
121
122
123
def test_mermaid_builder__octagonal_graph(octagonal_graph_model):
124
    """Test MermaidBuilder with the octagonal graph"""
125
    # act
126
    builder = MermaidBuilder(octagonal_graph_model)
127
    result = builder.build()
128
129
    # assert
130
    assert isinstance(result, str)
131
    assert "Octagonal Graph" in result
132
133
134
def test_mermaid_builder__map_graph_model(map_graph_model):
135
    """Test MermaidBuilder with a complex map graph model"""
136
    # arrange
137
    _country_count, _city_count, graph_model = map_graph_model
138
139
    # act
140
    builder = MermaidBuilder(graph_model)
141
    result = builder.build()
142
143
    # assert
144
    assert isinstance(result, str)
145
    assert "Map" in result
146
147
148
def test_mermaid_builder__with_all_parameters():
149
    """Test MermaidBuilder with all parameters"""
150
    # arrange
151
    graph_model = graphinate.model(name="Complete")
152
153
    @graph_model.node()
154
    def node():
155
        yield 'node1'
156
        yield 'node2'
157
158
    @graph_model.edge()
159
    def edge():
160
        yield {'source': 'node1', 'target': 'node2', 'label': 'connects'}
161
162
    # act
163
    builder = MermaidBuilder(graph_model, graph_type=GraphType.DiGraph)
164
    result = builder.build(
165
        orientation=nxm.DiagramOrientation.TOP_DOWN,
166
        node_shape=nxm.DiagramNodeShape.CIRCLE,
167
        title="Full Test",
168
        with_edge_labels=True
169
    )
170
171
    # assert
172
    assert isinstance(result, str)
173
    assert "Full Test" in result
174