11#!/usr/bin/env python
22"""
33This is used to drive many of the examples across the backends, for
4- regression testing, and comparing backend efficiency
4+ regression testing, and comparing backend efficiency.
5+
6+ The script takes one or more arguments specifying backends
7+ to be tested, e.g.
8+
9+ python backend_driver.py agg ps cairo.png cairo.ps
10+
11+ would test the agg and ps backends, and the cairo backend with
12+ output to png and ps files.
13+
14+ If no arguments are given, a default list of backends will be
15+ tested.
516"""
617
718from __future__ import division
@@ -98,7 +109,11 @@ def drive(backend, python='python', switches = []):
98109
99110 exclude = failbackend .get (backend , [])
100111 switchstring = ' ' .join (switches )
101-
112+ # Strip off the format specifier, if any.
113+ if backend .startswith ('cairo' ):
114+ _backend = 'cairo'
115+ else :
116+ _backend = backend
102117 for fname in files :
103118 if fname in exclude :
104119 print '\t Skipping %s, known to fail on backend: %s' % backend
@@ -107,17 +122,13 @@ def drive(backend, python='python', switches = []):
107122 print '\t driving %s %s' % (fname , switchstring )
108123 basename , ext = os .path .splitext (fname )
109124 outfile = basename + '_%s' % backend
110- # The following is temporary, until I put in a command-line
111- # argument to specify the output.
112- if backend .lower () == 'cairo' :
113- outfile += '.png'
114125 tmpfile_name = '_tmp_%s.py' % basename
115126 tmpfile = file (tmpfile_name , 'w' )
116127
117128 tmpfile .writelines ((
118129 'from __future__ import division\n ' ,
119130 'import matplotlib\n ' ,
120- 'matplotlib.use("%s")\n ' % backend ,
131+ 'matplotlib.use("%s")\n ' % _backend ,
121132 'from pylab import savefig\n ' ,
122133 ))
123134 for line in file (fname ):
@@ -138,18 +149,19 @@ def drive(backend, python='python', switches = []):
138149 #os.system('%s %s %s' % (python, tmpfile_name, switchstring))
139150 os .remove (tmpfile_name )
140151
141-
142152if __name__ == '__main__' :
143153 times = {}
144154 default_backends = ['Agg' , 'PS' , 'SVG' , 'Template' ]
145155 if sys .platform == 'win32' :
146156 python = r'c:\Python24\python.exe'
147157 else :
148158 python = 'python'
159+ all_backends = [b .lower () for b in mplbe .all_backends ]
160+ all_backends .extend (['cairo.png' , 'cairo.ps' , 'cairo.pdf' , 'cairo.svg' ])
149161 backends = []
150162 switches = []
151163 if sys .argv [1 :]:
152- backends = [b for b in sys .argv [1 :] if b in mplbe . all_backends ]
164+ backends = [b . lower () for b in sys .argv [1 :] if b . lower () in all_backends ]
153165 switches = [s for s in sys .argv [1 :] if s .startswith ('--' )]
154166 if not backends :
155167 backends = default_backends
0 commit comments