"""
    Unit tests for matplotlib drawing functions.
"""

import os

from nose import SkipTest

import networkx as nx

class TestPylab(object):
    @classmethod
    def setupClass(cls):
        global plt
        try:
            import matplotlib as mpl
            mpl.use('PS',warn=False)
            import matplotlib.pyplot as plt
        except ImportError:
            raise SkipTest('matplotlib not available.')
        except RuntimeError:
            raise SkipTest('matplotlib not available.')

    def setUp(self):
        self.G=nx.barbell_graph(5,10)


    def test_draw(self):
        N=self.G
        nx.draw_spring(N)
        plt.savefig("test.ps")
        nx.draw_random(N)
        plt.savefig("test.ps")
        nx.draw_circular(N)
        plt.savefig("test.ps")
        nx.draw_spectral(N)
        plt.savefig("test.ps")
        nx.draw_spring(N.to_directed())
        plt.savefig("test.ps")
        os.unlink('test.ps')

@@ -325,24 +325,72 @@
 plot as plt%0A
+            plt.rcParams%5B'text.usetex'%5D = False%0A
         exce
@@ -401,24 +401,24 @@
 mportError:%0A
-
             
@@ -625,32 +625,49 @@
 est_draw(self):%0A
+        try:%0A    
         N=self.G
@@ -667,32 +667,36 @@
 =self.G%0A        
+  
+  
 nx.draw_spring(N
@@ -693,24 +693,28 @@
 w_spring(N)%0A
+    
         plt.
@@ -732,32 +732,36 @@
 st.ps%22)%0A        
+   
+ 
 nx.draw_random(N
@@ -758,24 +758,28 @@
 w_random(N)%0A
+    
         plt.
@@ -789,32 +789,36 @@
 efig(%22test.ps%22)%0A
+    
         nx.draw_
@@ -829,32 +829,36 @@
 ular(N)%0A        
+    
 plt.savefig(%22tes
@@ -864,32 +864,36 @@
 st.ps%22)%0A        
+    
 nx.draw_spectral
@@ -896,32 +896,36 @@
 tral(N)%0A        
+  
+  
 plt.savefig(%22tes
@@ -923,32 +923,36 @@
 efig(%22test.ps%22)%0A
+    
         nx.draw_
@@ -975,32 +975,36 @@
 cted())%0A        
+   
+ 
 plt.savefig(%22tes
@@ -1022,25 +1022,116 @@
     
-os.unlink('test.ps')
+finally:%0A            try:%0A                os.unlink('test.ps')%0A            except OSError:%0A                pass
 %0A

Make test_draw() more robust.