def test_exceptions(output_filename): spill_pair = SpillContainerPair() print "output_filename:", output_filename # begin tests netcdf = NetCDFOutput(output_filename, which_data='all') netcdf.rewind() # delete temporary files with raises(TypeError): # need to pass in model start time netcdf.prepare_for_model_run(num_time_steps=4) with raises(TypeError): # need to pass in model start time and spills netcdf.prepare_for_model_run() with raises(ValueError): # need a cache object netcdf.write_output(0) with raises(ValueError): netcdf.which_data = 'some random string' # changed renderer and netcdf ouputter to delete old files in # prepare_for_model_run() rather than rewind() # -- rewind() was getting called a lot # -- before there was time to change the ouput file names, etc. # So for this unit test, there should be no exception if we do it twice. netcdf.prepare_for_model_run(model_start_time=datetime.now(), spills=spill_pair, num_time_steps=4) netcdf.prepare_for_model_run(model_start_time=datetime.now(), spills=spill_pair, num_time_steps=4) with raises(AttributeError): 'cannot change after prepare_for_model_run has been called' netcdf.prepare_for_model_run(model_start_time=datetime.now(), spills=spill_pair, num_time_steps=4) netcdf.which_data = 'most'
def test_exceptions(): t_file = os.path.join(base_dir, 'temp.nc') # clean up temporary file from previos run if os.path.exists(t_file): print 'remove temporary file {0}'.format(t_file) os.remove(t_file) netcdf = NetCDFOutput(t_file, which_data='all') with raises(TypeError): # need to pass in model start time netcdf.prepare_for_model_run(num_time_steps=4) with raises(TypeError): # need to pass in model start time netcdf.prepare_for_model_run() with raises(ValueError): # needs a spills object for "all" netcdf.prepare_for_model_run(model_start_time=datetime.now(), num_time_steps=4,) with raises(ValueError): # need a cache object netcdf.write_output(0) with raises(ValueError): # raise error because file 'temp.nc' should already exist netcdf.prepare_for_model_run(model_start_time=datetime.now(), num_time_steps=4) with raises(ValueError): # which_data is 'all' but spills are not provided so raise an error netcdf.rewind() netcdf.which_data = 'all' netcdf.prepare_for_model_run(model_start_time=datetime.now(), num_time_steps=4) with raises(ValueError): netcdf.which_data = 'some random string'