GUITESTS: Improve the running script.

Don't use recursion in the script. The Python's os.walk() already
lists all files in subdirectories and using recursion only caused
tests to be found twice. Also handle the case the project file
defines binary path with DESTDIR define.
This commit is contained in:
Kimmo Varis 2011-06-23 23:02:49 +03:00
parent 40a14736b7
commit 387fd35ff3
1 changed files with 32 additions and 19 deletions

View File

@ -23,6 +23,9 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
# Project repository:
# https://bitbucket.org/kimmov/testrun
'''Runs all the GUI tests in subdirectories.''' '''Runs all the GUI tests in subdirectories.'''
import os import os
@ -49,11 +52,12 @@ class TestList:
self._filelist = [] self._filelist = []
self._basedirectory = None self._basedirectory = None
def findtests(self, directory = ''): def findtests(self, directory):
'''Finds all tests from subdirectories of the given directory.''' '''Finds all tests from subdirectories of the given directory.'''
if directory == None or directory == '': if not os.path.exists(directory):
directory = os.getcwd() print 'Directory does not exist!'
return
self._basedirectory = directory self._basedirectory = directory
self._listprofiles(directory) self._listprofiles(directory)
@ -72,10 +76,6 @@ class TestList:
for root, dirnames, filenames in os.walk(directory): for root, dirnames, filenames in os.walk(directory):
self._walkfiles(root, filenames) self._walkfiles(root, filenames)
for curdir in dirnames:
fullpath = os.path.join(root, curdir)
self._listprofiles(fullpath)
def _walkfiles(self, dirname, filenames): def _walkfiles(self, dirname, filenames):
'''Find .pro files from list of given filenames. '''Find .pro files from list of given filenames.
@ -100,10 +100,13 @@ class TestList:
for fullpath, relpath in self._filelist: for fullpath, relpath in self._filelist:
#print 'Reading file: %s' % relpath #print 'Reading file: %s' % relpath
f = open(fullpath, 'r') f = open(fullpath, 'r')
targetfound = False target = ''
while not targetfound: destdir = ''
allread = False
while not allread:
line = f.readline() line = f.readline()
if line == '': if line == '':
allread = True
break break
line = line.strip() line = line.strip()
@ -111,18 +114,27 @@ class TestList:
target = line[line.find('=') + 1:] target = line[line.find('=') + 1:]
target = target.strip() target = target.strip()
#print 'File: %s Target: %s' % (relpath, target) #print 'File: %s Target: %s' % (relpath, target)
path = os.path.dirname(fullpath)
target = os.path.join(path, target)
targetfound = True
if os.path.exists(target): if line.startswith('DESTDIR'):
destdir = line[line.find('=') + 1:]
destdir = destdir.strip()
#print 'File: %s Dest: %s' % (relpath, dest)
f.close()
if target != '':
path = os.path.dirname(fullpath)
if destdir != '':
path = os.path.join(path, destdir)
path = os.path.join(path, target)
path = os.path.normpath(path)
#print 'Found test: %s' % path
if os.path.exists(path):
testinfo = Test() testinfo = Test()
testinfo.profile = relpath testinfo.profile = relpath
testinfo.binary = target testinfo.binary = path
self._testlist.append(testinfo) self._testlist.append(testinfo)
f.close()
class TestRunner: class TestRunner:
def __init__(self, testlist): def __init__(self, testlist):
@ -176,7 +188,8 @@ class TestRunner:
def main(): def main():
lister = TestList() lister = TestList()
lister.findtests() directory = os.getcwd()
lister.findtests(directory)
runner = TestRunner(lister.testlist()) runner = TestRunner(lister.testlist())
runner.runtests() runner.runtests()
return 0 return 0