diff --git a/unit_tests/test_gen.py b/unit_tests/test_gen.py index ade8acfe64e08b6d071e881b41ce15d812a28d75..d11b692e5f5d68f8966c7d900d54062cf7e1335b 100644 --- a/unit_tests/test_gen.py +++ b/unit_tests/test_gen.py @@ -15,8 +15,8 @@ def _main(): #Source Coords dx = 1000 # units in km dy = 1000 # units in Km - jpi = 15 - jpj = 15 + jpi = 16 + jpj = 16 jpk = 10 max_dep = 100 min_dep = 10 @@ -28,15 +28,15 @@ def _main(): write_coord_H = gt.write_coord_H(h_fname,grid_h1) write_coord_Z = gt.write_coord_Z(z_fname,grid_h1,grid_z1) if write_coord_H + write_coord_Z == 0: - print("Success!") + print("Parent grid generation successful!") #Dst Coords dx = 100 # units in km dy = 100 # units in Km jpi = 100 jpj = 100 - zoffx = 20 - zoffy = 20 + zoffx = 30 + zoffy = 30 jpk = 10 max_dep = 100 min_dep = 10 @@ -52,12 +52,12 @@ def _main(): bathy_fname = 'unit_tests/test_data/test_dst_bathy.nc' bathy = gt.write_bathy(bathy_fname,grid_h2,grid_z2) if write_coord_H + write_coord_Z + bathy == 0: - print("Success!") + print("Org child grid generation successful!") # set rotation and origin point rot = 45 theta = gt.radians(rot) - origin = (7,7) + origin = (8,8) # rotate grid rot_h_fname = 'unit_tests/test_data/test_rot_dst_hgr_zps.nc' @@ -73,7 +73,7 @@ def _main(): bathy_fname = 'unit_tests/test_data/test_rot_dst_bathy.nc' bathy = gt.write_bathy(bathy_fname,grid_rot,grid_z2) if write_coord_H + write_coord_Z + bathy == 0: - print("Success!") + print("Rotated child grid generation Successful!") # offset grid dx = 100 # units in km @@ -97,26 +97,27 @@ def _main(): bathy_fname = 'unit_tests/test_data/test_offset_dst_bathy.nc' bathy = gt.write_bathy(bathy_fname,grid_h3,grid_z3) if write_coord_H + write_coord_Z + bathy == 0: - print("Success!") + print("Offset child grid gneration successful!") # plot orginal, rotatated and source lat and lon - #gt.plot_grids(grid_h2['latt'],grid_h2['lont'],grid_rot['latt'],grid_rot['lont'],grid_h3['latt'], \ - # grid_h3['lont'],grid_h1['latt'],grid_h1['lont']) + gt.plot_grids(grid_h2['latt'],grid_h2['lont'],grid_rot['latt'],grid_rot['lont'],grid_h3['latt'], \ + grid_h3['lont'],grid_h1['latt'],grid_h1['lont']) # write boundary files (constant parameters) out_fname = 'unit_tests/test_data/output_boundary_T.nc' params = {'param1': {'name':'thetao','const_value':15.0,'longname':'temperature','units':'degreesC'}, 'param2': {'name':'so','const_value':35.0,'longname':'salinity','units':'PSU'} } + # TODO: This needs to be adapted for parameters that are not on the T grid. boundary = gt.write_parameter(out_fname,grid_h1,grid_z1,params) if boundary == 0: - print('Success!') + print('Boundary file generation successful!') #write_mask mask_fname = 'unit_tests/test_data/mask.nc' mask = gt.write_mask(mask_fname,grid_h1,grid_z1) if mask == 0: - print('Success!') + print('Mask file generation successful!') return 0 diff --git a/unit_tests/unit_test.py b/unit_tests/unit_test.py index 84fbbf37c9e6d21a06ff2c55339e5ab2a6a3090d..2f5a5c8d7ee91498fe3f1524576366646f6a4fa6 100644 --- a/unit_tests/unit_test.py +++ b/unit_tests/unit_test.py @@ -10,20 +10,24 @@ import glob import os # generate test data by import test gen script and executing main function +# TODO: Maybe simplify this, as this import imports other scripts and is abit clunky. import unit_tests.test_gen as tg gen_data = tg._main() +# if a non zero is return than the grid and data generation has failed. if gen_data != 0: - raise Exception('DONT PANIC: Input data generation failed') - -# TODO: run different bdy files or change bdy file for different grid types for testing. + raise Exception('DONT PANIC: Input grid and boundary data generation failed') # run PyNEMO with test data +# generate list of namelist.bdy files to run namelist_files = glob.glob('unit_tests/namelist*') for n in namelist_files: + # run each of the namelist files stdout, stderr = Popen(['pynemo', '-s', n], stdout=PIPE, stderr=PIPE, universal_newlines=True).communicate() -if 'Execution Time' not in stdout: - raise Exception('DONT PANIC: Test Run Failed') + # check to see if PyNEMO ran correctly, no execution time in stdout is indication of this. + if 'Execution Time' not in stdout: + print(stderr) + raise Exception('DONT PANIC: Test Run '+str(n)+' Failed') # TODO: Learn about parameterising the tests so that different parameters can be checked # with same code. Rather than having similar test functions repeated.