Skip to content

Commit

Permalink
Merge pull request clawpack#39 from rjleveque/rjl
Browse files Browse the repository at this point in the history
Mostly improve regression tests.  And close some data files after writing
  • Loading branch information
rjleveque committed Jul 4, 2013
2 parents ee588cc + eb1249d commit 1862ab4
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 9 deletions.
24 changes: 20 additions & 4 deletions src/python/clawutil/chardiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ def chardiff_file(fname1, fname2, print_all_lines=True, hfile1='', \
# -----------------------------------------------------------------


def chardiff_dir(dir1, dir2, file_pattern='all', dir3="_char_diff",
def chardiff_dir(dir1, dir2, dir3="_char_diff", file_pattern='all',
regression_test_files='all',
overwrite=False, print_all_lines=True, verbose=True):
"""
Run chardiff_file on all common files between dir1 and dir2 that match the patterns in the
Expand All @@ -200,7 +201,7 @@ def chardiff_dir(dir1, dir2, file_pattern='all', dir3="_char_diff",

ignored_extensions = ['.o','.pdf','.ps','.chk','']

print "Comparing files in the directory: ", dir1
print "\nComparing files in the directory: ", dir1
print " with the directory: ", dir2


Expand Down Expand Up @@ -242,7 +243,6 @@ def chardiff_dir(dir1, dir2, file_pattern='all', dir3="_char_diff",
if alltrue(testfiles) and verbose:
print "Files matching pattern in the two directories are equal"



#f_equal, f_diff, f_other = filecmp.cmpfiles(dir1,dir2,files,False)

Expand Down Expand Up @@ -310,7 +310,23 @@ def chardiff_dir(dir1, dir2, file_pattern='all', dir3="_char_diff",

hfile.write("</ul>\n</html>\n")

print "To view diffs, open the file ",dir3+'/_DiffIndex.html'
# Test regression files for return value:
if regression_test_files=='all':
rfiles1 = os.listdir(dir1)
rfiles2 = os.listdir(dir2)
regression_test_files = rfiles1 + rfiles2
regression_ok = alltrue([f in checkfiles.same_files for f in \
regression_test_files])
if verbose and regression_ok:
print "Regression files all match"
elif verbose:
print "*** Regression files are not all identical"

dir3 = os.path.abspath(dir3)
print "To view diffs, open the file ",dir3+'/_DiffIndex.html\n'

return regression_ok



# -----------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/python/clawutil/clawdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ def write(self, out_file='claw.data', data_source='setrun.py'):
% self.checkpt_style)

self.data_write()
self.close_data_file()


class UserData(ClawData):
Expand Down Expand Up @@ -660,3 +661,4 @@ def add_param(self,name,value,descr=''):

def write(self,data_source='setrun.py'):
super(UserData,self).write(self.__fname__, data_source)
self.close_data_file()
126 changes: 126 additions & 0 deletions src/python/clawutil/compare_regression_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
"""
Compare the results of run_regression_tests.py with archived results, if they
can be found using clawpack.clawutil.fetch_regression_data.
"""

from clawpack.clawutil.fetch_regression_data import fetch_regression_data
from clawpack.clawutil.chardiff import chardiff_dir
from clawpack.clawutil.imagediff import imagediff_dir
import os,sys,glob
from numpy import alltrue


def compare_regression_tests(regression_dir="_regression_tests", \
regression_output_files = 'all', \
regression_plot_files = 'all', \
verbose=False):

try:
archived_dir, tar_file = fetch_regression_data(regression_dir)
archived_dir = os.path.abspath(archived_dir)
os.system("rm %s" % tar_file)
except:
print "*** Error retrieving regression results"
sys.exit()


try:
os.chdir(regression_dir)
except:
print "*** Cannot cd to ",regression_dir
sys.exit()

index_file = 'index.html'
hfile = open(index_file,'w')
index_file = os.path.abspath(index_file)

hfile.write("""<html>
<h1>Regression test results</h1>
<h2>Comparison of output files:</h2>
&nbsp; &nbsp;Pass or Fail based only on files %s
<ul>
""" % regression_output_files)

outdirs = glob.glob('_output*')

if outdirs == []:
print "*** No output directories found"
else:
if glob.glob('_chardiffs*') != []:
ans = raw_input("Ok to clobber all _chardiffs directories? ")
if ans=='y':
os.system("rm -rf _chardiffs*")

output_ok_dirs = []

for outdir in outdirs:
outdir_archived = archived_dir + "/" + outdir
if not os.path.exists(outdir_archived):
print "*** Cannot find directory ",outdir_archived
print "*** will not compare to ",outdir
else:
diffdir = "_chardiffs" + outdir
regression_ok = chardiff_dir(outdir_archived, outdir, dir3=diffdir, \
regression_test_files=regression_output_files, \
verbose=verbose)
output_ok_dirs.append(regression_ok)
hfile.write('<li> <a href="%s/_DiffIndex.html">%s</a>' % (diffdir,outdir))
if regression_ok:
hfile.write('&nbsp; <font color="green">Pass</font>\n')
else:
hfile.write('&nbsp; <font color="red">Fail</font>\n')

hfile.write("""</ul>
<h2>Comparison of plot files: </h2>
&nbsp; &nbsp;Pass or Fail based only on files %s
<ul>
""" % regression_plot_files)

plot_ok_dirs = []

plotdirs = glob.glob('_plots*')
if plotdirs == []:
print "*** No plots directories found"
else:
if glob.glob('_imagediffs*') != []:
ans = raw_input("Ok to clobber all _imagediffs directories? ")
if ans=='y':
os.system("rm -rf _imagediffs*")

for plotdir in plotdirs:
plotdir_archived = archived_dir + "/" + plotdir
if not os.path.exists(plotdir_archived):
print "*** Cannot find directory ",plotdir_archived
print "*** will not compare to ",plotdir
else:
diffdir = "_imagediffs" + plotdir
regression_ok = imagediff_dir(plotdir_archived, plotdir, dir3=diffdir, \
regression_test_files=regression_plot_files, \
verbose=verbose)
plot_ok_dirs.append(regression_ok)
hfile.write('<li> <a href="%s/_ImageDiffIndex.html">%s</a>' % (diffdir,plotdir))
if regression_ok:
hfile.write('&nbsp; <font color="green">Pass</font>\n')
else:
hfile.write('&nbsp; <font color="red">Fail</font>\n')

hfile.write("""</ul>
</html>
""")
hfile.close()

print "\nTo see resulting diffs, open \n %s\n" % index_file

fail_dirs = \
[outdirs[i] for i in range(len(outdirs)) if not output_ok_dirs[i]] + \
[plotdirs[i] for i in range(len(plotdirs)) if not plot_ok_dirs[i]]

regression_ok = (fail_dirs == [])
if not regression_ok:
print "*** Regression files do not match in directories: ", fail_dirs

return regression_ok

if __name__=="__main__":

compare_regression_tests(*sys.argv[1:])
2 changes: 1 addition & 1 deletion src/python/clawutil/fetch_regression_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def fetch_regression_data(target_dir):
% clawdir)

tarfile = thisdir.replace('/','-') + '-' + target_dir + '.tar.gz'
regdir = target_dir + '-regression_data'
regdir = target_dir + '_archived_results'

url = "http://www.clawpack.org/regression_data"

Expand Down
19 changes: 18 additions & 1 deletion src/python/clawutil/imagediff.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import os, sys, getopt, shutil

def imagediff_file(fname1, fname2, verbose):
def imagediff_file(fname1, fname2, verbose=True):

fname3 = make_imagediff(fname1,fname2,verbose=verbose)

Expand Down Expand Up @@ -64,9 +64,11 @@ def make_imagediff(fname1,fname2,fname3='', verbose=False):


def imagediff_dir(dir1, dir2, dir3="_image_diff", ext='.png', \
regression_test_files='all', \
relocatable=False, overwrite=False, verbose=False):

import filecmp,glob
from numpy import alltrue

if dir1[-1] == '/': dir1 = dir1[:-1]
if dir2[-1] == '/': dir2 = dir2[:-1]
Expand Down Expand Up @@ -188,9 +190,24 @@ def imagediff_dir(dir1, dir2, dir3="_image_diff", ext='.png', \
<td><a href="%s"><img src="%s" width=350 border="1"></a></td> </tr>
</table><p>""" \
% (f,f,fhtml1,fname1,fhtml2,fname2,fname3,fname3))

# Test regression files for return value:
if regression_test_files=='all':
rfiles1 = os.listdir(dir1)
rfiles2 = os.listdir(dir2)
regression_test_files = rfiles1 + rfiles2
regression_ok = alltrue([f in f_equal for f in \
regression_test_files])
if verbose and regression_ok:
print "Regression files all match"
elif verbose:
print "*** Regression files are not all identical"

os.chdir(startdir)
dir3 = os.path.abspath(dir3)
print "To view diffs, open the file ",os.path.join(dir3,hname)

return regression_ok


class Usage(Exception):
Expand Down
4 changes: 2 additions & 2 deletions src/python/clawutil/runclaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Generic code for running the fortran version of Clawpack and sending the
results to subdirectory output of the directory from which this is executed.
Execute via
$ python $CLAW/python/pyclaw/runclaw.py
$ python $CLAWUTIL/src/python/clawutil/runclaw.py
from a directory that contains a claw.data file and a Clawpack executable.
"""

Expand Down Expand Up @@ -189,7 +189,7 @@ def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=False,

if returncode != 0:
print '==> runclaw: *** fortran returncode = ', returncode, ' aborting'
print '==> runclaw: Done executing %s via pyclaw.runclaw.py' % xclawcmd
print '==> runclaw: Done executing %s via clawutil.runclaw.py' % xclawcmd
print '==> runclaw: Output is in ', outdir


Expand Down
3 changes: 2 additions & 1 deletion src/python/clawutil/save_regression_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ def send_outdir(outdir="_output"):
% clawdir)

tarfile = thisdir.replace('/','-') + '-' + outdir + '.tar'
regdir = outdir + '-regression_data'
regdir = outdir + '_archived_results'
if os.path.exists(regdir):
raise Exception("Directory %s already exists" % regdir)

os.system("ln -sf %s %s" % (outdir, regdir))
os.system("tar -cHf %s %s" % (tarfile, regdir))
os.system("rm %s" % regdir) # remove sym link
os.system("gzip %s" % tarfile)
tarfile = tarfile + '.gz'

Expand Down

0 comments on commit 1862ab4

Please sign in to comment.