Changeset 2263


Ignore:
Timestamp:
Jan 20, 2006, 5:05:41 PM (18 years ago)
Author:
ole
Message:

Work towards a test_all.py at the inundation directory level. Most tests pass except a few in least_squares, data_manager and cg_solve...

Files:
1 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • inundation/caching/test_caching.py

    r2043 r2263  
    206206        assert T1 == T3, 'Recomputed value with changed dependencies failed'
    207207
    208     def test_performance(self):       
    209         """Performance test (with statistics)
    210         Don't really rely on this as it will depend on specific computer.
    211         """
    212         import time
    213         set_option('savestat', 1)
    214 
    215         N = 300000   #Should be large on fast computers...
    216         a = [1,2]
    217         b = ('Thou shalt count the number three',4)
    218         c = {'Five is right out': 6, (7,8): 9}
    219         x = 3
    220         y = 'holy hand granate'
    221        
    222        
    223         tt = time.time()
    224         T1 = cache(f,(a,b,c,N), {'x':x, 'y':y})
    225         t1 = time.time() - tt
    226  
    227         tt = time.time()
    228         T2 = cache(f,(a,b,c,N), {'x':x, 'y':y})
    229         t2 = time.time() - tt
    230  
    231         assert T1 == T2
    232         assert t1 > t2, 'WARNING: Performance a bit low - this could be specific to current platform. Try to increase N in this test'
    233         #test_OK('Performance test: relative time saved = %s pct' \
    234         #        %str(round((t1-t2)*100/t1,2)))
     208    #def test_performance(self):       
     209    #    """Performance test (with statistics)
     210    #    Don't really rely on this as it will depend on specific computer.
     211    #    """
     212    #
     213    #    import time
     214    #    set_option('savestat', 1)
     215    #
     216    #    N = 300000   #Should be large on fast computers...
     217    #    a = [1,2]
     218    #    b = ('Thou shalt count the number three',4)
     219    #    c = {'Five is right out': 6, (7,8): 9}
     220    #    x = 3
     221    #    y = 'holy hand granate'
     222    #     
     223    #   
     224    #    tt = time.time()
     225    #    T1 = cache(f,(a,b,c,N), {'x':x, 'y':y})
     226    #    t1 = time.time() - tt
     227    #
     228    #    tt = time.time()
     229    #    T2 = cache(f,(a,b,c,N), {'x':x, 'y':y})
     230    #    t2 = time.time() - tt
     231     
     232    #    assert T1 == T2
     233    #     assert t1 > t2, 'WARNING: Performance a bit low - this could be specific to current platform. Try to increase N in this test'
     234    #    #test_OK('Performance test: relative time saved = %s pct' \
     235    #    #        %str(round((t1-t2)*100/t1,2)))
    235236
    236237
  • inundation/pyvolution/test_data_manager.py

    r2262 r2263  
    7070
    7171
     72
     73
     74        #Write A testfile
     75
     76        self.test_MOST_file = 'xxxsmall_ha.nc'
     77
     78        longitudes = [150.66667, 150.83334, 151., 151.16667]
     79        latitudes = [-34.5, -34.33333, -34.16667, -34]
     80
     81        long_name = 'LON'
     82        lat_name = 'LAT'
     83
     84        nx = 4
     85        ny = 4
     86        six = 6
     87
     88
     89        fid = NetCDFFile(self.test_MOST_file, 'w')
     90       
     91        fid.createDimension(long_name,nx)
     92        fid.createVariable(long_name,'d',(long_name,))
     93        fid.variables[long_name].point_spacing='uneven'
     94        fid.variables[long_name].units='degrees_east'
     95        fid.variables[long_name].assignValue(longitudes)
     96
     97        fid.createDimension(lat_name,ny)
     98        fid.createVariable(lat_name,'d',(lat_name,))
     99        fid.variables[lat_name].point_spacing='uneven'
     100        fid.variables[lat_name].units='degrees_north'
     101        fid.variables[lat_name].assignValue(latitudes)
     102
     103        fid.createDimension('TIME',six)
     104        fid.createVariable('TIME','d',('TIME',))
     105        fid.variables['TIME'].point_spacing='uneven'
     106        fid.variables['TIME'].units='seconds'
     107        fid.variables['TIME'].assignValue([0.0, 0.1, 0.6, 1.1, 1.6, 2.1])
     108
     109        fid.createVariable('HA','d',('TIME', lat_name, long_name))
     110        #fid.createVariable('HA','d',(lat_name, long_name))
     111        fid.variables['HA'].assignValue([[[0.3400644, 0, -46.63519, -6.50198],
     112                                          [-0.1214216, 0, 0, 0],
     113                                          [0, 0, 0, 0],
     114                                          [0, 0, 0, 0]],
     115                                         [[0.3400644, 2.291054e-005, -23.33335, -6.50198],
     116                                          [-0.1213987, 4.581959e-005, -1.594838e-007, 1.421085e-012],
     117                                          [2.291054e-005, 4.582107e-005, 4.581715e-005, 1.854517e-009],
     118                                          [0, 2.291054e-005, 2.291054e-005, 0]],
     119                                         [[0.3400644, 0.0001374632, -23.31503, -6.50198],
     120                                          [-0.1212842, 0.0002756907, 0.006325484, 1.380492e-006],
     121                                          [0.0001374632, 0.0002749264, 0.0002742863, 6.665601e-008],
     122                                          [0, 0.0001374632, 0.0001374632, 0]],
     123                                         [[0.3400644, 0.0002520159, -23.29672, -6.50198],
     124                                          [-0.1211696, 0.0005075303, 0.01264618, 6.208276e-006],
     125                                          [0.0002520159, 0.0005040318, 0.0005027961, 2.23865e-007],
     126                                          [0, 0.0002520159, 0.0002520159, 0]],
     127                                         [[0.3400644, 0.0003665686, -23.27842, -6.50198],
     128                                          [-0.1210551, 0.0007413362, 0.01896192, 1.447638e-005],
     129                                          [0.0003665686, 0.0007331371, 0.0007313463, 4.734126e-007],
     130                                          [0, 0.0003665686, 0.0003665686, 0]],
     131                                         [[0.3400644, 0.0004811212, -23.26012, -6.50198],
     132                                          [-0.1209405, 0.0009771062, 0.02527271, 2.617787e-005],
     133                                          [0.0004811212, 0.0009622425, 0.0009599366, 8.152277e-007],
     134                                          [0, 0.0004811212, 0.0004811212, 0]]])
     135           
     136       
     137        fid.close()
     138       
     139
     140
    72141    def tearDown(self):
    73         pass
     142        import os
     143        #os.remove(self.test_MOST_file)
     144       
    74145
    75146    def test_sww_constant(self):
     
    17961867        """
    17971868        from Scientific.IO.NetCDF import NetCDFFile
     1869        import os, sys
    17981870
    17991871        #The test file has
     
    18051877        # Fourth value (index==3) is -6.50198 cm
    18061878
    1807 
     1879       
     1880
     1881        #Read
    18081882        from coordinate_transforms.redfearn import redfearn
    1809 
    1810         fid = NetCDFFile('small_ha.nc')
     1883        fid = NetCDFFile(self.test_MOST_file)
    18111884        first_value = fid.variables['HA'][:][0,0,0]
    18121885        fourth_value = fid.variables['HA'][:][0,0,3]
     
    18691942        from coordinate_transforms.redfearn import redfearn
    18701943
    1871         fid = NetCDFFile('small_ha.nc')
     1944        #fid = NetCDFFile('small_ha.nc')
     1945        fid = NetCDFFile(self.test_MOST_file)
    18721946
    18731947        #Pick a coordinate and a value
  • inundation/pyvolution/test_most2nc.py

    r1123 r2263  
    33import most2nc
    44from Scientific.IO.NetCDF import NetCDFFile
     5import os
     6
     7FN = 'small___.txt'
    58
    69class Test_most2nc(unittest.TestCase):
    710    def setUp(self):
    8         pass
    9 
     11        fid = open(FN, 'w')
     12        fid.write("""4 4
     13150.66667
     14150.83334
     15151.
     16151.16667
     17-34.
     18-34.16667
     19-34.33333
     20-34.5
     21-1. -2. -3. -4.
     22-5. -6. -7. -8.
     23-9. -10. -11. -12.
     24-13. -14. -15. -16.
     25""")
     26        fid.close()
     27                 
    1028    def tearDown(self):
    11         pass
     29        os.remove(FN)
    1230
    1331    def test_small_nxn(self):
    14         most2nc.most2nc(input_file='small.txt',output_file='test.nc'\
     32        most2nc.most2nc(input_file=FN,output_file='test.nc'\
    1533                        ,inverted_bathymetry = False,verbose = False)
    1634
     
    2947        os.remove('test.nc')
    3048       
     49if __name__ == "__main__":
     50    suite = unittest.makeSuite(Test_most2nc,'test')
     51    runner = unittest.TextTestRunner()
     52    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.