|
@@ 85-111 (lines=27) @@
|
| 82 |
|
mock_nx_draw_edge_labels.assert_called_once() |
| 83 |
|
|
| 84 |
|
# Drawing a graph with both node and edge labels turned on |
| 85 |
|
def test_draw_with_both_labels_on(self, mocker): |
| 86 |
|
# Arrange |
| 87 |
|
mock_nx_draw = mocker.patch('networkx.draw') |
| 88 |
|
mock_nx_draw_edge_labels = mocker.patch('networkx.draw_networkx_edge_labels') |
| 89 |
|
mock_spring_layout = mocker.patch('networkx.spring_layout', return_value='mock_pos') |
| 90 |
|
mock_is_planar = mocker.patch('networkx.is_planar', return_value=False) |
| 91 |
|
mock_node_color_mapping = mocker.patch('graphinate.renderers.matplotlib.node_color_mapping', |
| 92 |
|
return_value={0: 'red', 1: 'blue'}) |
| 93 |
|
|
| 94 |
|
graph = nx.Graph() |
| 95 |
|
graph.add_node(0, label='Node0') |
| 96 |
|
graph.add_node(1, label='Node1') |
| 97 |
|
graph.add_edge(0, 1, label='Edge0-1') |
| 98 |
|
|
| 99 |
|
# Act |
| 100 |
|
draw(graph, with_node_labels=True, with_edge_labels=True) |
| 101 |
|
|
| 102 |
|
# Assert |
| 103 |
|
mock_is_planar.assert_called_once_with(graph) |
| 104 |
|
mock_spring_layout.assert_called_once_with(graph) |
| 105 |
|
mock_node_color_mapping.assert_called_once_with(graph) |
| 106 |
|
mock_nx_draw.assert_called_once() |
| 107 |
|
mock_nx_draw_edge_labels.assert_called_once() |
| 108 |
|
|
| 109 |
|
# Check that node labels are enabled |
| 110 |
|
args, kwargs = mock_nx_draw.call_args |
| 111 |
|
assert kwargs.get('with_labels') is True |
| 112 |
|
|
| 113 |
|
# Drawing a planar graph uses planar_layout first |
| 114 |
|
def test_draw_planar_graph(self, mocker): |
|
@@ 34-57 (lines=24) @@
|
| 31 |
|
mock_nx_draw_edge_labels.assert_not_called() |
| 32 |
|
|
| 33 |
|
# Drawing a graph with node labels turned off |
| 34 |
|
def test_draw_with_node_labels_off(self, mocker): |
| 35 |
|
# Arrange |
| 36 |
|
mock_nx_draw = mocker.patch('networkx.draw') |
| 37 |
|
mock_spring_layout = mocker.patch('networkx.spring_layout', return_value='mock_pos') |
| 38 |
|
mock_is_planar = mocker.patch('networkx.is_planar', return_value=False) |
| 39 |
|
mock_node_color_mapping = mocker.patch('graphinate.renderers.matplotlib.node_color_mapping', |
| 40 |
|
return_value={0: 'red', 1: 'blue'}) |
| 41 |
|
|
| 42 |
|
graph = nx.Graph() |
| 43 |
|
graph.add_node(0, label='Node0') |
| 44 |
|
graph.add_node(1, label='Node1') |
| 45 |
|
graph.add_edge(0, 1) |
| 46 |
|
|
| 47 |
|
# Act |
| 48 |
|
draw(graph, with_node_labels=False) |
| 49 |
|
|
| 50 |
|
# Assert |
| 51 |
|
mock_is_planar.assert_called_once_with(graph) |
| 52 |
|
mock_spring_layout.assert_called_once_with(graph) |
| 53 |
|
mock_node_color_mapping.assert_called_once_with(graph) |
| 54 |
|
mock_nx_draw.assert_called_once() |
| 55 |
|
# Check that 'with_labels' is not in the draw parameters |
| 56 |
|
args, kwargs = mock_nx_draw.call_args |
| 57 |
|
assert 'with_labels' not in kwargs |
| 58 |
|
|
| 59 |
|
# Drawing a graph with edge labels turned on |
| 60 |
|
def test_draw_with_edge_labels_on(self, mocker): |