File: test_subgraph.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 (51 lines) | stat: -rw-r--r-- 1,008 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
# -*- coding: utf-8 -*-
from nose.tools import *
import pygraphviz as pgv
from os import linesep

def test_subgraph():
    G = pgv.AGraph()
    G.add_edge(1,2)
    s = G.add_subgraph((1,2),label='foo')
    assert_equal(G.string().expandtabs(2),
"""strict graph {
  {
    graph [label=foo];
    1 -- 2;
  }
}
""".replace('\n', linesep))



def test_subgraph_cluster():
    G = pgv.AGraph(label='foo')
    s = G.subgraph('cluster_a', label='<Hello<BR/>World>')
    s.add_node('sa')
    G.add_node('a')
    assert_equal(G.string().expandtabs(2),
"""strict graph {
  graph [label=foo];
  {
    graph [label=<Hello<BR/>World>];
    sa;
  }
  a;
}
""".replace('\n', linesep))

def test_subgraph_cluster_attribute():
    G = pgv.AGraph()
    s = G.subgraph(name='cluster_a')
    s.node_attr['foo']='bar'
    G.add_node('a')
    G.node_attr['foo']='baz'
    assert_equal(G.string().expandtabs(2),
"""strict graph {
  node [foo=baz];
  subgraph cluster_a {
    graph [foo=bar];
  }
  a;
}
""".replace('\n', linesep))