Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_flatten(self):
a = graph.Cycle([[1, 2], [2, 3], [3, 1]])
b = graph.Cycle([[4, 5], [5, 4]])
c = graph.Cycle([[a, 6], [6, b], [b, 7], [7, a]])
nodes = c.flatten_nodes()
self.assertEqual(sorted(nodes), [1, 2, 3, 4, 5, 6, 7])
def test_flatten(self):
a = graph.Cycle([[1, 2], [2, 3], [3, 1]])
b = graph.Cycle([[4, 5], [5, 4]])
c = graph.Cycle([[a, 6], [6, b], [b, 7], [7, a]])
nodes = c.flatten_nodes()
self.assertEqual(sorted(nodes), [1, 2, 3, 4, 5, 6, 7])
def test_flatten(self):
a = graph.Cycle([[1, 2], [2, 3], [3, 1]])
b = graph.Cycle([[4, 5], [5, 4]])
c = graph.Cycle([[a, 6], [6, b], [b, 7], [7, a]])
nodes = c.flatten_nodes()
self.assertEqual(sorted(nodes), [1, 2, 3, 4, 5, 6, 7])
def build(self):
"""Finalise the graph, after adding all input files to it."""
assert not self.final, 'Trying to mutate a final graph.'
# Recursively extract cycles until the graph is cycle-free.
while True:
try:
cycle = Cycle(nx.find_cycle(self.graph))
self.extract_cycle(cycle)
except nx.NetworkXNoCycle:
break
# Now that we have reduced the graph to a tree, we can flatten cycle
# nodes into NodeSets
def transform_node(node):
if isinstance(node, Cycle):
return NodeSet(node)
else:
return node
self.graph = nx.relabel_nodes(self.graph, transform_node)
self.final = True
def transform_node(node):
if isinstance(node, Cycle):
return NodeSet(node)
else:
return node
self.graph = nx.relabel_nodes(self.graph, transform_node)