|
@@ 223-251 (lines=29) @@
|
| 220 |
|
|
| 221 |
|
|
| 222 |
|
# Drawing a graph with no edge attributes for labels when with_edge_labels=True |
| 223 |
|
def test_draw_no_edge_labels_attribute(mocker): |
| 224 |
|
# Arrange |
| 225 |
|
mock_nx_draw = mocker.patch('networkx.draw') |
| 226 |
|
mock_nx_draw_edge_labels = mocker.patch('networkx.draw_networkx_edge_labels') |
| 227 |
|
mock_get_edge_attributes = mocker.patch('networkx.get_edge_attributes', return_value={}) |
| 228 |
|
mock_spring_layout = mocker.patch('networkx.spring_layout', return_value='mock_pos') |
| 229 |
|
mock_is_planar = mocker.patch('networkx.is_planar', return_value=False) |
| 230 |
|
mock_node_color_mapping = mocker.patch('graphinate.renderers.matplotlib.node_color_mapping', |
| 231 |
|
return_value={0: 'red', 1: 'blue'}) |
| 232 |
|
|
| 233 |
|
graph = nx.Graph() |
| 234 |
|
graph.add_node(0) |
| 235 |
|
graph.add_node(1) |
| 236 |
|
graph.add_edge(0, 1) # No label attribute |
| 237 |
|
|
| 238 |
|
# Act |
| 239 |
|
draw(graph, with_edge_labels=True) |
| 240 |
|
|
| 241 |
|
# Assert |
| 242 |
|
mock_is_planar.assert_called_once_with(graph) |
| 243 |
|
mock_spring_layout.assert_called_once_with(graph) |
| 244 |
|
mock_node_color_mapping.assert_called_once_with(graph) |
| 245 |
|
mock_get_edge_attributes.assert_called_once_with(graph, 'label') |
| 246 |
|
mock_nx_draw.assert_called_once() |
| 247 |
|
mock_nx_draw_edge_labels.assert_called_once() |
| 248 |
|
|
| 249 |
|
# Check that the edge_labels parameter is an empty dict |
| 250 |
|
args, kwargs = mock_nx_draw_edge_labels.call_args |
| 251 |
|
assert kwargs.get('edge_labels') == {} |
| 252 |
|
|
|
@@ 193-219 (lines=27) @@
|
| 190 |
|
|
| 191 |
|
|
| 192 |
|
# Drawing a graph with no node attributes for labels when with_node_labels=True |
| 193 |
|
def test_draw_no_node_labels_attribute(mocker): |
| 194 |
|
# Arrange |
| 195 |
|
mock_nx_draw = mocker.patch('networkx.draw') |
| 196 |
|
mock_get_node_attributes = mocker.patch('networkx.get_node_attributes', return_value={}) |
| 197 |
|
mock_spring_layout = mocker.patch('networkx.spring_layout', return_value='mock_pos') |
| 198 |
|
mock_is_planar = mocker.patch('networkx.is_planar', return_value=False) |
| 199 |
|
mock_node_color_mapping = mocker.patch('graphinate.renderers.matplotlib.node_color_mapping', |
| 200 |
|
return_value={0: 'red', 1: 'blue'}) |
| 201 |
|
|
| 202 |
|
graph = nx.Graph() |
| 203 |
|
graph.add_node(0) # No label attribute |
| 204 |
|
graph.add_node(1) # No label attribute |
| 205 |
|
graph.add_edge(0, 1) |
| 206 |
|
|
| 207 |
|
# Act |
| 208 |
|
draw(graph, with_node_labels=True) |
| 209 |
|
|
| 210 |
|
# Assert |
| 211 |
|
mock_is_planar.assert_called_once_with(graph) |
| 212 |
|
mock_spring_layout.assert_called_once_with(graph) |
| 213 |
|
mock_node_color_mapping.assert_called_once_with(graph) |
| 214 |
|
mock_get_node_attributes.assert_called_once_with(graph, 'label') |
| 215 |
|
mock_nx_draw.assert_called_once() |
| 216 |
|
|
| 217 |
|
# Check that labels parameter is empty dict |
| 218 |
|
args, kwargs = mock_nx_draw.call_args |
| 219 |
|
assert kwargs.get('labels') == {} |
| 220 |
|
|
| 221 |
|
|
| 222 |
|
# Drawing a graph with no edge attributes for labels when with_edge_labels=True |