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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from nose.tools import *
import pygraphviz as pgv
from os import linesep
def test_default_attributes():
A = pgv.AGraph()
A.graph_attr['label'] = 'test'
A.graph_attr['spam'] = 'eggs'
assert_true('label' in A.graph_attr)
assert_equal(A.graph_attr['label'], 'test')
assert_equal(A.graph_attr.keys(), ['label', 'spam'])
assert_equal(sorted(list(A.graph_attr.iteritems())),
[('label', 'test'), ('spam', 'eggs')])
assert_equal(A.string().expandtabs(2),
"""strict graph {
graph [label=test,
spam=eggs
];
}
""".replace('\n', linesep))
A.graph_attr['label'] = ''
A.graph_attr['spam'] = ''
assert_equal(A.string().expandtabs(2),
"""strict graph {
}
""".replace('\n', linesep))
A.graph_attr['label'] = 'test'
del A.graph_attr['label']
assert_equal(A.string().expandtabs(2),
"""strict graph {
}
""".replace('\n', linesep)
)
def test_graph_defaults():
A = pgv. AGraph(rankdir='LR',pack='true')
assert_equal(A.string().expandtabs(2),
"""strict graph {
graph [pack=true,
rankdir=LR
];
}
""".replace('\n', linesep))
def test_node_defaults():
A = pgv.AGraph()
A.node_attr['label']='test'
assert_true('label' in A.node_attr)
assert_equal(A.node_attr['label'], 'test')
assert_equal(A.node_attr.keys(), ['label'])
assert_equal(A.node_attr, {'label': 'test'})
assert_equal(list(A.node_attr.iteritems()), [('label', 'test')])
assert_equal(A.string().expandtabs(2),
"""strict graph {
node [label=test];
}
""".replace('\n', linesep)
)
A.node_attr['label'] = ''
assert_true(A.string().expandtabs(2),
"""strict graph {
}
""".replace('\n', linesep)
)
A.node_attr['label'] = 'test'
del A.node_attr['label']
assert_true(A.string().expandtabs(2),
"""strict graph {
}
""".replace('\n', linesep)
)
A.graph_attr['fontname'] = 'graph font'
A.node_attr['fontname'] = 'node font'
A.edge_attr['fontname'] = 'edge font'
assert_equal(A.string().expandtabs(2),
"""strict graph {
graph [fontname="graph font"];
node [fontname="node font"];
edge [fontname="edge font"];
}
""".replace('\n', linesep)
)
def test_edge_defaults():
A = pgv.AGraph()
A.edge_attr['label'] = 'test'
assert_true('label' in A.edge_attr)
assert_equal(A.edge_attr['label'], 'test')
assert_equal(A.edge_attr.keys(), ['label'])
assert_equal(A.edge_attr, {'label': 'test'})
assert_equal(list(A.edge_attr.iteritems()), [('label', 'test')])
assert_equal(A.string().expandtabs(2),
"""strict graph {
edge [label=test];
}
""".replace('\n', linesep)
)
A.edge_attr['label'] = ''
assert_equal(A.string().expandtabs(2),
"""strict graph {
}
""".replace('\n', linesep)
)
A.edge_attr['label'] = 'test'
del A.edge_attr['label']
assert_true(A.string().expandtabs(2),
"""strict graph {
}
""".replace('\n', linesep)
)
|