clean up, added --debug to base class, renamed testPossible to feasible

This commit is contained in:
Philip Eisenlohr 2016-09-01 15:37:49 -04:00
parent 6db0a42eae
commit 32c4a20a46
1 changed files with 39 additions and 30 deletions

View File

@ -17,40 +17,47 @@ class Test():
variants = [] variants = []
def __init__(self,test_description): def __init__(self,description = ''):
logger = logging.getLogger()
logger.setLevel(0)
fh = logging.FileHandler('test.log') # create file handler which logs even debug messages fh = logging.FileHandler('test.log') # create file handler which logs even debug messages
fh.setLevel(logging.DEBUG) fh.setLevel(logging.DEBUG)
full = logging.Formatter('%(asctime)s - %(levelname)s: \n%(message)s') fh.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s: \n%(message)s'))
fh.setFormatter(full)
ch = logging.StreamHandler(stream=sys.stdout) # create console handler with a higher log level ch = logging.StreamHandler(stream=sys.stdout) # create console handler with a higher log level
ch.setLevel(logging.INFO) ch.setLevel(logging.INFO)
# create formatter and add it to the handlers ch.setFormatter(logging.Formatter('%(message)s'))
plain = logging.Formatter('%(message)s')
ch.setFormatter(plain) logger = logging.getLogger()
# add the handlers to the logger
logger.addHandler(fh) logger.addHandler(fh)
logger.addHandler(ch) logger.addHandler(ch)
logger.setLevel(0)
logging.info('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n' \ logging.info('\n'.join(['+'*40,
+'----------------------------------------------------------------\n' \ '-'*40,
+'| '+test_description+'\n' \ '| '+description,
+'----------------------------------------------------------------') '-'*40,
]))
self.dirBase = os.path.dirname(os.path.realpath(sys.modules[self.__class__.__module__].__file__)) self.dirBase = os.path.dirname(os.path.realpath(sys.modules[self.__class__.__module__].__file__))
self.parser = OptionParser(
description = test_description+' (using class: {})'.format(damask.version), self.parser = OptionParser(description = '{} (using class: {})'.format(description,damask.version),
usage='./test.py [options]') usage = './test.py [options]')
self.updateRequested = False self.parser.add_option("-d", "--debug",
self.parser.add_option("-d", "--debug", action="store_true",\ action = "store_true",
dest="debug",\ dest = "debug",
help="debug run, don't calculate but use existing results") help = "debug run, don't calculate but use existing results")
self.parser.add_option("-p", "--pass", action="store_true",\ self.parser.add_option("-p", "--pass",
dest="accept",\ action = "store_true",
help="calculate results but always consider test as successfull") dest = "accept",
self.parser.set_defaults(debug=False, help = "calculate results but always consider test as successfull")
accept=False) self.parser.add_option("-u", "--update",
action = "store_true",
dest = "update",
help = "use current test results as new reference"
)
self.parser.set_defaults(debug = False,
accept = False,
update = False,
)
def execute(self): def execute(self):
"""Run all variants and report first failure.""" """Run all variants and report first failure."""
@ -65,15 +72,17 @@ class Test():
return variant+1 # return culprit return variant+1 # return culprit
return 0 return 0
else: else:
if not self.testPossible(): return -1 if not self.feasible(): return -1
self.clean() self.clean()
self.prepareAll() self.prepareAll()
for variant in xrange(len(self.variants)):
for variant,name in enumerate(self.variants):
try: try:
self.prepare(variant) self.prepare(variant)
self.run(variant) self.run(variant)
self.postprocess(variant) self.postprocess(variant)
if self.updateRequested: # update requested if self.options.update: # update requested
self.update(variant) self.update(variant)
elif not (self.options.accept or self.compare(variant)): # no update, do comparison elif not (self.options.accept or self.compare(variant)): # no update, do comparison
return variant+1 # return culprit return variant+1 # return culprit
@ -82,8 +91,8 @@ class Test():
return variant+1 # return culprit return variant+1 # return culprit
return 0 return 0
def testPossible(self): def feasible(self):
"""Check if test is possible or not (e.g. no license available).""" """Check whether test is possible or not (e.g. no license available)."""
return True return True
def clean(self): def clean(self):