def test_add_subgraph_escape_name(self): fac = PydotFactory() g = fac.get_graph() fac.add_subgraph_to_graph(g, 'graph') self.assertEqual(1, len(g.get_subgraph_list())) self.assertEqual('cluster_graph_', g.get_subgraph_list()[0].get_name()) self.assertEqual('graph_', g.get_subgraph_list()[0].get_label())
def test_add_subgraph_escape_name(self): fac = PydotFactory() g = fac.get_graph() fac.add_subgraph_to_graph(g, 'graph') self.assertEqual(1, len(g.get_subgraph_list())) self.assertEqual('cluster_graph_', g.get_subgraph_list()[0].get_name()) self.assertEqual('graph_', g.get_subgraph_list()[0].get_label())
def test_create_dot(self): fac = PydotFactory() g = fac.get_graph() fac.add_node_to_graph(g, 'foo') fac.add_node_to_graph(g, 'edge') fac.add_edge_to_graph(g, 'foo', 'edge') fac.add_subgraph_to_graph(g, 'foo') snippets = ['digraph graphname {\n\tgraph [rankdir=TB, ranksep="0.2", rank=same, compound=True];\n\tnode [label="\\N"];\n\tgraph [bb="', '"];\n\tsubgraph cluster_foo {\n\t\tgraph [', '];\n\t}\n\tfoo [label=foo, shape=box, pos="', 'edge_ [label=edge_, shape=box, pos="', 'foo -> edge_', '"];\n}\n'] result = fac.create_dot(g) for sn in snippets: self.assertTrue(sn in result, '%s \nmissing in\n %s' % (sn, result))
def test_create_dot(self): fac = PydotFactory() g = fac.get_graph() fac.add_node_to_graph(g, 'foo') fac.add_node_to_graph(g, 'edge') fac.add_edge_to_graph(g, 'foo', 'edge') fac.add_subgraph_to_graph(g, 'foo') snippets = [ 'digraph graphname {\n\tgraph [', 'rankdir=TB', 'compound=True', 'rank=same', 'node [label="\\N"]', 'subgraph cluster_foo {\n\t\tgraph [', 'foo\t [', 'label=foo', 'shape=box', 'pos="', 'edge_\t [', 'label=edge_', 'foo -> edge_\t [', '"];\n}\n' ] result = fac.create_dot(g) for sn in snippets: self.assertTrue(sn in result, '%s \nmissing in\n %s' % (sn, result))
def test_create_dot(self): fac = PydotFactory() g = fac.get_graph() fac.add_node_to_graph(g, 'foo') fac.add_node_to_graph(g, 'edge') fac.add_edge_to_graph(g, 'foo', 'edge') fac.add_subgraph_to_graph(g, 'foo') snippets = [ 'digraph graphname { graph [', 'rankdir=TB', 'compound=True', 'rank=same', 'node [label="\\N"]', 'subgraph cluster_foo { graph [', 'foo [', 'label=foo', 'shape=box', 'pos="', 'edge_ [', 'label=edge_', 'foo -> edge_ [', '"]; }' ] result = fac.create_dot(g) # get rid of version specific whitespaces result = re.sub('[\n\t ]+', ' ', result) for sn in snippets: self.assertTrue(sn in result, '%s \nmissing in\n %s' % (sn, result))
def test_create_dot(self): fac = PydotFactory() g = fac.get_graph() fac.add_node_to_graph(g, 'foo') fac.add_node_to_graph(g, 'edge') fac.add_edge_to_graph(g, 'foo', 'edge') fac.add_subgraph_to_graph(g, 'foo') snippets = ['digraph graphname {\n\tgraph [', 'rankdir=TB', 'compound=True', 'rank=same', 'node [label="\\N"]', 'subgraph cluster_foo {\n\t\tgraph [', 'foo\t [', 'label=foo', 'shape=box', 'pos="', 'edge_\t [', 'label=edge_', 'foo -> edge_\t [', '"];\n}\n'] result = fac.create_dot(g) for sn in snippets: self.assertTrue(sn in result, '%s \nmissing in\n %s' % (sn, result))
def generate_dotcode_from_capability_info(spec_index, running_providers): dotcode_factory = PydotFactory() dotgraph = dotcode_factory.get_graph(rankdir="BT") interface_graphs = {} # Draw plain interfaces for name in spec_index.interfaces: providers = [ k for k, v in spec_index.providers.items() if v.implements == name ] # Only create a subgraph if it has providers if providers: interface_graphs[name] = dotcode_factory.add_subgraph_to_graph( dotgraph, str(name) + "_group", subgraphlabel='') # Draw box for interface graph = interface_graphs.get(name, dotgraph) dotcode_factory.add_node_to_graph(graph, nodename=str(name), shape="box") # Draw semantic interfaces for name, interface in spec_index.semantic_interfaces.items(): providers = [ k for k, v in spec_index.providers.items() if v.implements == name ] # Only create a subgraph if it has providers if providers: interface_graphs[name] = dotcode_factory.add_subgraph_to_graph( dotgraph, str(name) + "_group", subgraphlabel='') graph = interface_graphs.get(name, dotgraph) # Draw box for semantic interface dotcode_factory.add_node_to_graph(graph, nodename=str(name), shape="box") # Make edge to interface it redefines, if it exists if interface.redefines in spec_index.interfaces: dotcode_factory.add_edge_to_graph(dotgraph, str(name), str(interface.redefines), label="redefines") # Draw providers interfaces = dict(spec_index.interfaces) interfaces.update(spec_index.semantic_interfaces) for name, provider in spec_index.providers.items(): # Get subgraph of interface this provider implements graph = interface_graphs[provider.implements] # Get the default provider for the interface this provider implements default_provider = interfaces[provider.implements].default_provider provider_name = name # Add annotaion if this is the default provider if default_provider != 'unknown' and default_provider == name: provider_name += " (default)" # If it is running, make it green if name in running_providers: dotcode_factory.add_node_to_graph(graph, nodename=str(name), nodelabel=str(provider_name), shape="ellipse", color="green") # Else no color else: dotcode_factory.add_node_to_graph(graph, nodename=str(name), nodelabel=str(provider_name), shape="ellipse") # Add edges to the interface, provider paris this provider depends on for dep, relationship in provider.dependencies.items(): if relationship.preferred_provider is not None: dotcode_factory.add_edge_to_graph( dotgraph, str(name), str(relationship.preferred_provider), label="requires") elif spec_index.interfaces[ relationship. capability_name].default_provider != 'unknown': dotcode_factory.add_edge_to_graph( dotgraph, str(name), str(spec_index.interfaces[ relationship.capability_name].default_provider), label="requires") return dotcode_factory.create_dot(dotgraph)
def generate_dotcode_from_capability_info(spec_index, running_providers): dotcode_factory = PydotFactory() dotgraph = dotcode_factory.get_graph(rankdir="BT") interface_graphs = {} # Draw plain interfaces for name in spec_index.interfaces: providers = [k for k, v in spec_index.providers.items() if v.implements == name] # Only create a subgraph if it has providers if providers: interface_graphs[name] = dotcode_factory.add_subgraph_to_graph( dotgraph, str(name) + "_group", subgraphlabel="" ) # Draw box for interface graph = interface_graphs.get(name, dotgraph) dotcode_factory.add_node_to_graph(graph, nodename=str(name), shape="box") # Draw semantic interfaces for name, interface in spec_index.semantic_interfaces.items(): providers = [k for k, v in spec_index.providers.items() if v.implements == name] # Only create a subgraph if it has providers if providers: interface_graphs[name] = dotcode_factory.add_subgraph_to_graph( dotgraph, str(name) + "_group", subgraphlabel="" ) graph = interface_graphs.get(name, dotgraph) # Draw box for semantic interface dotcode_factory.add_node_to_graph(graph, nodename=str(name), shape="box") # Make edge to interface it redefines, if it exists if interface.redefines in spec_index.interfaces: dotcode_factory.add_edge_to_graph(dotgraph, str(name), str(interface.redefines), label="redefines") # Draw providers interfaces = dict(spec_index.interfaces) interfaces.update(spec_index.semantic_interfaces) for name, provider in spec_index.providers.items(): # Get subgraph of interface this provider implements graph = interface_graphs[provider.implements] # Get the default provider for the interface this provider implements default_provider = interfaces[provider.implements].default_provider provider_name = name # Add annotaion if this is the default provider if default_provider != "unknown" and default_provider == name: provider_name += " (default)" # If it is running, make it green if name in running_providers: dotcode_factory.add_node_to_graph( graph, nodename=str(name), nodelabel=str(provider_name), shape="ellipse", color="green" ) # Else no color else: dotcode_factory.add_node_to_graph(graph, nodename=str(name), nodelabel=str(provider_name), shape="ellipse") # Add edges to the interface, provider paris this provider depends on for dep, relationship in provider.dependencies.items(): if relationship.preferred_provider is not None: dotcode_factory.add_edge_to_graph( dotgraph, str(name), str(relationship.preferred_provider), label="requires" ) elif spec_index.interfaces[relationship.capability_name].default_provider != "unknown": dotcode_factory.add_edge_to_graph( dotgraph, str(name), str(spec_index.interfaces[relationship.capability_name].default_provider), label="requires", ) return dotcode_factory.create_dot(dotgraph)