- Timestamp:
- Mar 27, 2009, 4:00:15 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified anuga_validation/automated_validation_tests/patong_validation/validate_patong.py ¶
r6639 r6649 10 10 import glob 11 11 import unittest 12 import logging 12 #import logging 13 import time 13 14 import project 14 from anuga.utilities.system_tools import get_web_file 15 from anuga.utilities.system_tools import get_web_file, untar_file 15 16 import anuga.utilities.log as log 16 17 # set logging levels18 log.console_logging_level = logging.DEBUG19 log.log_logging_level = logging.DEBUG20 17 21 18 … … 33 30 34 31 def update_local_data(): 35 36 32 # update one data object 37 33 def update_object(obj, auth): 34 # Get a unique date+time string to defeat caching. The idea is to add 35 # this to the end of any URL so proxy sees a different request. 36 cache_defeat = '?' + time.strftime('%Y%m%d%H%M%S') 37 38 # create local and remote paths, URLs, etc. 38 39 remote_path = os.path.join(Remote_Data_Directory, obj) 39 40 remote_digest = remote_path + '.tgz.digest' 40 41 41 42 local_path = os.path.join(Local_Data_Directory, obj) 42 local_digest = local_path + '.tgz.digest' 43 local_file = local_path + '.tgz' 44 local_digest = local_file + '.digest' 43 45 44 if not os.path.exists(local_digest): 45 # no object digest, download both digest and object 46 object_url = ANUGA_URL + obj + '.tgz.digest' 46 object_url = ANUGA_URL + obj + '.tgz' 47 digest_url = object_url + '.digest' 48 49 # see if have both digest and object .tgz 50 if not os.path.exists(local_digest) or not os.path.exists(local_file): 51 # no digest or no object, download both digest and object 52 log.debug('Fetching remote file %s' % digest_url) 53 auth = get_web_file(digest_url+cache_defeat, 54 local_digest, auth=auth) 47 55 log.debug('Fetching remote file %s' % object_url) 48 auth = get_web_file(object_url, local_digest, auth=auth) 49 object_url = ANUGA_URL + obj + '.tgz' 50 local_file = local_path + '.tgz' 51 log.debug('Fetching remote file %s' % object_url) 52 auth = get_web_file(object_url, local_file, auth=auth) 56 auth = get_web_file(object_url+cache_defeat, local_file, auth=auth) 53 57 else: 54 58 # download object digest to remote data directory 55 59 object_url = ANUGA_URL + obj + '.tgz.digest' 56 60 log.debug('Fetching remote file %s' % object_url) 57 auth = get_web_file(object_url, remote_digest, auth=auth) 61 auth = get_web_file(object_url+cache_defeat, 62 remote_digest, auth=auth) 58 63 59 # compare remote with local digest , refresh if necessary64 # compare remote with local digest 60 65 fd = open(local_digest, 'r') 61 66 local_digest_data = fd.read() … … 66 71 fd.close() 67 72 73 # if local digest != remote digest, refresh object 68 74 if local_digest_data != remote_digest_data: 69 # refresh local digest & object75 log.debug('Local file %s is out of date' % obj) 70 76 fd = open(local_digest, 'w') 71 77 fd.write(remote_digest_data) … … 75 81 local_file = local_path + '.tgz' 76 82 log.debug('Fetching remote file %s' % object_url) 77 auth = get_web_file(object_url, local_file, auth=auth) 83 auth = get_web_file(object_url+cache_defeat, 84 local_file, auth=auth) 78 85 return auth 79 86 … … 94 101 for data_object in Local_Data_Objects: 95 102 auth = update_object(data_object, auth) 103 104 # unpack *.tgz files 105 for data_object in Local_Data_Objects: 106 tar_path = os.path.join(Local_Data_Directory, data_object+'.tgz') 107 log.debug('Untarring %s in dir %s' % (tar_path, Local_Data_Directory)) 108 untar_file(tar_path, target_dir=Local_Data_Directory) 96 109 97 110 … … 111 124 def tearDown(self): 112 125 pass 126 ## # clear all data objects from local data directory 127 ## for data_object in Local_Data_Objects: 128 ## try: 129 ## log.debug('Deleting %s' % os.path.join(Local_Data_Directory, 130 ## data_object)) 131 ## os.remove(os.path.join(Local_Data_Directory, data_object)) 132 ## except IOError: 133 ## pass 113 134 114 135 def test_that_output_is_as_expected(self): … … 117 138 print 'update done' 118 139 119 ## # run the simulation, produce SWW file 120 ## s = 'run_model.py' 121 ## cmd = 'python %s > %s.stdout' % (s, s) 122 ## print 'cmd=%s' % cmd 123 ## res = os.system(cmd) 124 ## print 'res=%s' % str(res) 125 ## assert res == 0 126 ## 127 ## # is SWW file as expected? 128 ## print 'About to run compare_output_with_expected.py' 129 ## s = 'compare_output_with_expected.py' 130 ## res = os.system('python %s > %s.stdout' 131 ## % (s, s)) 132 ## print 'Result from %s is %d' % (s, res) 133 ## assert res == 0 140 # modify environment so we use the local data 141 # INUNDATIONHOME points into the 'anuga' local data directory 142 # N:\georisk_models\inundation\data\thailand\patong_tsunami_scenario\anuga 143 old_inundationhome = os.getenv(project.ENV_INUNDATIONHOME) 144 os.putenv(project.ENV_INUNDATIONHOME, 145 os.path.join(Local_Data_Directory, 'anuga')) 146 # MUXHOME isn't used, but must exist 147 undo_muxhome = False 148 if os.getenv(project.ENV_MUXHOME) is None: 149 os.putenv(project.ENV_MUXHOME, 150 os.path.join(Local_Data_Directory, 'data')) 151 undo_muxhome = True 152 153 # run the simulation, produce SWW file 154 s = 'run_model.py' 155 cmd = 'python %s > %s.stdout' % (s, s) 156 print 'cmd=%s' % cmd 157 res = os.system(cmd) 158 print 'res=%s' % str(res) 159 assert res == 0 160 161 # is SWW file as expected? 162 print 'About to run compare_output_with_expected.py' 163 s = 'compare_output_with_expected.py' 164 res = os.system('python %s > %s.stdout' 165 % (s, s)) 166 print 'Result from %s is %d' % (s, res) 167 assert res == 0 168 169 # undo environment changes 170 if old_inundationhome: 171 os.putenv(project.ENV_INUNDATIONHOME, old_inundationhome) 172 if undo_muxhome: 173 os.putenv(project.ENV_MUXHOME, None) 134 174 135 175 ################################################################################ 136 176 137 177 if __name__ == "__main__": 178 # set logging levels 179 #log.console_logging_level = log.CRITICAL # no console logging 180 log.console_logging_level = log.DEBUG 181 138 182 suite = unittest.makeSuite(Test_Patong, 'test') 139 183 runner = unittest.TextTestRunner(verbosity=2)
Note: See TracChangeset
for help on using the changeset viewer.