Home | History | Annotate | Download | only in tests
      1 """Unit tests for layout functions."""
      2 import sys
      3 from nose import SkipTest
      4 from nose.tools import assert_equal
      5 import networkx as nx
      6 
      7 class TestLayout(object):
      8     numpy=1 # nosetests attribute, use nosetests -a 'not numpy' to skip test
      9     @classmethod
     10     def setupClass(cls):
     11         global numpy
     12         try:
     13             import numpy
     14         except ImportError:
     15             raise SkipTest('numpy not available.')
     16 
     17 
     18     def setUp(self):
     19         self.Gi=nx.grid_2d_graph(5,5)
     20         self.Gs=nx.Graph()
     21         self.Gs.add_path('abcdef')
     22         self.bigG=nx.grid_2d_graph(25,25) #bigger than 500 nodes for sparse
     23 
     24     def test_smoke_int(self):
     25         G=self.Gi
     26         vpos=nx.random_layout(G)
     27         vpos=nx.circular_layout(G)
     28         vpos=nx.spring_layout(G)
     29         vpos=nx.fruchterman_reingold_layout(G)
     30         vpos=nx.spectral_layout(G)
     31         vpos=nx.spectral_layout(self.bigG)
     32         vpos=nx.shell_layout(G)
     33 
     34     def test_smoke_string(self):
     35         G=self.Gs
     36         vpos=nx.random_layout(G)
     37         vpos=nx.circular_layout(G)
     38         vpos=nx.spring_layout(G)
     39         vpos=nx.fruchterman_reingold_layout(G)
     40         vpos=nx.spectral_layout(G)
     41         vpos=nx.shell_layout(G)
     42 
     43 
     44     def test_adjacency_interface_numpy(self):
     45         A=nx.to_numpy_matrix(self.Gs)
     46         pos=nx.drawing.layout._fruchterman_reingold(A)
     47         pos=nx.drawing.layout._fruchterman_reingold(A,dim=3)
     48         assert_equal(pos.shape,(6,3))
     49 
     50     def test_adjacency_interface_scipy(self):
     51         try:
     52             import scipy
     53         except ImportError:
     54             raise SkipTest('scipy not available.')
     55 
     56         A=nx.to_scipy_sparse_matrix(self.Gs,dtype='f')
     57         pos=nx.drawing.layout._sparse_fruchterman_reingold(A)
     58         pos=nx.drawing.layout._sparse_spectral(A)
     59 
     60         pos=nx.drawing.layout._sparse_fruchterman_reingold(A,dim=3)
     61         assert_equal(pos.shape,(6,3))
     62