~ubuntu-branches/ubuntu/utopic/python-networkx/utopic

« back to all changes in this revision

Viewing changes to networkx/drawing/tests/test_layout.py

  • Committer: Package Import Robot
  • Author(s): Sandro Tosi
  • Date: 2012-08-11 12:41:30 UTC
  • mfrom: (1.4.1) (5.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20120811124130-whr6uso7fncyg8bi
Tags: 1.7-1
* New upstream release
* debian/patches/changeset_*
  - removed, included upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
    Unit tests for layout functions.
3
 
"""
4
 
 
5
 
import os, sys
6
 
import tempfile
7
 
 
 
1
"""Unit tests for layout functions."""
 
2
import sys
8
3
from nose import SkipTest
9
4
from nose.tools import assert_equal
10
 
 
11
5
import networkx as nx
12
6
 
13
7
class TestLayout(object):
 
8
    numpy=1 # nosetests attribute, use nosetests -a 'not numpy' to skip test
14
9
    @classmethod
15
10
    def setupClass(cls):
16
11
        global numpy
18
13
            import numpy
19
14
        except ImportError:
20
15
            raise SkipTest('numpy not available.')
21
 
        if sys.version_info[0] > 2:
22
 
            raise SkipTest('Drawing not implemented for Python 3.x')
23
16
 
24
17
 
25
18
    def setUp(self):
26
19
        self.Gi=nx.grid_2d_graph(5,5)
27
20
        self.Gs=nx.Graph()
28
21
        self.Gs.add_path('abcdef')
29
 
 
 
22
        self.bigG=nx.grid_2d_graph(25,25) #bigger than 500 nodes for sparse
30
23
 
31
24
    def test_smoke_int(self):
32
25
        G=self.Gi
35
28
        vpos=nx.spring_layout(G)
36
29
        vpos=nx.fruchterman_reingold_layout(G)
37
30
        vpos=nx.spectral_layout(G)
 
31
        vpos=nx.spectral_layout(self.bigG)
38
32
        vpos=nx.shell_layout(G)
39
33
 
40
 
 
41
34
    def test_smoke_string(self):
42
35
        G=self.Gs
43
36
        vpos=nx.random_layout(G)
60
53
        except ImportError:
61
54
            raise SkipTest('scipy not available.')
62
55
 
63
 
        A=nx.to_scipy_sparse_matrix(self.Gs)
 
56
        A=nx.to_scipy_sparse_matrix(self.Gs,dtype='f')
64
57
        pos=nx.drawing.layout._sparse_fruchterman_reingold(A)
 
58
        pos=nx.drawing.layout._sparse_spectral(A)
65
59
 
66
60
        pos=nx.drawing.layout._sparse_fruchterman_reingold(A,dim=3)
67
61
        assert_equal(pos.shape,(6,3))
68
 
 
69