Changeset 9213 for trunk/anuga_core/source/anuga
- Timestamp:
- Jun 23, 2014, 7:11:39 PM (10 years ago)
- Location:
- trunk/anuga_core/source/anuga
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/culvert_flows/test_all.py
r8150 r9213 11 11 import unittest 12 12 import os 13 import sys14 import tempfile15 import time16 import anuga.utilities.system_tools as aust17 from anuga.utilities.terminal_width import terminal_width18 13 19 14 20 15 #List files that should be excluded from the testing process. 21 16 #E.g. if they are known to fail and under development 22 exclude_files = [] 23 24 # Directories that should not be searched for test files. 25 exclude_dirs = ['pypar_dist', 'shallow_water_balanced', # Special requirements 26 '.svn', # subversion 27 'props', 'wcprops', 'prop-base', 'text-base', 'tmp'] 28 29 30 def list_names(names, func=None, col_width=None, page_width=None): 31 # set defaults 32 p_width = page_width - 1 # set page width 33 if p_width is None: 34 p_width = 132 # default page width 35 36 c_width = col_width # set column width 37 if c_width is None: 38 c_width = 0 39 for name in names: 40 if func: 41 name = func(name) 42 c_width = max(c_width, len(name)) 43 c_width += 2 # 2 column padding 44 45 # calculate number of columns allowed 46 max_columns = int(p_width / c_width) 47 48 # print columns 49 column = 0 50 for name in names: 51 if func: 52 name = func(name) 53 print '%-*s' % (c_width-1, name), 54 column += 1 55 if column >= max_columns: 56 column = 0 57 print 58 59 # if last line not finished, end it here 60 if column > 0: 61 print 17 exclude = [] 62 18 63 19 64 20 def get_test_files(path): 65 walk = os.walk(path)66 21 22 import sys 23 24 files = os.listdir(path) 25 26 #Check sub directories 67 27 test_files = [] 68 path_files = [] 69 70 for (dirpath, dirnames, filenames) in walk: 71 # exclude forbidden directories 72 for e_dir in exclude_dirs: 73 try: 74 dirnames.remove(e_dir) 75 except ValueError: 76 pass 77 78 # check for test_*.py files 79 for filename in filenames: 80 if filename.startswith('test_') and filename.endswith('.py'): 81 test_files.append(filename) 82 if dirpath not in path_files: 83 path_files.append(dirpath) 84 85 return test_files, path_files 28 for file in files: 29 if os.path.isdir(file): 30 sys.path.append(file) 31 #print 'Recursing into', file 32 test_files += get_test_files(path + os.sep + file) 33 elif file[:5] == 'test_' and file[-2:] == 'py': 34 #print 'Appending', file 35 test_files.append(file) 36 else: 37 pass 38 return test_files 86 39 87 40 88 def regressionTest(test_verbose=False):89 # start off with where we are90 path = os.getcwd()91 print92 print 'Testing path: %s' % path93 41 94 # get the terminal width 95 term_width = terminal_width() 96 97 # explain what we are doing 98 print 99 print "The following directories will be skipped over:" 100 exclude_dirs.sort() 101 list_names(exclude_dirs, page_width=term_width) 102 103 # get all test_*.py and enclosing directories 104 test_files, path_files = get_test_files(path) 105 path_files.sort() 106 107 files = [x for x in test_files if not x == 'test_all.py'] 108 files.sort() # Ensure same order on all platforms 109 110 print 111 print 'Paths searched:' 112 list_names(path_files, os.path.basename, page_width=term_width) 113 114 print 115 print 'Files tested:' 116 list_names(files, page_width=term_width) 117 print 118 119 # update system path with found paths 120 for path in path_files: 121 sys.path.append(path) 122 123 # exclude files that we can't handle 124 for file in exclude_files: 125 print 'WARNING: File '+ file + ' to be excluded from testing' 126 try: 127 files.remove(file) 128 except ValueError, e: 129 msg = 'File "%s" was not found in test suite.\n' % file 130 msg += 'Original error is "%s"\n' % e 131 msg += 'Perhaps it should be removed from exclude list?' 132 raise Exception, msg 133 134 # import all test_*.py files 135 # NOTE: This implies that test_*.py files MUST HAVE UNIQUE NAMES! 136 filenameToModuleName = lambda f: os.path.splitext(f)[0] 137 moduleNames = map(filenameToModuleName, files) 138 modules = map(__import__, moduleNames) 139 140 # Fix up the system path 141 for file in path_files: 142 sys.path.remove(file) 143 144 # bundle up all the tests 145 load = unittest.defaultTestLoader.loadTestsFromModule 146 testCaseClasses = map(load, modules) 147 148 if test_verbose is True: 149 # Test the code by setting verbose to True. 150 # The test cases have to be set up for this to work. 151 # See test data manager for an example. 152 for test_suite in testCaseClasses: 153 for tests in test_suite._tests: 154 # tests is of class TestSuite 155 if len(tests._tests) > 1: 156 # these are the test functions 157 try: 158 # Calls class method set_verbose in test case classes 159 tests._tests[0].set_verbose() 160 except: 161 pass # No all classes have set_verbose 162 163 return unittest.TestSuite(testCaseClasses) 42 def regressionTest(): 43 import sys, os, re, unittest 44 path = os.path.split(sys.argv[0])[0] or os.getcwd() 164 45 165 46 166 def check_anuga_import(): 167 try: 168 # importing something that loads quickly 169 import anuga.anuga_exceptions 170 except ImportError: 171 print "Python cannot import ANUGA module." 172 print "Check you have followed all steps of its installation." 173 import sys 174 sys.exit() 47 files = get_test_files(path) 175 48 176 49 50 51 #test = re.compile('^test_[\w]*.py$', re.IGNORECASE) 52 #files = filter(test.search, files) 53 54 55 try: 56 files.remove(__file__) #Remove self from list (Ver 2.3. or later) 57 except: 58 files.remove('test_all.py') 59 60 print 'Testing:' 61 for file in files: 62 print ' ' + file 63 64 if globals().has_key('exclude'): 65 for file in exclude: 66 files.remove(file) 67 print 'WARNING: File '+ file + ' excluded from testing' 68 69 70 filenameToModuleName = lambda f: os.path.splitext(f)[0] 71 #print "files",files 72 moduleNames = map(filenameToModuleName, files) 73 #print "moduleNames",moduleNames 74 modules = map(__import__, moduleNames) 75 load = unittest.defaultTestLoader.loadTestsFromModule 76 return unittest.TestSuite(map(load, modules)) 77 177 78 if __name__ == '__main__': 178 check_anuga_import()179 79 180 if len(sys.argv) > 1 and sys.argv[1][0].upper() == 'V': 181 test_verbose = True 182 saveout = sys.stdout 183 filename = ".temp" 184 fid = open(filename, 'w') 185 sys.stdout = fid 186 else: 187 test_verbose = False 188 suite = regressionTest(test_verbose) 189 runner = unittest.TextTestRunner() #verbosity=2 80 from os import sep 81 82 #Attempt to compile all extensions 83 #execfile('..' + sep + 'utilities' + sep + 'compile.py') 84 85 #FIXME: Temporary measure 86 #os.chdir('..' + sep + 'utilities') 87 #execfile('compile.py') 88 #os.chdir('..' + sep + 'pyvolution') 89 90 #FIXME: Temporary measure 91 #os.chdir('..' + sep + 'triangle') 92 #execfile('compile.py') 93 #os.chdir('..' + sep + 'pyvolution') 94 95 #os.system('python compile.py') 96 97 #print regressionTest() 98 #unittest.main(defaultTest='regressionTest') 99 100 suite = regressionTest() 101 runner = unittest.TextTestRunner() #(verbosity=2) 190 102 runner.run(suite) 191 192 # timestamp at the end193 timestamp = time.asctime()194 version = aust.get_revision_number()195 print196 print 'Finished at %s, version %s' % (timestamp, version)197 198 # Cleaning up199 if len(sys.argv) > 1 and sys.argv[1][0].upper() == 'V':200 sys.stdout = saveout201 #fid.close() # This was causing an error in windows202 #os.remove(filename)203 204 205 if sys.platform == 'win32':206 raw_input('Press the RETURN key') -
trunk/anuga_core/source/anuga/geometry/polygon.py
r9067 r9213 723 723 """ 724 724 725 from pylab import ion, ioff, hold, plot, savefig, xlabel, \ 726 ylabel, title, close, title, fill 725 726 import matplotlib as mpl 727 mpl.use('Agg') 728 #import matplotlib.pyplot as plt 729 730 731 from matplotlib.pyplot import hold, plot, savefig, xlabel, \ 732 ylabel, title, close, title, fill 727 733 728 734 assert type(polygons_points) == list, \ 729 735 'input must be a list of polygons and/or points' 730 736 731 ion()737 #ion() 732 738 hold(True) 733 739 … … 777 783 savefig('test_image') 778 784 779 ioff()785 #ioff() 780 786 hold(False) 781 787 close('all') -
trunk/anuga_core/source/anuga/geometry/test_polygon.py
r8819 r9213 1781 1781 plot_polygons([polygon1, polygon2], figname='test1') 1782 1782 1783 import pylab 1784 pylab.close('all') 1783 1785 1784 1786 1785 # Another case 1787 polygon3 = [[1,5], [10,1], [100,10], [50, 10], [3,6]]1786 polygon3 = [[1,5], [10,1], [100,10], [50,9], [3,6]] 1788 1787 plot_polygons([polygon2, polygon3], figname='test2') 1789 1788 1790 pylab.close('all')1791 1792 for file in ['test1.png', 'test2.png']:1793 assert os.access( file, os.R_OK)1794 os.remove( file)1789 #plt.close('all') 1790 1791 for plotfile in ['test1.png', 'test2.png']: 1792 assert os.access(plotfile, os.R_OK) 1793 os.remove(plotfile) 1795 1794 1796 1795 -
trunk/anuga_core/source/anuga/shallow_water/shallow_water_domain.py
r9212 r9213 1730 1730 """ 1731 1731 1732 N = len(self) # Number_of_triangles1733 d = len(self.conserved_quantities)1734 1732 1735 1733 timestep = self.timestep … … 1747 1745 Xmom = self.quantities['xmomentum'] 1748 1746 Ymom = self.quantities['ymomentum'] 1749 1750 #self.work_centroid_values[:] = Stage.centroid_values 1751 1752 tff = self.tri_full_flag 1753 1747 1754 1748 Stage.update(timestep) 1755 1749 Xmom.update(timestep) 1756 Ymom.update(timestep) 1757 1758 negative_ids = num.where( num.logical_and((Stage.centroid_values - Elev.centroid_values) < 0.0 , tff > 0) )[0] 1759 1760 if len(negative_ids)>0: 1761 #print 'NEGATIVE INDICES' 1762 Stage.centroid_values[negative_ids] = Elev.centroid_values[negative_ids] 1763 Xmom.centroid_values[negative_ids] = 0.0 1764 Ymom.centroid_values[negative_ids] = 0.0 1750 Ymom.update(timestep) 1751 1752 if self.get_using_discontinuous_elevation(): 1753 1754 tff = self.tri_full_flag 1755 1756 negative_ids = num.where( num.logical_and((Stage.centroid_values - Elev.centroid_values) < 0.0 , tff > 0) )[0] 1765 1757 1766 1767 # Note that Q.explicit_update is reset by compute_fluxes 1768 # Where is Q.semi_implicit_update reset? 1769 # It is reset in quantity_ext.c 1770 1758 if len(negative_ids)>0: 1759 #print 'NEGATIVE INDICES' 1760 Stage.centroid_values[negative_ids] = Elev.centroid_values[negative_ids] 1761 Xmom.centroid_values[negative_ids] = 0.0 1762 Ymom.centroid_values[negative_ids] = 0.0 1763 1764 1771 1765 1772 1766 -
trunk/anuga_core/source/anuga/utilities/plot_utils.py
r9212 r9213 978 978 for myTSi in myTimeStep: 979 979 if(verbose): 980 print myTSi980 print 'Reduction = ', myTSi 981 981 for output_quantity in output_quantities: 982 982 if (verbose): print output_quantity
Note: See TracChangeset
for help on using the changeset viewer.