#!/usr/bin/python # Copyright (c) 2005 by Mark T. Holder, Florida State University. (see end of file) '''Tool for launching all scripts that match PIPRes rules for a test (starts "test_" ends with ".py"). Acts recursive by default.''' import sys, os def printHelp(): scriptName = os.path.basename(sys.argv[0]) print scriptName, ''', a simple tool for launching all scripts that match PIPRes rules for a test (a file that starts "test_" ends with ".py"). Arguments are interpretted as directories to search. If no arguments are given, the current working directory will be used. By default directories starting with "test" will also be processed. Use the --norec option to suppress recursion (applies to subsequent directories listed).''' def runTestsOnDir(d, recurse): if not os.path.exists(d): print >> sys.stderr, d, 'does not exists.' return False if not os.path.isdir(d): print >> sys.stderr, d, 'is not a directory.' return False children = os.listdir(d) failedTests = [] cached_pwd = os.getcwd() os.chdir(d) passedTests = 0 for i in children: filename = os.path.basename(i) if filename.startswith('test'): fullpath = os.path.join(d, i) if not os.path.isdir(fullpath): if filename.startswith('test_') and filename.endswith('.py'): cmd = 'python "%s"' % fullpath print fullpath if os.system(cmd): failedTests.append(fullpath) else: passedTests += 1 elif recurse: f, p = runTestsOnDir(fullpath, True) failedTests += f passedTests += p os.chdir(cached_pwd) return failedTests, passedTests if __name__ == '__main__': recurse = True dirProcessed = False failedTests = [] passedTests = 0 for a in sys.argv[1:]: cap = a.upper() if cap == '--HELP': printHelp() elif cap == '--NOREC': recurse = False else: dirProcessed = True f, p = runTestsOnDir(a, recurse) failedTests += f passedTests += p if not dirProcessed: failedTests, passedTests = runTestsOnDir(os.getcwd(), recurse) print '============================================================================' print 'Failed ', len(failedTests), 'test scripts.' if len(failedTests) > 0: print '\t' + '\n\t'.join([str(i) for i in failedTests]) print 'Passed ', passedTests, 'test scripts' if len(failedTests) == 0: print 'OK' if not os.environ.get('PIPRES_ROOT') and os.environ.get('CIPRES_ROOT'): print """The environment variables PIPRES_ROOT and CIPRES_ROOT are not set. This will cause several tests to fail. These tests should be: """, '\n '.join([ 'test/test_util/test_cipres_registry.py', 'test/test_util/test_io.py', 'test/test_util/test_rich_cipres_registry.py',]) sys.exit(len(failedTests)) # This file is part of the PIPRes library # # The PIPRes library is free software; you can redistribute it # and/or modify it under the terms of the GNU Lesser General # Public License as published by the Free Software Foundation; # either version 2.1 of the License, or (at your option) any later # version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, # MA 02111-1307, USA