Changeset 6639


Ignore:
Timestamp:
Mar 27, 2009, 10:35:59 AM (15 years ago)
Author:
rwilson
Message:

Working to the point of fetching remote data if required.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_validation/automated_validation_tests/patong_validation/validate_patong.py

    r6609 r6639  
    22Automatic verification that the ANUGA code validates against the patong
    33dataset as expected.
     4
     5Required files are downloaded from the ANUGA servers if they are
     6out of date or missing.
    47'''
    58
     
    710import glob
    811import unittest
     12import logging
    913import project
     14from anuga.utilities.system_tools import get_web_file
     15import anuga.utilities.log as log
    1016
     17# set logging levels
     18log.console_logging_level = logging.DEBUG
     19log.log_logging_level = logging.DEBUG
     20
     21
     22# path to the local data directory
     23Local_Data_Directory = os.path.join('.', 'local_data')
     24
     25# path to the remote data directory
     26Remote_Data_Directory = os.path.join('.', 'remote_data')
     27
     28# sequence of required local data objects
     29Local_Data_Objects = ('patong.sww', 'anuga')
     30
     31# base URL for the remote ANUGA data
     32ANUGA_URL = 'http://10.7.64.243/patong_validation_data/'
     33
     34def 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       
    1197
    1298class Test_Patong(unittest.TestCase):
    1399    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 
    22100        # Check that environment variables are defined.
    23101        if os.getenv(project.ENV_INUNDATIONHOME) is None:
     
    32110
    33111    def tearDown(self):
    34         # delete all output necessary
    35112        pass
    36113
    37114    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'
    44118
    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
    51134
    52135################################################################################
Note: See TracChangeset for help on using the changeset viewer.