def test_edge_attribute_discard(): # Test that edge attributes are discarded if we do not specify to keep them G = nx.Graph() edgelist = [(0, 1, [('weight', 5), ('otherattr', 1), ('otherattr2', 3)]), (0, 2, [('weight', 5), ('otherattr', 2), ('otherattr2', 2)]), (1, 2, [('weight', 6), ('otherattr', 3), ('otherattr2', 1)])] G.add_edges_from(edgelist) ed = branchings.Edmonds(G) B = ed.find_optimum('weight', preserve_attrs=False) edge_dict = B[0][1] with pytest.raises(KeyError): _ = edge_dict['otherattr']
def test_edge_attribute_preservation_normal_graph(): # Test that edge attributes are preserved when finding an optimum graph # using the Edmonds class for normal graphs. G = nx.Graph() edgelist = [(0, 1, [('weight', 5), ('otherattr', 1), ('otherattr2', 3)]), (0, 2, [('weight', 5), ('otherattr', 2), ('otherattr2', 2)]), (1, 2, [('weight', 6), ('otherattr', 3), ('otherattr2', 1)])] G.add_edges_from(edgelist) ed = branchings.Edmonds(G) B = ed.find_optimum('weight', preserve_attrs=True, seed=1) assert B[0][1]['otherattr'] == 1 assert B[0][1]['otherattr2'] == 3
def test_edge_attribute_preservation_multigraph(): # Test that edge attributes are preserved when finding an optimum graph # using the Edmonds class for multigraphs. G = nx.MultiGraph() edgelist = [(0, 1, [('weight', 5), ('otherattr', 1), ('otherattr2', 3)]), (0, 2, [('weight', 5), ('otherattr', 2), ('otherattr2', 2)]), (1, 2, [('weight', 6), ('otherattr', 3), ('otherattr2', 1)])] G.add_edges_from(edgelist * 2) # Make sure we have duplicate edge paths ed = branchings.Edmonds(G) B = ed.find_optimum('weight', preserve_attrs=True) assert B[0][1][0]['otherattr'] == 1 assert B[0][1][0]['otherattr2'] == 3