Exemplo n.º 1
0
 def assert_sort(self, tuples, allitems=None):
     if allitems is None:
         allitems = self._nodes_from_tuples(tuples)
     else:
         allitems = self._nodes_from_tuples(tuples).union(allitems)
     result = list(topological.sort(tuples, allitems))
     assert conforms_partial_ordering(tuples, result)
Exemplo n.º 2
0
    def test_raise_on_cycle_two(self):

        # this condition was arising from ticket:362 and was not treated
        # properly by topological sort

        node1 = "node1"
        node2 = "node2"
        node3 = "node3"
        node4 = "node4"
        tuples = [
            (node1, node2),
            (node3, node1),
            (node2, node4),
            (node3, node2),
            (node2, node3),
        ]
        allitems = self._nodes_from_tuples(tuples)

        try:
            list(topological.sort(tuples, allitems))
            assert False
        except exc.CircularDependencyError as err:
            eq_(err.cycles, set(["node1", "node3", "node2"]))
            eq_(
                err.edges,
                set(
                    [
                        ("node3", "node1"),
                        ("node2", "node3"),
                        ("node3", "node2"),
                        ("node1", "node2"),
                        ("node2", "node4"),
                    ]
                ),
            )
Exemplo n.º 3
0
    def test_raise_on_cycle_one(self):
        node1 = "node1"
        node2 = "node2"
        node3 = "node3"
        node4 = "node4"
        node5 = "node5"
        tuples = [
            (node4, node5),
            (node5, node4),
            (node1, node2),
            (node2, node3),
            (node3, node1),
            (node4, node1),
        ]
        allitems = self._nodes_from_tuples(tuples)

        try:
            list(topological.sort(tuples, allitems))
            assert False
        except exc.CircularDependencyError as err:
            eq_(err.cycles, set(["node1", "node3", "node2", "node5", "node4"]))
            eq_(
                err.edges,
                set(
                    [
                        ("node3", "node1"),
                        ("node4", "node1"),
                        ("node2", "node3"),
                        ("node1", "node2"),
                        ("node4", "node5"),
                        ("node5", "node4"),
                    ]
                ),
            )
Exemplo n.º 4
0
 def test_raise_on_cycle_three(self):
     question, issue, providerservice, answer, provider = (
         "Question",
         "Issue",
         "ProviderService",
         "Answer",
         "Provider",
     )
     tuples = [
         (question, issue),
         (providerservice, issue),
         (provider, question),
         (question, provider),
         (providerservice, question),
         (provider, providerservice),
         (question, answer),
         (issue, question),
     ]
     allitems = self._nodes_from_tuples(tuples)
     assert_raises(
         exc.CircularDependencyError,
         list,
         topological.sort(tuples, allitems),
     )
Exemplo n.º 5
0
 def assert_sort_deterministic(self, tuples, allitems, expected):
     result = list(
         topological.sort(tuples, allitems, deterministic_order=True)
     )
     assert conforms_partial_ordering(tuples, result)
     assert result == expected