-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathtest_graph.py
More file actions
199 lines (172 loc) · 6.86 KB
/
test_graph.py
File metadata and controls
199 lines (172 loc) · 6.86 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import unittest
from igraph import Graph, plot, VertexClustering
# FIXME: find a better way to do this that works for both direct call and module
# import e.g. tox
try:
from .utils import find_image_comparison
except ImportError:
from utils import find_image_comparison
try:
import plotly
except ImportError:
plotly = None
if plotly is not None:
from plotly import graph_objects as go
image_comparison = find_image_comparison()
class GraphTestRunner(unittest.TestCase):
def setUp(self):
if plotly is None:
raise unittest.SkipTest("plotly not found, skipping tests")
@property
def layout_small_ring(self):
coords = [
[1.015318095035966, 0.03435580194714975],
[0.29010409851547664, 1.0184451153265959],
[-0.8699239050738742, 0.6328259400443561],
[-0.8616466426732888, -0.5895891303732176],
[0.30349699041342515, -0.9594640169691343],
]
return coords
@image_comparison(baseline_images=["graph_basic"])
def test_basic(self):
g = Graph.Ring(5)
fig = go.Figure()
plot(g, target=fig, layout=self.layout_small_ring)
return fig
@image_comparison(baseline_images=["graph_directed"])
def test_directed(self):
g = Graph.Ring(5, directed=True)
fig = go.Figure()
plot(g, target=fig, layout=self.layout_small_ring)
return fig
@image_comparison(baseline_images=["graph_mark_groups_directed"])
def test_mark_groups(self):
g = Graph.Ring(5, directed=True)
fig = go.Figure()
plot(g, target=fig, mark_groups=True, layout=self.layout_small_ring)
return fig
@image_comparison(baseline_images=["graph_mark_groups_squares_directed"])
def test_mark_groups_squares(self):
g = Graph.Ring(5, directed=True)
fig = go.Figure()
plot(
g,
target=fig,
mark_groups=True,
vertex_shape="square",
layout=self.layout_small_ring,
)
return fig
@image_comparison(baseline_images=["graph_edit_children"])
def test_graph_edit_children(self):
g = Graph.Ring(5)
fig = go.Figure()
plot(g, target=fig, vertex_shape="circle", layout=self.layout_small_ring)
# FIXME
# dot = ax.get_children()[0]
# dot.set_facecolor("blue")
# dot.radius *= 0.5
return fig
@image_comparison(baseline_images=["graph_null"])
def test_null_graph(self):
g = Graph()
fig = go.Figure()
plot(g, target=fig)
return fig
class ClusteringTestRunner(unittest.TestCase):
def setUp(self):
if plotly is None:
raise unittest.SkipTest("plotly not found, skipping tests")
@property
def layout_small_ring(self):
coords = [
[1.015318095035966, 0.03435580194714975],
[0.29010409851547664, 1.0184451153265959],
[-0.8699239050738742, 0.6328259400443561],
[-0.8616466426732888, -0.5895891303732176],
[0.30349699041342515, -0.9594640169691343],
]
return coords
@property
def layout_large_ring(self):
coords = [
(2.5, 0.0),
(2.4802867532861947, 0.31333308391076065),
(2.4214579028215777, 0.621724717912137),
(2.324441214720628, 0.9203113817116949),
(2.190766700109659, 1.2043841852542883),
(2.0225424859373686, 1.469463130731183),
(1.822421568553529, 1.7113677648217218),
(1.5935599743717241, 1.926283106939473),
(1.3395669874474914, 2.110819813755038),
(1.0644482289126818, 2.262067631165049),
(0.7725424859373686, 2.3776412907378837),
(0.4684532864643113, 2.4557181268217216),
(0.15697629882328326, 2.495066821070679),
(-0.1569762988232835, 2.495066821070679),
(-0.46845328646431206, 2.4557181268217216),
(-0.7725424859373689, 2.3776412907378837),
(-1.0644482289126818, 2.2620676311650487),
(-1.3395669874474923, 2.1108198137550374),
(-1.5935599743717244, 1.926283106939473),
(-1.8224215685535292, 1.7113677648217211),
(-2.022542485937368, 1.4694631307311832),
(-2.190766700109659, 1.204384185254288),
(-2.3244412147206286, 0.9203113817116944),
(-2.4214579028215777, 0.621724717912137),
(-2.4802867532861947, 0.3133330839107602),
(-2.5, -8.040613248383183e-16),
(-2.4802867532861947, -0.3133330839107607),
(-2.4214579028215777, -0.6217247179121376),
(-2.324441214720628, -0.9203113817116958),
(-2.1907667001096587, -1.2043841852542885),
(-2.022542485937368, -1.4694631307311834),
(-1.822421568553529, -1.7113677648217218),
(-1.5935599743717237, -1.9262831069394735),
(-1.339566987447491, -2.1108198137550382),
(-1.0644482289126804, -2.2620676311650496),
(-0.7725424859373689, -2.3776412907378837),
(-0.46845328646431156, -2.4557181268217216),
(-0.156976298823283, -2.495066821070679),
(0.1569762988232843, -2.495066821070679),
(0.46845328646431283, -2.4557181268217216),
(0.7725424859373681, -2.377641290737884),
(1.0644482289126815, -2.262067631165049),
(1.3395669874474918, -2.1108198137550374),
(1.593559974371725, -1.9262831069394726),
(1.8224215685535297, -1.7113677648217207),
(2.0225424859373695, -1.4694631307311814),
(2.190766700109659, -1.2043841852542883),
(2.3244412147206286, -0.9203113817116947),
(2.421457902821578, -0.6217247179121362),
(2.4802867532861947, -0.3133330839107595),
]
return coords
@image_comparison(baseline_images=["clustering_directed"])
def test_clustering_directed_small(self):
g = Graph.Ring(5, directed=True)
clu = VertexClustering(g, [0] * 5)
fig = go.Figure()
plot(clu, target=fig, mark_groups=True, layout=self.layout_small_ring)
return fig
@image_comparison(baseline_images=["clustering_directed_large"])
def test_clustering_directed_large(self):
g = Graph.Ring(50, directed=True)
clu = VertexClustering(g, [0] * 3 + [1] * 17 + [2] * 30)
fig = go.Figure()
plot(clu, layout=self.layout_large_ring, target=fig, mark_groups=True)
return fig
def suite():
graph = unittest.defaultTestLoader.loadTestsFromTestCase(GraphTestRunner)
clustering = unittest.defaultTestLoader.loadTestsFromTestCase(ClusteringTestRunner)
return unittest.TestSuite(
[
graph,
clustering,
]
)
def test():
runner = unittest.TextTestRunner()
runner.run(suite())
if __name__ == "__main__":
test()