Changeset 4924


Ignore:
Timestamp:
Jan 10, 2008, 10:48:21 AM (17 years ago)
Author:
nick
Message:

Added test for screen_catcher in data_manager.py. Also added a print statement telling user that output will now be store in a file when using screen_catcher and added file.close() to the write function in screen_catcher.

Location:
anuga_core/source/anuga/shallow_water
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r4899 r4924  
    52575257       
    52585258def start_screen_catcher(dir_name, myid='', numprocs='', extra_info='',
    5259                          verbose=False):
     5259                         verbose=True):
    52605260    """
    52615261    Used to store screen output and errors to file, if run on multiple
     
    52765276      #  if verbose: print "myid", myid
    52775277        mkdir (dir_name,0777)
     5278#    print 'helloa'
    52785279    if myid <>'':
    52795280        myid = '_'+str(myid)
     
    52825283    if extra_info <>'':
    52835284        extra_info = '_'+str(extra_info)
     5285#    print 'hello1'
    52845286    screen_output_name = dir_name + "screen_output%s%s%s.txt" %(myid,
    52855287                                                                numprocs,
     
    52885290                                                              numprocs,
    52895291                                                              extra_info)
    5290     if verbose: print screen_output_name
     5292
     5293    if verbose: print 'Starting ScreenCatcher, all output will be stored in %s' \
     5294                                     %(screen_output_name)
    52915295    #used to catch screen output to file
    52925296    sys.stdout = Screen_Catcher(screen_output_name)
     
    53005304    def __init__(self, filename):
    53015305        self.filename = filename
    5302  
     5306#        print 'init'
    53035307        if exists(self.filename)is True:
    53045308            print'Old existing file "%s" has been deleted' %(self.filename)
     
    53085312        fid = open(self.filename, 'a')
    53095313        fid.write(stuff)
    5310 
     5314        fid.close()
     5315       
    53115316def copy_code_files(dir_name, filename1, filename2=None):
    53125317    """Copies "filename1" and "filename2" to "dir_name". Very useful for
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r4899 r4924  
    73567356        assert len(iterate)==4
    73577357
     7358    def test_screen_catcher(self):
     7359   
     7360        stdout_orginal = sys.stdout
     7361        stderr_orginal = sys.stderr
     7362       
     7363        output_dir = tempfile.mkdtemp('','output_test')
     7364        #print output_dir
     7365        start_screen_catcher(output_dir+sep,verbose=False)
     7366       
     7367        print 'hello screen catcher'
     7368        print 'goodbye screen catcher'
     7369       
     7370        sys.stdout = stdout_orginal
     7371        sys.stderr = stderr_orginal
     7372       
     7373        output_file = output_dir+sep+'screen_output.txt'
     7374        assert access(output_file,F_OK)
     7375       
     7376        fid = open(output_file)
     7377        file_line1 = fid.readline()
     7378        file_line2 = fid.readline()
     7379       
     7380        #print 'file contents',file_line1, file_line2
     7381        assert (file_line1 == 'hello screen catcher\n')
     7382        assert (file_line2 == 'goodbye screen catcher\n')
    73587383       
    73597384       
     
    73657390
    73667391    #suite = unittest.makeSuite(Test_Data_Manager,'test_export_gridII')
    7367     #suite = unittest.makeSuite(Test_Data_Manager,'test_sww_header')
     7392#    suite = unittest.makeSuite(Test_Data_Manager,'test_screen_catcher')
    73687393    suite = unittest.makeSuite(Test_Data_Manager,'test')
    73697394    #suite = unittest.makeSuite(Test_Data_Manager,'test_urs_ungridded_holeII')
Note: See TracChangeset for help on using the changeset viewer.