def test_topsort_double_cycle(self): graph = DepGraph({ 'a': ['b', 'c'], 'c': ['a', 'b'], 'b': ['c', 'a'], }) assert ['a', 'b', 'c'] == graph.topsort()
def test_topsort_simple(self): graph = DepGraph({ 'a': ['c'], 'b': [], 'c': ['b'], }) assert ['b', 'c', 'a'] == graph.topsort()
def test_topsort_cycle_plus(self): graph = DepGraph({ 'a': ['b', 'c'], 'c': ['a', 'b'], 'b': ['c', 'a', 'd'], 'd': [] }) assert ['d', 'a', 'b', 'c'] == graph.topsort()
def test_topsort_same_level(self): graph = DepGraph({ 'a': ['b', 'd', 'e', 'c'], 'e': [], 'c': [], 'd': [], 'b': [], }) # same level sort by name assert ['b', 'c', 'd', 'e', 'a'] == graph.topsort()
class Test_DepGraph(object): graph = DepGraph({ 'a': ['b', 'c'], 'b': ['d'], 'd': ['c', 'e'], }) def test_nodes(self): b_deps = [n.name for n in self.graph.nodes['b'].all_deps()] assert set(b_deps) == set(['c', 'e', 'b', 'd']) def test_dot(self): output = StringIO() self.graph.write_dot(output) lines = output.getvalue().splitlines() assert '"a" -> "c"' in lines assert '"a" -> "b"' in lines assert '"b" -> "d"' in lines assert '"d" -> "c"' in lines assert '"d" -> "e"' in lines def test_topsort_simple(self): graph = DepGraph({ 'a': ['c'], 'b': [], 'c': ['b'], }) assert ['b', 'c', 'a'] == graph.topsort() def test_topsort_same_level(self): graph = DepGraph({ 'a': ['b', 'd', 'e', 'c'], 'e': [], 'c': [], 'd': [], 'b': [], }) # same level sort by name assert ['b', 'c', 'd', 'e', 'a'] == graph.topsort() def test_topsort_cycle(self): graph = DepGraph({ 'a': ['b'], 'c': ['a'], 'b': ['c'], }) assert ['a', 'b', 'c'] == graph.topsort() def test_topsort_double_cycle(self): graph = DepGraph({ 'a': ['b', 'c'], 'c': ['a', 'b'], 'b': ['c', 'a'], }) assert ['a', 'b', 'c'] == graph.topsort() def test_topsort_cycle_plus(self): graph = DepGraph({ 'a': ['b', 'c'], 'c': ['a', 'b'], 'b': ['c', 'a', 'd'], 'd': [] }) assert ['d', 'a', 'b', 'c'] == graph.topsort()