@@ -103,3 +103,86 @@ def test_color_nodes_default() -> None:
103
103
assert VG .nodes [1 ].color == Color (neo4j_colors [1 ])
104
104
assert VG .nodes [2 ].color == Color (neo4j_colors [1 ])
105
105
assert VG .nodes [3 ].color == Color (neo4j_colors [2 ])
106
+
107
+
108
+ def test_color_nodes_lists () -> None :
109
+ nodes = [
110
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:0" , caption = "Person" , labels = ["Person" ]),
111
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:6" , caption = "Product" , labels = ["Product" ]),
112
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:11" , caption = "Product" , labels = ["Product" ]),
113
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:1" , caption = "Both" , labels = ["Person" , "Product" ]),
114
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:2" , caption = "Both again" , labels = ["Person" , "Product" ]),
115
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:3" , caption = "Both reorder" , labels = ["Product" , "Person" ]),
116
+ ]
117
+
118
+ VG = VisualizationGraph (nodes = nodes , relationships = [])
119
+
120
+ VG .color_nodes ("labels" , ["#000000" , "#00FF00" , "#FF0000" , "#0000FF" ])
121
+
122
+ assert VG .nodes [0 ].color == Color ("#000000" )
123
+ assert VG .nodes [1 ].color == Color ("#00ff00" )
124
+ assert VG .nodes [2 ].color == Color ("#00ff00" )
125
+ assert VG .nodes [3 ].color == Color ("#ff0000" )
126
+ assert VG .nodes [4 ].color == Color ("#ff0000" )
127
+ assert VG .nodes [5 ].color == Color ("#0000ff" )
128
+
129
+
130
+ def test_color_nodes_sets () -> None :
131
+ nodes = [
132
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:0" , caption = "Person" , labels = {"Person" }),
133
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:6" , caption = "Product" , labels = {"Product" }),
134
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:11" , caption = "Product" , labels = {"Product" }),
135
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:1" , caption = "Both" , labels = {"Person" , "Product" }),
136
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:2" , caption = "Both again" , labels = {"Person" , "Product" }),
137
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:3" , caption = "Both reorder" , labels = {"Product" , "Person" }),
138
+ ]
139
+
140
+ VG = VisualizationGraph (nodes = nodes , relationships = [])
141
+
142
+ VG .color_nodes ("labels" , ["#000000" , "#00FF00" , "#FF0000" , "#0000FF" ])
143
+
144
+ assert VG .nodes [0 ].color == Color ("#000000" )
145
+ assert VG .nodes [1 ].color == Color ("#00ff00" )
146
+ assert VG .nodes [2 ].color == Color ("#00ff00" )
147
+ assert VG .nodes [3 ].color == Color ("#ff0000" )
148
+ assert VG .nodes [4 ].color == Color ("#ff0000" )
149
+ assert VG .nodes [4 ].color == Color ("#ff0000" )
150
+
151
+
152
+ def test_color_nodes_dicts () -> None :
153
+ nodes = [
154
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:0" , caption = "Person" , config = {"age" : 18 }),
155
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:6" , caption = "Product" , config = {"price" : 100 }),
156
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:11" , caption = "Product" , config = {"price" : 100 }),
157
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:1" , caption = "Product" , config = {"price" : 1 }),
158
+ ]
159
+
160
+ VG = VisualizationGraph (nodes = nodes , relationships = [])
161
+
162
+ VG .color_nodes ("config" , ["#000000" , "#00FF00" , "#FF0000" , "#0000FF" ])
163
+
164
+ assert VG .nodes [0 ].color == Color ("#000000" )
165
+ assert VG .nodes [1 ].color == Color ("#00ff00" )
166
+ assert VG .nodes [2 ].color == Color ("#00ff00" )
167
+ assert VG .nodes [3 ].color == Color ("#ff0000" )
168
+
169
+
170
+ def test_color_nodes_unhashable () -> None :
171
+ nodes = [
172
+ Node (
173
+ id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:0" ,
174
+ caption = "Person" ,
175
+ config = {"movies" : ["Star Wars" , "Star Trek" ]},
176
+ ),
177
+ ]
178
+ VG = VisualizationGraph (nodes = nodes , relationships = [])
179
+
180
+ with pytest .raises (ValueError , match = "Unable to color nodes by unhashable property type '<class 'dict'>'" ):
181
+ VG .color_nodes ("config" , ["#000000" ])
182
+
183
+ nodes = [
184
+ Node (id = "4:d09f48a4-5fca-421d-921d-a30a896c604d:0" , caption = "Person" , list_of_lists = [[1 , 2 ], [3 , 4 ]]),
185
+ ]
186
+ VG = VisualizationGraph (nodes = nodes , relationships = [])
187
+ with pytest .raises (ValueError , match = "Unable to color nodes by unhashable property type '<class 'list'>'" ):
188
+ VG .color_nodes ("list_of_lists" , ["#000000" ])
0 commit comments