simplified updating

This commit is contained in:
Martin Diehl 2014-06-03 13:09:52 +00:00
parent 5321019457
commit 41b097bbc1
1 changed files with 25 additions and 8 deletions

View File

@ -24,7 +24,7 @@ class Test():
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( self.parser = OptionParser(
description = 'Using: $Id run_test.py 1285 2012-02-09 08:54:09Z MPIE\m.diehl $', description = 'Using: $Id run_test.py 1285 2012-02-09 08:54:09Z MPIE\m.diehl $',
usage='run_test.py [options]') usage='./test.py [options]')
self.parser.add_option("-u", "--update", action="store_true",\ self.parser.add_option("-u", "--update", action="store_true",\
dest="update",\ dest="update",\
@ -33,13 +33,12 @@ class Test():
(self.options, self.args) = self.parser.parse_args() (self.options, self.args) = self.parser.parse_args()
def execute(self,variants = [],update = []): def execute(self):
''' '''
Run all variants and report first failure. Run all variants and report first failure.
''' '''
if not self.testPossible(): return -1 if not self.testPossible(): return -1
if len(update) == 0 and self.options.update: print(' This test has no reference to update') if len(variants) == 0: variants = xrange(len(self.variants)) # iterate over all variants
if len(variants) == 0: variants = xrange(len(self.variants)) # iterate over all variants
self.clean() self.clean()
self.prepareAll() self.prepareAll()
for variant in variants: for variant in variants:
@ -47,13 +46,13 @@ class Test():
self.prepare(variant) self.prepare(variant)
self.run(variant) self.run(variant)
self.postprocess(variant) self.postprocess(variant)
if variant in update: if options.update: # update requested
self.update(variant) self.update(variant)
elif not self.compare(variant): elif not self.compare(variant): # no update, do comparison
return variant+1 return variant+1 # return culprit
except Exception as e : except Exception as e :
print('\nWARNING:\n %s\n'%e) print('\nWARNING:\n %s\n'%e)
return variant+1 return variant+1 # return culprit
return 0 return 0
def testPossible(self): def testPossible(self):
@ -120,6 +119,7 @@ class Test():
''' '''
Update reference with current results. Update reference with current results.
''' '''
print('Update not necessary')
return True return True
@ -129,17 +129,20 @@ class Test():
''' '''
return os.path.normpath(os.path.join(self.dirBase,'reference/')) return os.path.normpath(os.path.join(self.dirBase,'reference/'))
def dirCurrent(self): def dirCurrent(self):
''' '''
Directory containing current results of the test. Directory containing current results of the test.
''' '''
return os.path.normpath(os.path.join(self.dirBase,'current/')) return os.path.normpath(os.path.join(self.dirBase,'current/'))
def dirProof(self): def dirProof(self):
''' '''
Directory containing human readable proof of correctness for the test. Directory containing human readable proof of correctness for the test.
''' '''
return os.path.normpath(os.path.join(self.dirBase,'proof/')) return os.path.normpath(os.path.join(self.dirBase,'proof/'))
def fileInReference(self,file): def fileInReference(self,file):
''' '''
@ -147,17 +150,20 @@ class Test():
''' '''
return os.path.join(self.dirReference(),file) return os.path.join(self.dirReference(),file)
def fileInCurrent(self,file): def fileInCurrent(self,file):
''' '''
Path to a file in the current results directory for the test. Path to a file in the current results directory for the test.
''' '''
return os.path.join(self.dirCurrent(),file) return os.path.join(self.dirCurrent(),file)
def fileInProof(self,file): def fileInProof(self,file):
''' '''
Path to a file in the proof directory for the test. Path to a file in the proof directory for the test.
''' '''
return os.path.join(self.dirProof(),file) return os.path.join(self.dirProof(),file)
def copy_Reference2Current(self,sourcefiles=[],targetfiles=[]): def copy_Reference2Current(self,sourcefiles=[],targetfiles=[]):
@ -167,6 +173,7 @@ class Test():
shutil.copy2(self.fileInReference(file),self.fileInCurrent(targetfiles[i])) shutil.copy2(self.fileInReference(file),self.fileInCurrent(targetfiles[i]))
except: except:
print('Reference2Current: Unable to copy file %s'%file) print('Reference2Current: Unable to copy file %s'%file)
def copy_Base2Current(self,sourceDir,sourcefiles=[],targetfiles=[]): def copy_Base2Current(self,sourceDir,sourcefiles=[],targetfiles=[]):
@ -179,6 +186,7 @@ class Test():
print(os.path.join(source,file)) print(os.path.join(source,file))
print('Base2Current: Unable to copy file %s'%file) print('Base2Current: Unable to copy file %s'%file)
def copy_Current2Reference(self,sourcefiles=[],targetfiles=[]): def copy_Current2Reference(self,sourcefiles=[],targetfiles=[]):
if len(targetfiles) == 0: targetfiles = sourcefiles if len(targetfiles) == 0: targetfiles = sourcefiles
@ -187,6 +195,7 @@ class Test():
shutil.copy2(self.fileInCurrent(file),self.fileInReference(targetfiles[i])) shutil.copy2(self.fileInCurrent(file),self.fileInReference(targetfiles[i]))
except: except:
print('Current2Reference: Unable to copy file %s'%file) print('Current2Reference: Unable to copy file %s'%file)
def copy_Proof2Current(self,sourcefiles=[],targetfiles=[]): def copy_Proof2Current(self,sourcefiles=[],targetfiles=[]):
@ -196,6 +205,7 @@ class Test():
shutil.copy2(self.fileInProof(file),self.fileInCurrent(targetfiles[i])) shutil.copy2(self.fileInProof(file),self.fileInCurrent(targetfiles[i]))
except: except:
print('Proof2Current: Unable to copy file %s'%file) print('Proof2Current: Unable to copy file %s'%file)
def copy_Current2Current(self,sourcefiles=[],targetfiles=[]): def copy_Current2Current(self,sourcefiles=[],targetfiles=[]):
@ -205,6 +215,7 @@ class Test():
except: except:
print('Current2Current: Unable to copy file %s'%file) print('Current2Current: Unable to copy file %s'%file)
def execute_inCurrentDir(self,cmd,outfile='execute_log.txt'): def execute_inCurrentDir(self,cmd,outfile='execute_log.txt'):
initialPath=os.getcwd() initialPath=os.getcwd()
@ -215,6 +226,7 @@ class Test():
process.wait() process.wait()
file.close() file.close()
os.chdir(initialPath) os.chdir(initialPath)
def compare_Array(self,File1,File2): def compare_Array(self,File1,File2):
@ -239,12 +251,14 @@ class Test():
else: else:
raise Exception('mismatch in array size to compare') raise Exception('mismatch in array size to compare')
def compare_ArrayRefCur(self,ref,cur=''): def compare_ArrayRefCur(self,ref,cur=''):
if cur =='': cur = ref if cur =='': cur = ref
refName = self.fileInReference(ref) refName = self.fileInReference(ref)
curName = self.fileInCurrent(cur) curName = self.fileInCurrent(cur)
return self.compare_Array(refName,curName) return self.compare_Array(refName,curName)
def compare_ArrayCurCur(self,cur0,cur1): def compare_ArrayCurCur(self,cur0,cur1):
@ -354,6 +368,7 @@ class Test():
print(' * maximum relative error %e for %s and %s'%(maxError[i],headings0[i]['label'],headings1[i]['label'])) print(' * maximum relative error %e for %s and %s'%(maxError[i],headings0[i]['label'],headings1[i]['label']))
print(' ********') print(' ********')
return maxError return maxError
def compare_TableRefCur(self,headingsRef,ref,headingsCur='',cur='',normHeadings='',normType=None,\ def compare_TableRefCur(self,headingsRef,ref,headingsCur='',cur='',normHeadings='',normType=None,\
absoluteTolerance=False,perLine=False,skipLines=[]): absoluteTolerance=False,perLine=False,skipLines=[]):
@ -364,6 +379,7 @@ class Test():
curName = self.fileInCurrent(cur) curName = self.fileInCurrent(cur)
return self.compare_Table(headingsRef,refName,headingsCur,curName,normHeadings,normType, return self.compare_Table(headingsRef,refName,headingsCur,curName,normHeadings,normType,
absoluteTolerance,perLine,skipLines) absoluteTolerance,perLine,skipLines)
def compare_TableCurCur(self,headingsCur0,Cur0,Cur1,headingsCur1='',normHeadings='',normType=None,\ def compare_TableCurCur(self,headingsCur0,Cur0,Cur1,headingsCur1='',normHeadings='',normType=None,\
absoluteTolerance=False,perLine=False,skipLines=[]): absoluteTolerance=False,perLine=False,skipLines=[]):
@ -374,6 +390,7 @@ class Test():
return self.compare_Table(headingsCur0,cur0Name,headingsCur1,cur1Name,normHeadings,normType, return self.compare_Table(headingsCur0,cur0Name,headingsCur1,cur1Name,normHeadings,normType,
absoluteTolerance,perLine,skipLines) absoluteTolerance,perLine,skipLines)
def report_Success(self,culprit): def report_Success(self,culprit):
if culprit == 0: if culprit == 0: