1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
import pygraphviz as pgv
stringify = pgv.testing.stringify
def test_default_attributes():
A = pgv.AGraph()
A.graph_attr["label"] = "test"
A.graph_attr["spam"] = "eggs"
assert "label" in A.graph_attr
assert A.graph_attr["label"] == "test"
assert A.graph_attr.keys() == ["label", "spam"]
graph_attrs = [("label", "test"), ("spam", "eggs")]
assert sorted(A.graph_attr.iteritems()) == graph_attrs
ans = """strict graph { graph [label=test, spam=eggs]; }"""
assert stringify(A) == " ".join(ans.split())
A.graph_attr["label"] = ""
A.graph_attr["spam"] = ""
ans = """strict graph { }"""
assert stringify(A) == " ".join(ans.split())
A.graph_attr["label"] = "test"
del A.graph_attr["label"]
ans = """strict graph { }"""
assert stringify(A) == " ".join(ans.split())
def test_graph_defaults():
A = pgv.AGraph(rankdir="LR", pack="true")
ans = """strict graph { graph [pack=true, rankdir=LR]; }"""
assert stringify(A) == " ".join(ans.split())
def test_node_defaults():
A = pgv.AGraph()
A.node_attr["label"] = "test"
assert "label" in A.node_attr
assert A.node_attr["label"] == "test"
assert A.node_attr.keys() == ["label"]
assert A.node_attr == {"label": "test"}
assert list(A.node_attr.iteritems()) == [("label", "test")]
ans = """strict graph { node [label=test]; }"""
assert stringify(A) == " ".join(ans.split())
A.node_attr["label"] = ""
ans = """strict graph { }"""
assert stringify(A) == " ".join(ans.split())
A.node_attr["label"] = "test"
del A.node_attr["label"]
ans = """strict graph { }"""
assert stringify(A) == " ".join(ans.split())
A.graph_attr["fontname"] = "graph font"
A.node_attr["fontname"] = "node font"
A.edge_attr["fontname"] = "edge font"
ans = """strict graph {
graph [fontname="graph font"];
node [fontname="node font"];
edge [fontname="edge font"];
}"""
assert stringify(A) == " ".join(ans.split())
def test_edge_defaults():
A = pgv.AGraph()
A.edge_attr["label"] = "test"
assert "label" in A.edge_attr
assert A.edge_attr["label"] == "test"
assert A.edge_attr.keys() == ["label"]
assert A.edge_attr == {"label": "test"}
assert list(A.edge_attr.iteritems()) == [("label", "test")]
ans = """strict graph { edge [label=test]; } """
assert stringify(A) == " ".join(ans.split())
A.edge_attr["label"] = ""
ans = """strict graph { }"""
assert stringify(A) == " ".join(ans.split())
A.edge_attr["label"] = "test"
del A.edge_attr["label"]
ans = """strict graph { }"""
assert stringify(A) == " ".join(ans.split())
|