Skip to content

Commit

Permalink
update tests for new edges
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhi committed Oct 1, 2020
1 parent 8d247fd commit df87be6
Showing 1 changed file with 35 additions and 36 deletions.
71 changes: 35 additions & 36 deletions ipycytoscape/tests/test_graph_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def compare_nodes(expected_nodes, actual_nodes):
def compare_edges(expected_edges, actual_edges):
for expected, actual in zip(expected_edges, actual_edges):
assert expected.data == actual.data
assert expected.position == actual.position
assert expected.classes == actual.classes

class TestNetworkx:
Expand All @@ -46,16 +45,16 @@ def test_lonely_nodes(self):
Node(data={'id': 'unconnected_node'}, position={})
]
expected_edges = [
Edge(data={'source': '0', 'target': '1'}, position={}),
Edge(data={'source': '0', 'target': '2'}, position={}),
Edge(data={'source': '0', 'target': '3'}, position={}),
Edge(data={'source': '0', 'target': '4'}, position={}),
Edge(data={'source': '1', 'target': '2'}, position={}),
Edge(data={'source': '1', 'target': '3'}, position={}),
Edge(data={'source': '1', 'target': '4'}, position={}),
Edge(data={'source': '2', 'target': '3'}, position={}),
Edge(data={'source': '2', 'target': '4'}, position={}),
Edge(data={'source': '3', 'target': '4'}, position={})
Edge(data={'source': '0', 'target': '1'}),
Edge(data={'source': '0', 'target': '2'}),
Edge(data={'source': '0', 'target': '3'}),
Edge(data={'source': '0', 'target': '4'}),
Edge(data={'source': '1', 'target': '2'}),
Edge(data={'source': '1', 'target': '3'}),
Edge(data={'source': '1', 'target': '4'}),
Edge(data={'source': '2', 'target': '3'}),
Edge(data={'source': '2', 'target': '4'}),
Edge(data={'source': '3', 'target': '4'})
]
compare_nodes(expected_nodes, graph.nodes)
compare_edges(expected_edges, graph.edges)
Expand All @@ -72,11 +71,11 @@ def test_classes(self):
graph.add_graph_from_networkx(G)

expected_nodes = [
Node(classes='class1', data={'id': 'separate node 1'}, position={}),
Node(classes='class2', data={'id': 'separate node 2'}, position={})
Node(classes='class1', data={'id': 'separate node 1'}),
Node(classes='class2', data={'id': 'separate node 2'})
]
expected_edges = [
Edge(data={'source': 'separate node 1', 'target': 'separate node 2'}, position={})
Edge(data={'source': 'separate node 1', 'target': 'separate node 2'})
]

compare_nodes(expected_nodes, graph.nodes)
Expand All @@ -99,8 +98,8 @@ def test_directed(self):
Node(classes='', data={'id': 'separate node 2'}, position={})
]
expected_edges = [
Edge(data={'source': 'separate node 1', 'target': 'separate node 2'}, classes = ' directed ', position={}),
Edge(data={'source': 'separate node 2', 'target': 'separate node 1'}, classes = ' directed ', position={})
Edge(data={'source': 'separate node 1', 'target': 'separate node 2'}, classes = ' directed '),
Edge(data={'source': 'separate node 2', 'target': 'separate node 1'}, classes = ' directed ')
]

compare_nodes(expected_nodes, graph.nodes)
Expand All @@ -120,11 +119,11 @@ def test_multigraphs(self):
graph.add_graph_from_networkx(G)

expected_edges = [
Edge(classes=' multiple_edges ', data={'source': '1', 'target': '2', 'weight': 15}, position={}),
Edge(classes=' multiple_edges ', data={'source': '1', 'target': '2', 'weight': 15}, position={}),
Edge(classes=' multiple_edges ', data={'source': '1', 'target': '2', 'weight': 1}, position={}),
Edge(classes=' multiple_edges ', data={'source': '1', 'target': '2', 'weight': 10}, position={}),
Edge(classes=' multiple_edges ', data={'source': '2', 'target': '4'}, position={})]
Edge(classes=' multiple_edges ', data={'source': '1', 'target': '2', 'weight': 15}),
Edge(classes=' multiple_edges ', data={'source': '1', 'target': '2', 'weight': 15}),
Edge(classes=' multiple_edges ', data={'source': '1', 'target': '2', 'weight': 1}),
Edge(classes=' multiple_edges ', data={'source': '1', 'target': '2', 'weight': 10}),
Edge(classes=' multiple_edges ', data={'source': '2', 'target': '4'})]

expected_nodes = [Node(data={'id': '1'}, position={}),
Node(data={'id': '2'}, position={}),
Expand All @@ -136,8 +135,8 @@ def test_multigraphs(self):
graph = Graph()
# override default behavior
graph.add_graph_from_networkx(G, multiple_edges=False)
expected_edges = [Edge(data={'source': '1', 'target': '2', 'weight': 15}, position={}),
Edge(data={'source': '2', 'target': '4'}, position={})]
expected_edges = [Edge(data={'source': '1', 'target': '2', 'weight': 15}),
Edge(data={'source': '2', 'target': '4'})]

compare_edges(expected_edges, graph.edges)

Expand All @@ -155,11 +154,11 @@ def test_multidigraphs(self):
graph.add_graph_from_networkx(G)

expected_edges = [
Edge(classes=' directed multiple_edges ', data={'source': '1', 'target': '2', 'weight': 15}, position={}),
Edge(classes=' directed multiple_edges ', data={'source': '1', 'target': '2', 'weight': 15}, position={}),
Edge(classes=' directed multiple_edges ', data={'source': '1', 'target': '2', 'weight': 1}, position={}),
Edge(classes=' directed multiple_edges ', data={'source': '2', 'target': '1', 'weight': 10}, position={}),
Edge(classes=' directed multiple_edges ', data={'source': '2', 'target': '4'}, position={})]
Edge(classes=' directed multiple_edges ', data={'source': '1', 'target': '2', 'weight': 15}),
Edge(classes=' directed multiple_edges ', data={'source': '1', 'target': '2', 'weight': 15}),
Edge(classes=' directed multiple_edges ', data={'source': '1', 'target': '2', 'weight': 1}),
Edge(classes=' directed multiple_edges ', data={'source': '2', 'target': '1', 'weight': 10}),
Edge(classes=' directed multiple_edges ', data={'source': '2', 'target': '4'})]

expected_nodes = [Node(data={'id': '1'}, position={}),
Node(data={'id': '2'}, position={}),
Expand All @@ -171,8 +170,8 @@ def test_multidigraphs(self):
graph = Graph()
# override default behavior
graph.add_graph_from_networkx(G, multiple_edges=False, directed=False)
expected_edges = [Edge(data={'source': '1', 'target': '2', 'weight': 15}, position={}),
Edge(data={'source': '2', 'target': '4'}, position={})]
expected_edges = [Edge(data={'source': '1', 'target': '2', 'weight': 15}),
Edge(data={'source': '2', 'target': '4'})]

compare_edges(expected_edges, graph.edges)

Expand All @@ -193,10 +192,10 @@ def test_hybridgraphs(self):
graph.add_edge(e, directed=True)

expected_edges = [
Edge(classes=' multiple_edges ', data={'source': '1', 'target': '2', 'weight': 15}, position={}),
Edge(classes=' multiple_edges ', data={'source': '1', 'target': '2', 'weight': 15}, position={}),
Edge(classes=' multiple_edges ', data={'source': '2', 'target': '4'}, position={}),
Edge(classes=' directed ', data={'source': '1', 'target': '4'}, position={})]
Edge(classes=' multiple_edges ', data={'source': '1', 'target': '2', 'weight': 15}),
Edge(classes=' multiple_edges ', data={'source': '1', 'target': '2', 'weight': 15}),
Edge(classes=' multiple_edges ', data={'source': '2', 'target': '4'}),
Edge(classes=' directed ', data={'source': '1', 'target': '4'})]
compare_edges(expected_edges, graph.edges)

def test_custom_node(self):
Expand All @@ -222,7 +221,7 @@ def __str__(self):
Node(classes='', data={'id': 'Node: node 2'}, position={})
]
expected_edges = [
Edge(data={'source': 'Node: node 1', 'target': 'Node: node 2'}, classes = '', position={})
Edge(data={'source': 'Node: node 1', 'target': 'Node: node 2'}, classes = '')
]

compare_edges(expected_nodes, graph.nodes)
Expand All @@ -248,7 +247,7 @@ def __init__(self, name, classes='', custom_variable=1234):
n1, n2
]
expected_edges = [
Edge(data={'source': 'node 1', 'target': 'node 2'}, classes = '', position={})
Edge(data={'source': 'node 1', 'target': 'node 2'}, classes = '')
]

for expected, actual in zip(expected_nodes, graph.nodes):
Expand Down

0 comments on commit df87be6

Please sign in to comment.