from subprocess import Popen
from sys import argv
from sys import maxint
-from sys import exit
from threading import Timer
from time import time
self.timeout = 60
def __str__(self):
- return "Pathname: %s\nOutputdir: %s\nTimeout: %d\nUser: %s\n" % (
- self.pathname, self.outputdir, self.timeout, self.user)
+ return "Pathname: %s\nOutputdir: %s\nTimeout: %d\nUser: %s\n" % \
+ (self.pathname, self.outputdir, self.timeout, self.user)
def kill_cmd(self, proc):
"""
if len(self.post_user):
post_user = ' (as %s)' % (self.post_user)
return "Pathname: %s\nOutputdir: %s\nTimeout: %d\nPre: %s%s\nPost: " \
- "%s%s\nUser: %s\n" % (
- self.pathname, self.outputdir,
- self.timeout, self.pre, pre_user, self.post, post_user,
- self.user)
+ "%s%s\nUser: %s\n" % \
+ (self.pathname, self.outputdir, self.timeout, self.pre,
+ pre_user, self.post, post_user, self.user)
def verify(self, logger):
"""
Create Cmd instances for the pre/post scripts. If the pre script
doesn't pass, skip this Test. Run the post script regardless.
"""
- pretest = Cmd(self.pre, outputdir=os.path.join(self.outputdir,
- os.path.basename(self.pre)), timeout=self.timeout,
+ odir = os.path.join(self.outputdir, os.path.basename(self.pre))
+ pretest = Cmd(self.pre, outputdir=odir, timeout=self.timeout,
user=self.pre_user)
test = Cmd(self.pathname, outputdir=self.outputdir,
timeout=self.timeout, user=self.user)
- posttest = Cmd(self.post, outputdir=os.path.join(self.outputdir,
- os.path.basename(self.post)), timeout=self.timeout,
+ odir = os.path.join(self.outputdir, os.path.basename(self.post))
+ posttest = Cmd(self.post, outputdir=odir, timeout=self.timeout,
user=self.post_user)
cont = True
if len(self.post_user):
post_user = ' (as %s)' % (self.post_user)
return "Pathname: %s\nOutputdir: %s\nTests: %s\nTimeout: %d\n" \
- "Pre: %s%s\nPost: %s%s\nUser: %s\n" % (
- self.pathname, self.outputdir, self.tests, self.timeout,
+ "Pre: %s%s\nPost: %s%s\nUser: %s\n" % \
+ (self.pathname, self.outputdir, self.tests, self.timeout,
self.pre, pre_user, self.post, post_user, self.user)
def verify(self, logger):
doesn't pass, skip all the tests in this TestGroup. Run the post
script regardless.
"""
- pretest = Cmd(self.pre, outputdir=os.path.join(self.outputdir,
- os.path.basename(self.pre)), timeout=self.timeout,
+ odir = os.path.join(self.outputdir, os.path.basename(self.pre))
+ pretest = Cmd(self.pre, outputdir=odir, timeout=self.timeout,
user=self.pre_user)
- posttest = Cmd(self.post, outputdir=os.path.join(self.outputdir,
- os.path.basename(self.post)), timeout=self.timeout,
+ odir = os.path.join(self.outputdir, os.path.basename(self.post))
+ posttest = Cmd(self.post, outputdir=odir, timeout=self.timeout,
user=self.post_user)
cont = True
testgroup = TestGroup(os.path.abspath(pathname))
for prop in TestGroup.props:
- try:
- setattr(testgroup, prop, config.get('DEFAULT', prop))
- setattr(testgroup, prop, config.get(section, prop))
- except ConfigParser.NoOptionError:
- pass
+ for sect in ['DEFAULT', section]:
+ if config.has_option(sect, prop):
+ setattr(testgroup, prop, config.get(sect, prop))
# Repopulate tests using eval to convert the string to a list
testgroup.tests = eval(config.get(section, 'tests'))
else:
test = Test(section)
for prop in Test.props:
- try:
- setattr(test, prop, config.get('DEFAULT', prop))
- setattr(test, prop, config.get(section, prop))
- except ConfigParser.NoOptionError:
- pass
+ for sect in ['DEFAULT', section]:
+ if config.has_option(sect, prop):
+ setattr(test, prop, config.get(sect, prop))
+
if test.verify(logger):
self.tests[section] = test
"""
defaults = dict([(prop, getattr(options, prop)) for prop, _ in
- self.defaults])
+ self.defaults])
config = ConfigParser.RawConfigParser(defaults)
for test in sorted(self.tests.keys()):
except IOError:
fail('Could not open \'%s\' for writing.' % options.template)
- def complete_outputdirs(self, options):
+ def complete_outputdirs(self):
"""
Collect all the pathnames for Tests, and TestGroups. Work
backwards one pathname component at a time, to create a unique
m, s = divmod(time() - self.starttime, 60)
h, m = divmod(m, 60)
print '\nRunning Time:\t%02d:%02d:%02d' % (h, m, s)
- print 'Percent passed:\t%.1f%%' % (
- (float(Result.runresults['PASS']) / float(Result.total)) * 100)
+ print 'Percent passed:\t%.1f%%' % ((float(Result.runresults['PASS']) /
+ float(Result.total)) * 100)
print 'Log directory:\t%s' % self.outputdir
path_options = ['runfile', 'outputdir', 'template', 'testdir']
if option.dest is 'runfile' and '-w' in parser.rargs or \
- option.dest is 'template' and '-c' in parser.rargs:
+ option.dest is 'template' and '-c' in parser.rargs:
fail('-c and -w are mutually exclusive.')
if opt_str in parser.rargs:
return options
-def main(args):
+def main():
options = parse_args()
testrun = TestRun(options)
else:
fail('Unknown command specified')
- testrun.complete_outputdirs(options)
+ testrun.complete_outputdirs()
testrun.run(options)
testrun.summary()
exit(0)
if __name__ == '__main__':
- main(argv[1:])
+ main()