| 1 | #!/usr/bin/python |
|---|
| 2 | |
|---|
| 3 | # First cut of a routine to run our unittests for the |
|---|
| 4 | # MysteryMachine Project |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | # runtests.sh - Copyright Roger Gammans |
|---|
| 8 | # |
|---|
| 9 | # |
|---|
| 10 | # This program is free software; you can redistribute it and/or modify |
|---|
| 11 | # it under the terms of the GNU General Public License as published by |
|---|
| 12 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 13 | # (at your option) any later version. |
|---|
| 14 | # |
|---|
| 15 | # This program is distributed in the hope that it will be useful, |
|---|
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 18 | # GNU General Public License for more details. |
|---|
| 19 | # |
|---|
| 20 | # You should have received a copy of the GNU General Public License along |
|---|
| 21 | # with this program; if not, write to the Free Software Foundation, Inc., |
|---|
| 22 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|---|
| 23 | # |
|---|
| 24 | import os |
|---|
| 25 | import imp |
|---|
| 26 | import sys |
|---|
| 27 | import re |
|---|
| 28 | |
|---|
| 29 | PYTHONS =( 'python2.5', 'python2.6', 'python2.6 -3') |
|---|
| 30 | UNITTEST ='/usr/lib/python2.6/unittest.py' |
|---|
| 31 | TESTSDIR ='tests' |
|---|
| 32 | |
|---|
| 33 | STRIP = re.compile('\.py$') |
|---|
| 34 | |
|---|
| 35 | sys.path.insert(0,"./%s" % TESTSDIR ) |
|---|
| 36 | |
|---|
| 37 | path=os.getenv("PYTHONPATH") |
|---|
| 38 | if path == None: |
|---|
| 39 | path = "." |
|---|
| 40 | else: |
|---|
| 41 | #FIXME: Needs to be ';' under windows |
|---|
| 42 | path = ".:" + path |
|---|
| 43 | |
|---|
| 44 | os.putenv("PYTHONPATH",path) |
|---|
| 45 | |
|---|
| 46 | def NoTests(): |
|---|
| 47 | return( ) |
|---|
| 48 | |
|---|
| 49 | #Allow the ability to run tests under a single python. |
|---|
| 50 | if len(sys.argv) > 1: |
|---|
| 51 | DEFPYTHONS=PYTHONS |
|---|
| 52 | PYTHONS = [] |
|---|
| 53 | |
|---|
| 54 | for arg in sys.argv[1:]: |
|---|
| 55 | print arg |
|---|
| 56 | PYTHONS += [ 'python%s' % arg ] |
|---|
| 57 | |
|---|
| 58 | for python in (PYTHONS): |
|---|
| 59 | sys.stderr.write( "Testing under %s:\n" % python ) |
|---|
| 60 | #TODO: should this inner loop go inside tests/__init__.py ? |
|---|
| 61 | for module in os.listdir('tests/'): |
|---|
| 62 | #Turn filenmae into module name |
|---|
| 63 | testname , replaced =re.subn(STRIP,"",module) |
|---|
| 64 | # SKip invalid module names |
|---|
| 65 | if not replaced: continue |
|---|
| 66 | #run tests. |
|---|
| 67 | sys.stderr.write("Running %s (%s)" % (module,python) ) |
|---|
| 68 | os.system("%s %s/%s" % ( python, TESTSDIR, module)) |
|---|
| 69 | |
|---|
| 70 | sys.stderr.write("\n") |
|---|
| 71 | sys.stdout.write("\n") |
|---|