示例#1
0
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)
示例#2
0
 def test_repr_svg(self):
     self.assertRegexpMatches(
         Graph('spam')._repr_svg_(), r'(?s)^<\?xml .+</svg>\s*$')
示例#3
0
    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
}''')
示例#4
0
 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}')
示例#5
0
    def test_subgraph_invalid(self):
        with self.assertRaises(ValueError):
            Graph().subgraph(Digraph())

        with self.assertRaises(ValueError):
            Digraph().subgraph(Graph())
示例#6
0
 def test_strict(self):
     self.assertEqual(Graph(strict=True).source, 'strict graph {\n}')
     self.assertEqual(Digraph(strict=True).source, 'strict digraph {\n}')
示例#7
0
 def test_attr(self):
     with self.assertRaises(ValueError):
         Graph().attr('spam')
示例#8
0
def test_subgraph_reflexive():  # guard against potential infinite loop
    dot = Graph()
    dot.subgraph(dot)
    assert dot.source == 'graph {\n\t{\n\t}\n}'
示例#9
0
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}'
示例#10
0
def test_attr_kw_none():
    dot = Graph()
    dot.attr(spam='eggs')
    assert dot.source == 'graph {\n\tspam=eggs\n}'
示例#11
0
def test_iter_strict():
    assert Graph(strict=True).source == 'strict graph {\n}'
    assert Digraph(strict=True).source == 'strict digraph {\n}'
示例#12
0
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 {
示例#13
0
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 {
示例#14
0
    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
}''')
示例#15
0
 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}')
示例#16
0
    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
}""",
        )