Code Duplication    Length = 23-23 lines in 3 locations

tests/graphinate/renderers/test_matplotlib_plot.py 3 locations

@@ 57-79 (lines=23) @@
54
55
56
# Plot a graph with neither node nor edge labels displayed
57
def test_plot_without_node_and_edge_labels(mocker):
58
    # Arrange
59
    mock_draw = mocker.patch('graphinate.renderers.matplotlib.draw')
60
    mock_pyplot = mocker.patch('graphinate.renderers.matplotlib.pyplot')
61
    mock_ax = mocker.MagicMock()
62
    mock_fig = mocker.MagicMock()
63
    mock_pyplot.gca.return_value = mock_ax
64
    mock_pyplot.gcf.return_value = mock_fig
65
66
    graph = nx.Graph(name="Test Graph")
67
    graph.add_node(1, label="Node 1")
68
    graph.add_edge(1, 2, label="Edge 1-2")
69
70
    # Act
71
    from graphinate.renderers.matplotlib import plot
72
    plot(graph, with_node_labels=False, with_edge_labels=False)
73
74
    # Assert
75
    mock_draw.assert_called_once_with(graph, False, False)
76
    mock_ax.margins.assert_called_once_with(0.10)
77
    mock_fig.suptitle.assert_called_once_with("Test Graph")
78
    mock_fig.tight_layout.assert_called_once()
79
    mock_pyplot.show.assert_called_once()
80
81
82
# Plot a graph with custom kwargs that are passed to the draw function
@@ 31-53 (lines=23) @@
28
29
30
# Plot a graph with both node and edge labels displayed
31
def test_plot_with_node_and_edge_labels(mocker):
32
    # Arrange
33
    mock_draw = mocker.patch('graphinate.renderers.matplotlib.draw')
34
    mock_pyplot = mocker.patch('graphinate.renderers.matplotlib.pyplot')
35
    mock_ax = mocker.MagicMock()
36
    mock_fig = mocker.MagicMock()
37
    mock_pyplot.gca.return_value = mock_ax
38
    mock_pyplot.gcf.return_value = mock_fig
39
40
    graph = nx.Graph(name="Test Graph")
41
    graph.add_node(1, label="Node 1")
42
    graph.add_edge(1, 2, label="Edge 1-2")
43
44
    # Act
45
    from graphinate.renderers.matplotlib import plot
46
    plot(graph, with_node_labels=True, with_edge_labels=True)
47
48
    # Assert
49
    mock_draw.assert_called_once_with(graph, True, True)
50
    mock_ax.margins.assert_called_once_with(0.10)
51
    mock_fig.suptitle.assert_called_once_with("Test Graph")
52
    mock_fig.tight_layout.assert_called_once()
53
    mock_pyplot.show.assert_called_once()
54
55
56
# Plot a graph with neither node nor edge labels displayed
@@ 5-27 (lines=23) @@
2
3
4
# Plot a simple graph with default parameters (node labels shown, edge labels hidden)
5
def test_plot_with_default_parameters(mocker):
6
    # Arrange
7
    mock_draw = mocker.patch('graphinate.renderers.matplotlib.draw')
8
    mock_pyplot = mocker.patch('graphinate.renderers.matplotlib.pyplot')
9
    mock_ax = mocker.MagicMock()
10
    mock_fig = mocker.MagicMock()
11
    mock_pyplot.gca.return_value = mock_ax
12
    mock_pyplot.gcf.return_value = mock_fig
13
14
    graph = nx.Graph(name="Test Graph")
15
    graph.add_node(1, label="Node 1")
16
    graph.add_edge(1, 2, label="Edge 1-2")
17
18
    # Act
19
    from graphinate.renderers.matplotlib import plot
20
    plot(graph)
21
22
    # Assert
23
    mock_draw.assert_called_once_with(graph, True, False)
24
    mock_ax.margins.assert_called_once_with(0.10)
25
    mock_fig.suptitle.assert_called_once_with("Test Graph")
26
    mock_fig.tight_layout.assert_called_once()
27
    mock_pyplot.show.assert_called_once()
28
29
30
# Plot a graph with both node and edge labels displayed