Changeset 6218
- Timestamp:
- Jan 20, 2009, 2:56:26 PM (16 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/lib/maxasc/test_maxasc.py
r6213 r6218 2 2 3 3 from maxasc import * 4 import anuga.utilities.system_tools as aust 4 5 5 6 import exceptions … … 8 9 9 10 import sys 11 import os 10 12 import re 13 import glob 11 14 12 15 HEADER_SIZE = 6 … … 82 85 83 86 class Test_MaxAsc(unittest.TestCase): 87 def tearDown(self): 88 # delete all output files 89 files = glob.glob('*.out.asc') 90 for file in files: 91 os.remove(file) 92 84 93 def test_unequal_lines(self): 94 test_path = aust.get_pathname_from_package('anuga.lib.maxasc') 95 in_file = os.path.join(test_path, 'test1.asc') 96 expected_file = os.path.join(test_path, 'test1_bad_num_lines.asc') 85 97 self.failUnlessRaises(RuntimeError, MaxAsc, 86 98 'test.out.asc', 87 [ 'test1.asc', 'test1_bad_num_lines.asc'])99 [in_file, expected_file]) 88 100 89 101 def test_headers_differ(self): 102 test_path = aust.get_pathname_from_package('anuga.lib.maxasc') 103 in_file = os.path.join(test_path, 'test1.asc') 104 expected_file = os.path.join(test_path, 'test1_bad_num_lines.asc') 90 105 self.failUnlessRaises(RuntimeError, MaxAsc, 91 106 'test.out.asc', 92 [ 'test1.asc', 'test1_bad_num_lines.asc'])107 [in_file, expected_file]) 93 108 94 109 def test_wrong_num_columns(self): 110 test_path = aust.get_pathname_from_package('anuga.lib.maxasc') 111 in_file = os.path.join(test_path, 'test1.asc') 112 expected_file = os.path.join(test_path, 'test1_wrong_num_columns.asc') 95 113 self.failUnlessRaises(RuntimeError, MaxAsc, 96 114 'test.out.asc', 97 [ 'test1.asc', 'test1_wrong_num_columns.asc'])115 [in_file, expected_file]) 98 116 99 117 def test_same_input_equals_output1(self): 100 MaxAsc('test1.out.asc', ['test1.asc']) 101 self.failUnless(FilesEqual('test1.out.asc', 'test1.asc')) 118 test_path = aust.get_pathname_from_package('anuga.lib.maxasc') 119 in_file = os.path.join(test_path, 'test1.asc') 120 MaxAsc('test1.out.asc', [in_file]) 121 self.failUnless(FilesEqual('test1.out.asc', in_file)) 102 122 103 123 def test_same_input_equals_bigA(self): 104 MaxAsc('perth.out.asc', ['perthAll_stage_250m.asc']) 105 self.failUnless(FilesEqual('perth.out.asc', 'perthAll_stage_250m.asc')) 124 test_path = aust.get_pathname_from_package('anuga.lib.maxasc') 125 in_file = os.path.join(test_path, 'perthAll_stage_250m.asc') 126 MaxAsc('perth.out.asc', [in_file]) 127 self.failUnless(FilesEqual('perth.out.asc', in_file)) 106 128 107 129 def test_same_input_equals_bigB(self): 108 MaxAsc('perth.out.asc', ['perthAll_stage_250m_all.asc']) 109 self.failUnless(FilesEqual('perth.out.asc', 'perthAll_stage_250m_all.asc')) 130 test_path = aust.get_pathname_from_package('anuga.lib.maxasc') 131 in_file = os.path.join(test_path, 'perthAll_stage_250m_all.asc') 132 MaxAsc('perth.out.asc', [in_file]) 133 self.failUnless(FilesEqual('perth.out.asc', in_file)) 110 134 111 135 def test_same_input_equals_bigC(self): 112 MaxAsc('perth.out.asc', ['perthAll_stage_original.asc']) 113 self.failUnless(FilesEqual('perth.out.asc', 'perthAll_stage_original.asc')) 136 test_path = aust.get_pathname_from_package('anuga.lib.maxasc') 137 in_file = os.path.join(test_path, 'perthAll_stage_original.asc') 138 MaxAsc('perth.out.asc', [in_file]) 139 self.failUnless(FilesEqual('perth.out.asc', in_file)) 114 140 115 141 def test_same_input_equals_big3(self): 116 MaxAsc('perth.out.asc', ['perthAll_stage_250m.asc',117 'perthAll_stage_250m.asc',118 'perthAll_stage_250m.asc'])119 self.failUnless(FilesEqual('perth.out.asc', 'perthAll_stage_250m.asc'))142 test_path = aust.get_pathname_from_package('anuga.lib.maxasc') 143 in_file = os.path.join(test_path, 'perthAll_stage_250m.asc') 144 MaxAsc('perth.out.asc', [in_file, in_file, in_file]) 145 self.failUnless(FilesEqual('perth.out.asc', in_file)) 120 146 121 147 def test_same_input_equals_outputN(self): 122 MaxAsc('test1.out.asc', ['test1.asc'] * 30) 123 self.failUnless(FilesEqual('test1.out.asc', 'test1.asc')) 148 test_path = aust.get_pathname_from_package('anuga.lib.maxasc') 149 in_file = os.path.join(test_path, 'test1.asc') 150 MaxAsc('test1.out.asc', [in_file] * 30) 151 self.failUnless(FilesEqual('test1.out.asc', in_file)) 124 152 125 153 def test_different_input2(self): 126 MaxAsc('test2.out.asc', ['test1.asc', 'test2.asc']) 127 self.failUnless(FilesEqual('test2.out.asc', 'test2.expected.asc')) 154 test_path = aust.get_pathname_from_package('anuga.lib.maxasc') 155 in_file = os.path.join(test_path, 'test1.asc') 156 in_file2 = os.path.join(test_path, 'test2.asc') 157 expected_file = os.path.join(test_path, 'test2.expected.asc') 158 MaxAsc('test2.out.asc', [in_file, in_file2]) 159 self.failUnless(FilesEqual('test2.out.asc', expected_file)) 128 160 129 161 def test_different_input3(self): 130 MaxAsc('test3.out.asc', ['test1.asc', 'test2.asc', 'test3.asc']) 131 self.failUnless(FilesEqual('test3.out.asc', 'test3.expected.asc')) 162 test_path = aust.get_pathname_from_package('anuga.lib.maxasc') 163 in_file = os.path.join(test_path, 'test1.asc') 164 in_file2 = os.path.join(test_path, 'test2.asc') 165 in_file3 = os.path.join(test_path, 'test3.asc') 166 expected_file = os.path.join(test_path, 'test3.expected.asc') 167 MaxAsc('test3.out.asc', [in_file, in_file2, in_file3]) 168 self.failUnless(FilesEqual('test3.out.asc', expected_file)) 132 169 133 134 suite = unittest.makeSuite(Test_MaxAsc,'test') 135 #suite = unittest.makeSuite(Test_MaxAsc,'test_same_input_equals_output1') 136 runner = unittest.TextTestRunner(verbosity=1) 137 runner.run(suite) 170 if __name__ == '__main__': 171 suite = unittest.makeSuite(Test_MaxAsc,'test') 172 runner = unittest.TextTestRunner(verbosity=1) 173 runner.run(suite) -
anuga_core/source/anuga/test_all.py
r6215 r6218 17 17 #List files that should be excluded from the testing process. 18 18 #E.g. if they are known to fail and under development 19 20 19 exclude_files = [] 21 20 22 #if sys.platform != 'win32':23 # exclude_files.append('test_advection.py') #Weave doesn't work on Linux24 # Exclude test_advection on all platforms for the time being. See ticket:20525 #exclude_files.append('test_advection.py') #Weave doesn't work on Linux26 27 21 # Directories that should not be searched for test files. 28 29 exclude_dirs = ['pypar_dist', #Special requirements 30 'props', 'wcprops', 'prop-base', 'text-base', '.svn', #Svn 31 'tmp', 'lib'] 32 33 print "The following directories will be skipped over;" 34 for dir in exclude_dirs: 35 print dir 36 print "" 37 38 22 exclude_dirs = ['pypar_dist', # Special requirements 23 '.svn', # subversion 24 'props', 'wcprops', 'prop-base', 'text-base', 'tmp'] 25 26 27 ## 28 # @brief List a string sequence on the screen in columns. 29 # @param names Sequence of strings to list. 30 # @param func Function to apply to each string in sequence. 31 # @param col_width Force columns to this width (default calculated). 32 # @param page_width Set displayable page width to this (default 132). 33 def list_names(names, func=None, col_width=None, page_width=None): 34 # set defaults 35 p_width = page_width # set page width 36 if p_width is None: 37 p_width = 132 # default page width 38 39 c_width = col_width # set column width 40 if c_width is None: 41 c_width = 0 42 for name in names: 43 if func: 44 name = func(name) 45 c_width = max(c_width, len(name)) 46 c_width += 2 # padding between columns 47 48 # calculate number of columns allowed 49 max_columns = int(p_width / c_width) 50 51 # print columns 52 column = 0 53 for name in names: 54 if func: 55 name = func(name) 56 print '%-*s' % (c_width, name), 57 column += 1 58 if column >= max_columns: 59 column = 0 60 print 61 62 # if last line not finished, end it here 63 if column > 0: 64 print 65 66 67 ## 68 # @brief Get 'test_*.py' files and paths to directories. 69 # @param path Path to directory to start walk in. 70 # @return A tuple (<files>, <dirs>). 71 # @note Don't include any files in and below forbidden directories. 39 72 def get_test_files(path): 40 try: 41 files = os.listdir(path) 42 except: 43 return [] 44 45 #Check sub directories 73 walk = os.walk(path) 74 46 75 test_files = [] 47 48 #Exclude svn admin dirs49 files = [x for x in files if x not in exclude_dirs]50 76 path_files = [] 51 for file in files: 52 absolute_filename = path + os.sep + file 53 54 #sys.path.append('pmesh') 55 if os.path.isdir(absolute_filename): 56 # FIXME: May cause name conflicts between pyvolution\mesh.py and 57 # pmesh\mesh.py on some systems 58 sys.path.append(file) 59 path_files.append(file) 60 print file + ',', 61 more_test_files, more_path_files = \ 62 get_test_files(absolute_filename) 63 test_files += more_test_files 64 path_files += more_path_files 65 elif file.startswith('test_') and file.endswith('.py'): 66 test_files.append(file) 67 else: 68 pass 77 78 for (dirpath, dirnames, filenames) in walk: 79 # exclude forbidden directories 80 for e_dir in exclude_dirs: 81 try: 82 dirnames.remove(e_dir) 83 except ValueError: 84 pass 85 86 # check for test_*.py files 87 for filename in filenames: 88 if filename.startswith('test_') and filename.endswith('.py'): 89 test_files.append(filename) 90 if dirpath not in path_files: 91 path_files.append(dirpath) 69 92 70 93 return test_files, path_files … … 72 95 73 96 def regressionTest(test_verbose=False): 97 # start off with where we are 74 98 path = os.getcwd() 75 print 'Recursing into;' 99 print 100 print 'Testing path: %s' % path 101 102 # explain what we are doing 103 print 104 print "The following directories will be skipped over:" 105 exclude_dirs.sort() 106 list_names(exclude_dirs) 107 108 # get all test_*.py and enclosing directories 76 109 test_files, path_files = get_test_files(path) 77 110 78 111 files = [x for x in test_files if not x == 'test_all.py'] 79 80 files.sort() # Ensure same order on all platforms 81 82 print 83 print 84 print 'Testing path %s:' %('...'+path[-50:]) 112 files.sort() # Ensure same order on all platforms 113 85 114 print 86 115 print 'Paths searched:' 87 for path_file in path_files: 88 print path_file + ',', 89 print 116 list_names(path_files, os.path.basename) 117 90 118 print 91 print 'Files tested;' 92 for file in files: 93 print file + ',', 94 print 95 print 96 print 97 98 if globals().has_key('exclude_files'): 99 for file in exclude_files: 100 print 'WARNING: File '+ file + ' to be excluded from testing' 101 try: 102 files.remove(file) 103 except ValueError, e: 104 msg = 'File "%s" was not found in test suite.\n' % file 105 msg += 'Original error is "%s"\n' % e 106 msg += 'Perhaps it should be removed from exclude list?' 107 raise Exception, msg 108 119 print 'Files tested:' 120 list_names(files) 121 122 # update system path with found paths 123 for path in path_files: 124 sys.path.append(path) 125 126 # exclude files that we can't handle 127 for file in exclude_files: 128 print 'WARNING: File '+ file + ' to be excluded from testing' 129 try: 130 files.remove(file) 131 except ValueError, e: 132 msg = 'File "%s" was not found in test suite.\n' % file 133 msg += 'Original error is "%s"\n' % e 134 msg += 'Perhaps it should be removed from exclude list?' 135 raise Exception, msg 136 137 # import all test_*.py files 138 # NOTE: This implies that test_*.py files MUST HAVE UNIQUE NAMES! 109 139 filenameToModuleName = lambda f: os.path.splitext(f)[0] 110 140 moduleNames = map(filenameToModuleName, files) 111 141 modules = map(__import__, moduleNames) 112 113 142 114 143 # Fix up the system path … … 116 145 sys.path.remove(file) 117 146 147 # bundle up all the tests 118 148 load = unittest.defaultTestLoader.loadTestsFromModule 119 149 testCaseClasses = map(load, modules) … … 133 163 except: 134 164 pass # No all classes have set_verbose 165 135 166 return unittest.TestSuite(testCaseClasses) 136 167 137 168 169 ## 170 # @brief Check that the environment is sane. 171 # @note Stops here if there is an error. 138 172 def check_anuga_import(): 139 173 try:
Note: See TracChangeset
for help on using the changeset viewer.