File: test_node_attributes.py

package info (click to toggle)
python-pygraphviz 1.3.1-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 664 kB
  • sloc: ansic: 4,970; python: 2,523; makefile: 152
file content (73 lines) | stat: -rw-r--r-- 1,772 bytes parent folder | download | duplicates (3)
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
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from nose.tools import *
import pygraphviz as pgv
from os import linesep

def test_node_attribute():
    A = pgv.AGraph()
    A.add_node(1,label='test',spam='eggs')
    assert_equal(A.string().expandtabs(2),
"""strict graph {
  node [label="\\N"];
  1  [label=test,
    spam=eggs];
}
""".replace('\n', linesep))

def test_node_attributes2():
    A = pgv.AGraph()
    A.add_node(1)
    one = A.get_node(1)
    one.attr['label'] = 'test'
    one.attr['spam'] = 'eggs'
    assert_true('label' in one.attr)
    assert_equal(one.attr['label'],'test')
    assert_equal(sorted(one.attr.keys()), ['label', 'spam'])
    assert_equal(A.string().expandtabs(2),
"""strict graph {
  node [label="\\N"];
  1  [label=test,
    spam=eggs];
}
""".replace('\n', linesep)
)
    one.attr['label'] = ''
    one.attr['spam'] = ''
    assert_equal(A.string().expandtabs(2),
"""strict graph {
  node [label="\\N"];
  1  [label=""];
}
""".replace('\n', linesep))
    one.attr['label'] = 'test'
    del one.attr['label']
    assert_equal(A.string().expandtabs(2),
"""strict graph {
  node [label="\\N"];
  1  [label=""];
}
""".replace('\n', linesep))

def test_node_attribute_update():
    A = pgv.AGraph()
    A.add_node(1,label='test',spam='eggs')
    A.add_node(1,label='updated')
    assert_equal(A.string().expandtabs(2),
"""strict graph {
  node [label="\\N"];
  1  [label=updated,
    spam=eggs];
}
""".replace('\n', linesep))

def test_node_attribute_remove():
    A = pgv.AGraph()
    A.add_node(1,label='test',spam='eggs')
    A.add_node(1,label=r'\N',spam='') # use \N to signify null label, otherwise ''
    assert_equal(A.string().expandtabs(2),
"""strict graph {
  node [label="\\N"];
  1;
}
""".replace('\n', linesep))