From: <jo...@us...> - 2009-06-14 05:38:12
|
Revision: 7218 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7218&view=rev Author: jouni Date: 2009-06-14 05:38:11 +0000 (Sun, 14 Jun 2009) Log Message: ----------- Extend backend_driver.py to support running only some test directories Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/examples/tests/backend_driver.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-06-14 01:32:20 UTC (rev 7217) +++ trunk/matplotlib/CHANGELOG 2009-06-14 05:38:11 UTC (rev 7218) @@ -1,3 +1,6 @@ +2009-06-14 Add new command line options to backend_driver.py to support + running only some directories of tests - JKS + 2009-06-13 partial cleanup of mlab and its importation in pylab - EF 2009-06-13 Introduce a rotation_mode property for the Text artist. See Modified: trunk/matplotlib/examples/tests/backend_driver.py =================================================================== --- trunk/matplotlib/examples/tests/backend_driver.py 2009-06-14 01:32:20 UTC (rev 7217) +++ trunk/matplotlib/examples/tests/backend_driver.py 2009-06-14 05:38:11 UTC (rev 7218) @@ -3,30 +3,40 @@ This is used to drive many of the examples across the backends, for regression testing, and comparing backend efficiency. -The script takes one or more arguments specifying backends -to be tested, e.g. +You can specify the backends to be tested either via the --backends +switch, which takes a comma-separated list, or as separate arguments, +e.g. python backend_driver.py agg ps cairo.png cairo.ps -would test the agg and ps backends, and the cairo backend with -output to png and ps files. +would test the agg and ps backends, and the cairo backend with output +to png and ps files. If no arguments are given, a default list of +backends will be tested. -If no arguments are given, a default list of backends will be -tested. +Interspersed with the backend arguments can be switches for the Python +interpreter executing the tests. If entering such arguments causes an +option parsing error with the driver script, separate them from driver +switches with a --. """ from __future__ import division -import os, time, sys, glob - +import os, time, sys, glob, string +from optparse import OptionParser import matplotlib.rcsetup as rcsetup +from matplotlib.cbook import Bunch, dedent all_backends = list(rcsetup.all_backends) # to leave the original list alone all_backends.extend(['cairo.png', 'cairo.ps', 'cairo.pdf', 'cairo.svg']) -pylab_dir = os.path.join('..', 'pylab_examples') -pylab_files = [ +# actual physical directory for each dir +dirs = dict(pylab = os.path.join('..', 'pylab_examples'), + api = os.path.join('..', 'api'), + units = os.path.join('..', 'units'), + mplot3d = os.path.join('..', 'mplot3d')) - +# files in each dir +files = dict() +files['pylab'] = [ 'accented_text.py', 'alignment_test.py', 'annotation_demo.py', @@ -196,8 +206,7 @@ ] -api_dir = os.path.join('..', 'api') -api_files = [ +files['api'] = [ 'agg_oo.py', 'barchart_demo.py', 'bbox_intersect.py', @@ -228,8 +237,7 @@ 'watermark_text.py', ] -units_dir = os.path.join('..', 'units') -units_files = [ +files['units'] = [ 'annotate_with_units.py', #'artist_tests.py', # broken, fixme 'bar_demo2.py', @@ -241,8 +249,7 @@ ] -mplot3d_dir = os.path.join('..', 'mplot3d') -mplot3d_files = [ +files['mplot3d'] = [ '2dcollections3d_demo.py', 'bars3d_demo.py', 'contour3d_demo.py', @@ -263,8 +270,8 @@ # examples that generate multiple figures excluded = { - pylab_dir : ['__init__.py', 'toggle_images.py',], - units_dir : ['__init__.py', 'date_support.py',], + 'pylab' : ['__init__.py', 'toggle_images.py',], + 'units' : ['__init__.py', 'date_support.py',], } def report_missing(dir, flist): @@ -278,24 +285,16 @@ flist = set(flist) missing = list(pyfiles-flist-exclude) missing.sort() - print '%s files not tested: %s'%(dir, ', '.join(missing)) + if missing: + print '%s files not tested: %s'%(dir, ', '.join(missing)) +def report_all_missing(directories): + for f in directories: + report_missing(dirs[f], files[f]) -report_missing(pylab_dir, pylab_files) -report_missing(api_dir, api_files) -report_missing(units_dir, units_files) -report_missing(mplot3d_dir, mplot3d_files) -files = ( - [os.path.join(api_dir, fname) for fname in api_files] + - [os.path.join(pylab_dir, fname) for fname in pylab_files] + - [os.path.join(units_dir, fname) for fname in units_files] + - [os.path.join(mplot3d_dir, fname) for fname in mplot3d_files] - ) - # tests known to fail on a given backend - failbackend = dict( svg = ('tex_demo.py', ), agg = ('hyperlinks.py', ), @@ -317,7 +316,7 @@ def run(arglist): os.system(' '.join(arglist)) -def drive(backend, python=['python'], switches = []): +def drive(backend, directories, python=['python'], switches = []): exclude = failbackend.get(backend, []) # Clear the destination directory for the examples @@ -329,8 +328,12 @@ else: os.mkdir(backend) failures = [] - for fullpath in files: + testcases = [os.path.join(dirs[d], fname) + for d in directories + for fname in files[d]] + + for fullpath in testcases: print ('\tdriving %-40s' % (fullpath)), sys.stdout.flush() @@ -376,21 +379,64 @@ tmpfile.close() start_time = time.time() program = [x % {'name': basename} for x in python] - ret = run(program + [tmpfile_name, switchstring]) + ret = run(program + [tmpfile_name] + switches) end_time = time.time() print (end_time - start_time), ret - #os.system('%s %s %s' % (python, tmpfile_name, switchstring)) + #os.system('%s %s %s' % (python, tmpfile_name, ' '.join(switches))) os.remove(tmpfile_name) if ret: failures.append(fullpath) return failures +def parse_options(): + doc = __doc__.split('\n\n') + op = OptionParser(description=doc[0].strip(), + usage='%prog [options] [--] [backends and switches]', + epilog='\n'.join(doc[1:])) + op.disable_interspersed_args() + op.set_defaults(dirs='pylab,api,units,mplot3d', + clean=False, coverage=False, valgrind=False) + op.add_option('-d', '--dirs', '--directories', type='string', + dest='dirs', help=dedent(''' + Run only the tests in these directories; comma-separated list of + one or more of: pylab (or pylab_examples), api, units, mplot3d''')) + op.add_option('-b', '--backends', type='string', dest='backends', + help=dedent(''' + Run tests only for these backends; comma-separated list of + one or more of: agg, ps, svg, pdf, template, cairo, + cairo.png, cairo.ps, cairo.pdf, cairo.svg. Default is everything + except cairo.''')) + op.add_option('--clean', action='store_true', dest='clean', + help='Remove result directories, run no tests') + op.add_option('-c', '--coverage', action='store_true', dest='coverage', + help='Run in coverage.py') + op.add_option('-v', '--valgrind', action='store_true', dest='valgrind', + help='Run in valgrind') + options, args = op.parse_args() + switches = [x for x in args if x.startswith('--')] + backends = [x.lower() for x in args if not x.startswith('--')] + if options.backends: + backends += map(string.lower, options.backends.split(',')) + + result = Bunch( + dirs = options.dirs.split(','), + backends = backends or ['agg', 'ps', 'svg', 'pdf', 'template'], + clean = options.clean, + coverage = options.coverage, + valgrind = options.valgrind, + switches = switches) + if 'pylab_examples' in result.dirs: + result.dirs[result.dirs.index('pylab_examples')] = 'pylab' + #print result + return result + if __name__ == '__main__': times = {} failures = {} - default_backends = ['agg', 'ps', 'svg', 'pdf', 'template'] - if len(sys.argv)==2 and sys.argv[1]=='--clean': + options = parse_options() + + if options.clean: localdirs = [d for d in glob.glob('*') if os.path.isdir(d)] all_backends_set = set(all_backends) for d in localdirs: @@ -405,38 +451,31 @@ print 'all clean...' raise SystemExit - if '--coverage' in sys.argv: + if options.coverage: python = ['coverage.py', '-x'] - sys.argv.remove('--coverage') - elif '--valgrind' in sys.argv: + elif options.valgrind: python = ['valgrind', '--tool=memcheck', '--leak-check=yes', '--log-file=%(name)s', 'python'] - sys.argv.remove('--valgrind') elif sys.platform == 'win32': python = [r'c:\Python24\python.exe'] else: python = ['python'] - backends = [] - switches = [] - if sys.argv[1:]: - backends = [b.lower() for b in sys.argv[1:] if b.lower() in all_backends] - switches = [s for s in sys.argv[1:] if s.startswith('--')] - if not backends: - backends = default_backends - for backend in backends: - switchstring = ' '.join(switches) - print 'testing %s %s' % (backend, switchstring) + + report_all_missing(options.dirs) + for backend in options.backends: + print 'testing %s %s' % (backend, ' '.join(options.switches)) t0 = time.time() - failures[backend] = drive(backend, python, switches) + failures[backend] = \ + drive(backend, options.dirs, python, options.switches) t1 = time.time() times[backend] = (t1-t0)/60.0 # print times for backend, elapsed in times.items(): - print 'Backend %s took %1.2f minutes to complete' % ( backend, elapsed) + print 'Backend %s took %1.2f minutes to complete' % (backend, elapsed) failed = failures[backend] if failed: print ' Failures: ', failed - if 'Template' in times: + if 'template' in times: print '\ttemplate ratio %1.3f, template residual %1.3f' % ( - elapsed/times['Template'], elapsed-times['Template']) + elapsed/times['template'], elapsed-times['template']) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |