def create_file_dot(V, E): dot = Graph(name="City_Map", filename="map") for vertex in V: dot.node(str(vertex[0]), label="{} {} ({},{})".format(str(base26to10(vertex[0])), vertex[0], vertex[1], vertex[2])) for edge in E: dot.edge(str(edge[1]), str(edge[2]), label=str(edge[0])) dot.render(filename="map", directory=PATH_GRAPH, cleanup=True)
def test_repr_svg(self): self.assertRegexpMatches( Graph('spam')._repr_svg_(), r'(?s)^<\?xml .+</svg>\s*$')
def test_subgraph(self): s1 = Graph() s1.node('A') s1.node('B') s1.node('C') s1.edge('A', 'B', constraint='false') s1.edges(['AC', 'BC']) s2 = Graph() s2.node('D') s2.node('E') s2.node('F') s2.edge('D', 'E', constraint='false') s2.edges(['DF', 'EF']) dot = Graph() dot.subgraph(s1) dot.subgraph(s2) dot.attr('edge', style='dashed') dot.edges(['AD', 'BE', 'CF']) self.assertEqual( dot.source, '''graph { subgraph { A B C A -- B [constraint=false] A -- C B -- C } subgraph { D E F D -- E [constraint=false] D -- F E -- F } edge [style=dashed] A -- D B -- E C -- F }''')
def test_subgraph_recursive(self): # guard against potential infinite loop dot = Graph() dot.subgraph(dot) self.assertEqual(dot.source, 'graph {\n\tsubgraph {\n\t}\n}')
def test_subgraph_invalid(self): with self.assertRaises(ValueError): Graph().subgraph(Digraph()) with self.assertRaises(ValueError): Digraph().subgraph(Graph())
def test_strict(self): self.assertEqual(Graph(strict=True).source, 'strict graph {\n}') self.assertEqual(Digraph(strict=True).source, 'strict digraph {\n}')
def test_attr(self): with self.assertRaises(ValueError): Graph().attr('spam')
def test_subgraph_reflexive(): # guard against potential infinite loop dot = Graph() dot.subgraph(dot) assert dot.source == 'graph {\n\t{\n\t}\n}'
def test_subgraph_graph_none(): dot = Graph() with dot.subgraph(name='name', comment='comment'): pass assert dot.source == 'graph {\n\t// comment\n\tsubgraph name {\n\t}\n}'
def test_attr_kw_none(): dot = Graph() dot.attr(spam='eggs') assert dot.source == 'graph {\n\tspam=eggs\n}'
def test_iter_strict(): assert Graph(strict=True).source == 'strict graph {\n}' assert Digraph(strict=True).source == 'strict digraph {\n}'
def test_subgraph(): s1 = Graph() s1.node('A') s1.node('B') s1.node('C') s1.edge('A', 'B', constraint='false') s1.edges(['AC', 'BC']) s2 = Graph() s2.node('D') s2.node('E') s2.node('F') s2.edge('D', 'E', constraint='false') s2.edges(['DF', 'EF']) dot = Graph() dot.subgraph(s1) dot.subgraph(s2) dot.attr('edge', style='dashed') dot.edges(['AD', 'BE', 'CF']) assert dot.source == '''graph {
def test_subgraph(self): s1 = Graph() s1.node('A') s1.node('B') s1.node('C') s1.edge('A', 'B', constraint='false') s1.edges(['AC', 'BC']) s2 = Graph() s2.node('D') s2.node('E') s2.node('F') s2.edge('D', 'E', constraint='false') s2.edges(['DF', 'EF']) dot = Graph() dot.subgraph(s1) dot.subgraph(s2) dot.attr('edge', style='dashed') dot.edges(['AD', 'BE', 'CF']) self.assertEqual(dot.source, '''graph { subgraph { A B C A -- B [constraint=false] A -- C B -- C } subgraph { D E F D -- E [constraint=false] D -- F E -- F } edge [style=dashed] A -- D B -- E C -- F }''')
def test_subgraph(self): s1 = Graph() s1.node("A") s1.node("B") s1.node("C") s1.edge("A", "B", constraint="false") s1.edges(["AC", "BC"]) s2 = Graph() s2.node("D") s2.node("E") s2.node("F") s2.edge("D", "E", constraint="false") s2.edges(["DF", "EF"]) dot = Graph() dot.subgraph(s1) dot.subgraph(s2) dot.attr("edge", style="dashed") dot.edges(["AD", "BE", "CF"]) self.assertEqual( dot.source, """graph { subgraph { A B C A -- B [constraint=false] A -- C B -- C } subgraph { D E F D -- E [constraint=false] D -- F E -- F } edge [style=dashed] A -- D B -- E C -- F }""", )