1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
# -*- coding: latin1 -*-
"""Script for executing the Unit-Tests in the sourcen.
"""
import os
################################################################################
# BuildError
class BuildError(Exception):
"""Throw an exception, when there is an error while building.
"""
################################################################################
# shell_command
def shell_command(cmd):
"""Start a process and return the process-output as string.
"""
cmd2 = cmd + ' 2>&1'
p = os.popen(cmd2)
lines = []
line = p.readline()
while line:
lines.append(line)
line = p.readline()
try:
status = p.close()
except KeyboardInterrupt, e:
raise
except:
raise BuildError(''.join(lines))
if status:
raise BuildError(''.join(lines))
return lines
################################################################################
# execute_config
def execute_testscripts(path, config):
"""Seach the scripts with end .test.pl, .test.py, .test.bat in the transmitted files and execute it
If the returned status ist defferent to 0, the returned value will be add as Error.
A table ist returned, per testscript an incertion with the error-message.
"""
messages = {};
for root, dirs, files in os.walk(path):
if root.find('.svn') < 0: # nicht die Dateien aus den .svn-Verzeichnissen
for file in files:
cmd = None
if file.lower().endswith('.test.pl'):
cmd = 'perl.exe '
elif file.lower().endswith('.test.py'):
cmd = 'python.exe '
elif file.lower().endswith('.test.bat'):
cmd = 'cmd /C '
if cmd:
cmd += root + '\\' + file
print '%-30s ' % file,
try:
if 'Debug' in dirs:
shell_command('rmdir /S /Q ' + root + '\\Debug') # Delete all files from last tests
shell_command(cmd + ' %s' % config)
print 'ok'
messages[file] = ''
except BuildError, e:
print 'Fehler'
messages[file] = str(e)
return messages
################################################################################
# main
def main():
"""The "mainprogramm".
"""
import sys
rootpath = sys.argv[1]
messages = execute_testscripts(rootpath, 'Debug')
text = ''
has_errors = False
for file in sorted(messages.keys()):
status = 'ok'
if messages[file]:
status = 'Fehler'
has_errors = True
text += '%-30s %s\n' % (file, status)
if messages[file]:
text += '=' * 80 + '\n'
text += messages[file]
text += '=' * 80 + '\n\n'
dumpFile = open(sys.argv[2], 'w')
dumpFile.write(text)
dumpFile.close()
return has_errors
################################################################################
if __name__ == '__main__':
main() |
Partager