diff --git a/src/python/clawutil/__init__.py b/src/python/clawutil/__init__.py new file mode 100644 index 00000000..3ec50da7 --- /dev/null +++ b/src/python/clawutil/__init__.py @@ -0,0 +1,3 @@ + +__all__ = ['data','save_regression_data','regression_test','chardiff','imagediff'] + diff --git a/src/python/clawutil/chardiff.py b/src/python/clawutil/chardiff.py index d96fc524..b11440c1 100755 --- a/src/python/clawutil/chardiff.py +++ b/src/python/clawutil/chardiff.py @@ -67,9 +67,12 @@ def chardiff_file(fname1, fname2, print_all_lines=True, hfile1='', \ toggle.append(j) if len(toggle)==0: - print "*** Error: toggle should be nonempty" - print "*** Aborting" - raise Exception() + #print "*** Error: toggle should be nonempty" + #print "*** Aborting" + #raise Exception() + # They might be the same after padding with blanks. + # Accept this case as ok... + line_changed = False if print_all_lines and (not line_changed): changed.append(False) @@ -189,15 +192,31 @@ def chardiff_file(fname1, fname2, print_all_lines=True, hfile1='', \ # ----------------------------------------------------------------- -def chardiff_dir(dir1, dir2, file_pattern='all', dir3="diff_dir", - overwrite=False, print_all_lines=True, verbose=False): +def chardiff_dir(dir1, dir2, file_pattern='all', dir3="_char_diff", + 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 list files. """ import filecmp, glob + from numpy import alltrue + + ignored_extensions = ['.o','.pdf','.ps','.chk',''] + + print "Comparing files in the directory: ", dir1 + print " with the directory: ", dir2 + + + # Start out comparing all files: + checkfiles = filecmp.dircmp(dir1,dir2) + allsame = (checkfiles.diff_files==[]) and (checkfiles.left_list == checkfiles.right_list) - ignored_extensions = ['.o','.pdf','.ps',''] + if allsame and verbose: + print "*All* files in the two directories are equal" + elif verbose: + if len(checkfiles.diff_files)>0: + print "Files that differ between dir1 and dir2: ",checkfiles.diff_files + # Construct sorted list of files matching in either or both directories: if file_pattern=='all': @@ -221,9 +240,15 @@ def chardiff_dir(dir1, dir2, file_pattern='all', dir3="diff_dir", for f in files_both: if f not in files: files.append(f) files.sort() + + testfiles = [f in checkfiles.same_files for f in files] + if alltrue(testfiles) and verbose: + print "Files matching pattern in the two directories are equal" - print "Comparing files in the directory: ", dir1 - print " with the directory: ", dir2 + + + #f_equal, f_diff, f_other = filecmp.cmpfiles(dir1,dir2,files,False) + if os.path.isdir(dir3): if (len(os.listdir(dir3)) > 0) and (not overwrite): @@ -244,22 +269,33 @@ def chardiff_dir(dir1, dir2, file_pattern='all', dir3="diff_dir",