| 1 | #!/usr/bin/python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | ## |
|---|
| 4 | ## runtests.py -- Runs tests to verify the gdhost code works |
|---|
| 5 | ## Started on Wed Sep 14 23:49:35 2005 Christian Höltje |
|---|
| 6 | ## |
|---|
| 7 | ## Copyright (C) 2005 Christian Höltje |
|---|
| 8 | ## This program is free software; you can redistribute it and/or modify |
|---|
| 9 | ## it under the terms of the GNU General Public License as published by |
|---|
| 10 | ## the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | ## (at your option) any later version. |
|---|
| 12 | ## |
|---|
| 13 | ## This program is distributed in the hope that it will be useful, |
|---|
| 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | ## GNU General Public License for more details. |
|---|
| 17 | ## |
|---|
| 18 | ## You should have received a copy of the GNU General Public License |
|---|
| 19 | ## along with this program; if not, write to the Free Software |
|---|
| 20 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 21 | ## |
|---|
| 22 | |
|---|
| 23 | import os, sys |
|---|
| 24 | import unittest |
|---|
| 25 | sys.path.insert(0,os.path.realpath(os.curdir)) |
|---|
| 26 | |
|---|
| 27 | def importdir( dir, limit=3, strip=None, verbose=0 ): |
|---|
| 28 | global counter |
|---|
| 29 | if verbose: print "importdir( %s, %d, %s, %s )" % (dir, limit, |
|---|
| 30 | strip, verbose) |
|---|
| 31 | if limit <= 0: |
|---|
| 32 | return [] |
|---|
| 33 | dir = os.path.abspath( dir ) |
|---|
| 34 | if strip is None: |
|---|
| 35 | strip = len(os.path.abspath( os.curdir ) + os.sep) |
|---|
| 36 | filelist = os.listdir( dir ) |
|---|
| 37 | filelist.sort() |
|---|
| 38 | output = [] |
|---|
| 39 | for file in filelist: |
|---|
| 40 | path = os.path.join( dir, file )[strip:] |
|---|
| 41 | if os.path.isdir( path ): |
|---|
| 42 | if not ( |
|---|
| 43 | file.startswith('.') |
|---|
| 44 | ): |
|---|
| 45 | output.extend( importdir( path, limit - 1, strip, verbose ) ) |
|---|
| 46 | elif os.path.isfile( path ) and \ |
|---|
| 47 | file.endswith('.py') and \ |
|---|
| 48 | not ( |
|---|
| 49 | file.startswith( '_' ) or \ |
|---|
| 50 | file.startswith( 'testall.py' ) or \ |
|---|
| 51 | file.find( '#' ) >= 0 |
|---|
| 52 | ): |
|---|
| 53 | imp = path[:-3].replace(os.sep,'.') |
|---|
| 54 | if verbose: print " Importing '%s'..."% imp |
|---|
| 55 | output.append( "from %s import *" % imp ) |
|---|
| 56 | elif verbose: print " skipping '%s'" % path |
|---|
| 57 | return output |
|---|
| 58 | |
|---|
| 59 | if __name__ == "__main__": |
|---|
| 60 | for e in importdir( |
|---|
| 61 | os.path.join( os.curdir, 'gdhost' ), |
|---|
| 62 | verbose=('-v' in sys.argv) ): |
|---|
| 63 | exec e |
|---|
| 64 | unittest.main() |
|---|