Beispiel #1
0
 def test_with_cyclic_edges(self):
     graph = {
         1: {2},
         2: {1},
     }
     with self.assertRaises(CyclicGraphError):
         tsort_grouped(graph)
Beispiel #2
0
 def test_with_isolated_vertices(self):
     graph = {
         1: set(),
         2: set(),
     }
     # Without edges we cannot assert the order.
     self.assertEquals([{1, 2}], tsort_grouped(graph))
Beispiel #3
0
 def test_with_multiple_outdegrees(self):
     graph = {
         1: {2, 3},
     }
     vertex_groups = tsort_grouped(graph)
     self.assertEquals([
         {1},
         {2, 3},
     ], vertex_groups)
Beispiel #4
0
 async def _dispatch(*args, **kwargs) -> List[Any]:
     return [
         await asyncio.gather(*[
             getattr(target_extensions[target_extension_type],
                     target_method_name)(*args, **kwargs)
             for target_extension_type in target_extension_type_group
             if issubclass(target_extension_type, target_type)
         ]) for target_extension_type_group in tsort_grouped(
             target_extension_graph)
     ]
Beispiel #5
0
 def test_with_multiple_indegrees(self):
     graph = {
         1: {3},
         2: {3},
     }
     vertex_groups = tsort_grouped(graph)
     self.assertEquals([
         {1, 2},
         {3},
     ], vertex_groups)
Beispiel #6
0
 def test_with_isolated_vertices_and_edges(self):
     graph = {
         1: {2, 3, 4},
         5: {4, 6, 7},
         8: set(),
         9: set(),
     }
     vertex_groups = tsort_grouped(graph)
     self.assertEquals([
         {8, 9},
         {1, 5},
         {2, 3, 4, 6, 7},
     ], vertex_groups)
Beispiel #7
0
def _clean_places(ancestry: Ancestry) -> None:
    places = list(ancestry.places.values())

    def _extend_place_graph(graph: Graph, enclosing_place: Place) -> None:
        enclosures = enclosing_place.encloses
        # Ensure each place appears in the graph, even if they're anonymous.
        graph.setdefault(enclosing_place, set())
        for enclosure in enclosures:
            enclosed_place = enclosure.encloses
            seen_enclosed_place = enclosed_place in graph
            graph[enclosed_place].add(enclosing_place)
            if not seen_enclosed_place:
                _extend_place_graph(graph, enclosed_place)

    places_graph = defaultdict(set)
    for place in places:
        _extend_place_graph(places_graph, place)

    for grouped_places in tsort_grouped(places_graph):
        for place in grouped_places:
            _clean_place(ancestry, place)
Beispiel #8
0
    def _init_extensions(self) -> None:
        for grouped_extension_types in tsort_grouped(
                build_extension_type_graph(
                    set(self._configuration.extensions.keys()))):
            for extension_type in grouped_extension_types:
                extension_args = []
                if issubclass(
                        extension_type, ConfigurableExtension
                ) and extension_type in self.configuration.extensions:
                    extension_kwargs = self.configuration.extensions[
                        extension_type]
                else:
                    extension_kwargs = {}

                if issubclass(extension_type, AppAwareFactory):
                    extension = extension_type.new_for_app(
                        self, *extension_args, **extension_kwargs)
                else:
                    extension = extension_type(*extension_args,
                                               **extension_kwargs)

                self._extensions[extension_type] = extension
Beispiel #9
0
 def test_with_empty_graph(self):
     graph = {}
     self.assertCountEqual([], tsort_grouped(graph))
Beispiel #10
0
 def test_with_multiple_chained_edges(self):
     graph = {
         2: {3},
         1: {2},
     }
     self.assertEquals([{1}, {2}, {3}], tsort_grouped(graph))
Beispiel #11
0
 def test_with_edges(self):
     graph = {
         1: {2},
     }
     self.assertEquals([{1}, {2}], tsort_grouped(graph))