(self, graph, expected)
| 6 | |
| 7 | class TestTopologicalSort(unittest.TestCase): |
| 8 | def _test_graph(self, graph, expected): |
| 9 | def static_order_with_groups(ts): |
| 10 | ts.prepare() |
| 11 | while ts.is_active(): |
| 12 | nodes = ts.get_ready() |
| 13 | for node in nodes: |
| 14 | ts.done(node) |
| 15 | yield tuple(sorted(nodes)) |
| 16 | |
| 17 | ts = graphlib.TopologicalSorter(graph) |
| 18 | self.assertEqual(list(static_order_with_groups(ts)), list(expected)) |
| 19 | |
| 20 | ts = graphlib.TopologicalSorter(graph) |
| 21 | # need to be a bit careful comparing the result of ts.static_order and |
| 22 | # expected, because the order within a group is dependent on set |
| 23 | # iteration order |
| 24 | it = iter(ts.static_order()) |
| 25 | for group in expected: |
| 26 | tsgroup = {next(it) for element in group} |
| 27 | self.assertEqual(set(group), tsgroup) |
| 28 | |
| 29 | def _assert_cycle(self, graph, cycle): |
| 30 | ts = graphlib.TopologicalSorter() |
no test coverage detected