def test_new_from_dict_filename(): """ test to_dict function for Wind object create a new wind object and make sure it has same properties """ wm = Wind(filename=wind_file) wm_state = wm.to_dict('create') print wm_state # this does not catch two objects with same ID wm2 = Wind.new_from_dict(wm_state) assert wm == wm2
def test_from_dict(): """ test update_from_dict function for Wind object update existing wind object update_from_dict """ wm = Wind(filename=wind_file) wm_dict = wm.to_dict() # let's update timeseries update_value = np.array((10., 180.)) (wm_dict['timeseries'][0]['value'])[:] = update_value wm.update_from_dict(wm_dict) updatable_attr = wm._state.get_field_by_attribute('update') for key in wm_dict.keys(): if key in updatable_attr and key != 'timeseries': assert getattr(wm, key) == wm_dict[key] assert np.all(wm.timeseries['value'][0] == update_value)
def test_from_dict(): """ test from_dict function for Wind object update existing wind object from_dict """ wm = Wind(filename=wind_file) wm_dict = wm.to_dict() # let's update timeseries update_value = np.array((10., 180.)) (wm_dict['timeseries'][0]['value'])[:] = update_value wm.from_dict(wm_dict) for key in wm_dict.keys(): if key != 'timeseries': assert wm.__getattribute__(key) == wm_dict.__getitem__(key) assert np.all(wm.timeseries['value'][0] == update_value)