Changeset 6639
- Timestamp:
- Mar 27, 2009, 10:35:59 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_validation/automated_validation_tests/patong_validation/validate_patong.py
r6609 r6639 2 2 Automatic verification that the ANUGA code validates against the patong 3 3 dataset as expected. 4 5 Required files are downloaded from the ANUGA servers if they are 6 out of date or missing. 4 7 ''' 5 8 … … 7 10 import glob 8 11 import unittest 12 import logging 9 13 import project 14 from anuga.utilities.system_tools import get_web_file 15 import anuga.utilities.log as log 10 16 17 # set logging levels 18 log.console_logging_level = logging.DEBUG 19 log.log_logging_level = logging.DEBUG 20 21 22 # path to the local data directory 23 Local_Data_Directory = os.path.join('.', 'local_data') 24 25 # path to the remote data directory 26 Remote_Data_Directory = os.path.join('.', 'remote_data') 27 28 # sequence of required local data objects 29 Local_Data_Objects = ('patong.sww', 'anuga') 30 31 # base URL for the remote ANUGA data 32 ANUGA_URL = 'http://10.7.64.243/patong_validation_data/' 33 34 def update_local_data(): 35 36 # update one data object 37 def update_object(obj, auth): 38 remote_path = os.path.join(Remote_Data_Directory, obj) 39 remote_digest = remote_path + '.tgz.digest' 40 41 local_path = os.path.join(Local_Data_Directory, obj) 42 local_digest = local_path + '.tgz.digest' 43 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' 47 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) 53 else: 54 # download object digest to remote data directory 55 object_url = ANUGA_URL + obj + '.tgz.digest' 56 log.debug('Fetching remote file %s' % object_url) 57 auth = get_web_file(object_url, remote_digest, auth=auth) 58 59 # compare remote with local digest, refresh if necessary 60 fd = open(local_digest, 'r') 61 local_digest_data = fd.read() 62 fd.close() 63 64 fd = open(remote_digest, 'r') 65 remote_digest_data = fd.read() 66 fd.close() 67 68 if local_digest_data != remote_digest_data: 69 # refresh local digest & object 70 fd = open(local_digest, 'w') 71 fd.write(remote_digest_data) 72 fd.close() 73 74 object_url = ANUGA_URL + obj + '.tgz' 75 local_file = local_path + '.tgz' 76 log.debug('Fetching remote file %s' % object_url) 77 auth = get_web_file(object_url, local_file, auth=auth) 78 return auth 79 80 81 # create local data directory if required 82 if not os.path.exists(Local_Data_Directory): 83 os.mkdir(Local_Data_Directory) 84 85 # create or clean out remote data copy directory 86 if not os.path.exists(Remote_Data_Directory): 87 os.mkdir(Remote_Data_Directory) 88 rem_files = glob.glob(os.path.join(Remote_Data_Directory, '*')) 89 for file in rem_files: 90 os.remove(file) 91 92 # refresh local files 93 auth = None 94 for data_object in Local_Data_Objects: 95 auth = update_object(data_object, auth) 96 11 97 12 98 class Test_Patong(unittest.TestCase): 13 99 def setUp(self): 14 15 ## for file in glob.glob('./*.stdout'):16 ## os.remove(file)17 ## for file in glob.glob('./*.sww'):18 ## os.remove(file)19 ## for file in glob.glob('./*.msh'):20 ## os.remove(file)21 22 100 # Check that environment variables are defined. 23 101 if os.getenv(project.ENV_INUNDATIONHOME) is None: … … 32 110 33 111 def tearDown(self): 34 # delete all output necessary35 112 pass 36 113 37 114 def test_that_output_is_as_expected(self): 38 s = 'run_model.py' 39 cmd = 'python %s > %s.stdout' % (s, s) 40 print 'cmd=%s' % cmd 41 res = os.system(cmd) 42 print 'res=%s' % str(res) 43 assert res == 0 115 # make sure local data is up to date 116 update_local_data() 117 print 'update done' 44 118 45 print 'About to run compare_output_with_expected.py' 46 s = 'compare_output_with_expected.py' 47 res = os.system('python %s > %s.stdout' 48 % (s, s)) 49 print 'Result from %s is %d' % (s, res) 50 assert res == 0 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 51 134 52 135 ################################################################################
Note: See TracChangeset
for help on using the changeset viewer.