def test_serialize_deseriailize(): 'test serialize/deserialize for webapi' wind = constant_wind(1., 0) water = Water() w = Waves(wind, water) json_ = w.serialize() # deserialize and ensure the dict's are correct w2 = Waves.deserialize(json_) assert w2.wind == Wind.deserialize(json_['wind']) assert w2.water == Water.deserialize(json_['water']) assert w == w2
def test_roundtrip_dst_spring_transition(): """ checking the round trip trhough serializing for time series crossing over the spring DST transition. """ timeseries = gen_timeseries_for_dst('spring') wind_json = { 'obj_type': 'gnome.environment.wind.Wind', 'description': 'dst transition test', 'latitude': 90, 'longitude': 90, 'updated_at': '2016-03-12T12:52:45.385126', 'source_type': u'manual', 'source_id': u'unknown', 'timeseries': timeseries, 'units': 'knots', 'json_': u'webapi' } wind = Wind.deserialize(wind_json) # now make one from the new dict... wind2 = Wind.deserialize(wind_json) assert wind2 == wind
def test_update_from_dict_with_dst_spring_transition(): """ checking a time series crossing over a DST transition. NOTE: the ofset is ignored! so there is no way to do this "right" """ timeseries = gen_timeseries_for_dst('spring') wind_json = { 'obj_type': 'gnome.environment.Wind', 'description': 'dst transition test', 'latitude': 90, 'longitude': 90, 'updated_at': '2016-03-12T12:52:45.385126', 'source_type': u'manual', 'source_id': u'unknown', 'timeseries': timeseries, 'units': 'knots', 'json_': u'webapi' } wind = Wind.deserialize(wind_json) assert wind.description == 'dst transition test' assert wind.units == 'knots' ts = wind.get_timeseries() # this should raise if there is a problem wind._check_timeseries(ts) assert True # if we got here, the test passed.
def test_update_from_dict_with_dst_spring_transition(): """ checking a time series crossing over a DST transition. NOTE: the ofset is ignored! so there is no way to do this "right" """ timeseries = gen_timeseries_for_dst('spring') wind_json = {'obj_type': 'gnome.environment.Wind', 'description': 'dst transition test', 'latitude': 90, 'longitude': 90, 'updated_at': '2016-03-12T12:52:45.385126', 'source_type': u'manual', 'source_id': u'unknown', 'timeseries': timeseries, 'units': 'knots', 'json_': u'webapi' } wind = Wind.deserialize(wind_json) assert wind.description == 'dst transition test' assert wind.units == 'knots' ts = wind.get_timeseries() # this should raise if there is a problem wind._check_timeseries(ts) assert True # if we got here, the test passed.
def test_serialize_deserialize(): 'test serialize/deserialize for webapi' wind = constant_wind(1., 0) av = RunningAverage(wind) json_ = av.serialize() json_['wind'] = wind.serialize() # deserialize and ensure the dict's are correct d_av = RunningAverage.deserialize(json_) assert d_av['wind'] == Wind.deserialize(json_['wind']) d_av['wind'] = wind av.update_from_dict(d_av) assert av.wind is wind
def test_serialize_deserialize_update_webapi(wind_circ): ''' wind_circ is a fixture create - it creates new object after serializing original object and tests equality of the two update - tests serialize/deserialize and update_from_dict methods don't fail. It doesn't update any properties. ''' wind = wind_circ['wind'] serial = wind.serialize('webapi') dict_ = Wind.deserialize(serial) wind.update_from_dict(dict_) assert True
def test_roundtrip_dst_spring_transition(): """ checking the round trip trhough serializing for time series crossing over the spring DST transition. """ timeseries = gen_timeseries_for_dst('spring') wind_json = {'obj_type': 'gnome.environment.wind.Wind', 'description': 'dst transition test', 'latitude': 90, 'longitude': 90, 'updated_at': '2016-03-12T12:52:45.385126', 'source_type': u'manual', 'source_id': u'unknown', 'timeseries': timeseries, 'units': 'knots', 'json_': u'webapi' } wind = Wind.deserialize(wind_json) # now make one from the new dict... wind2 = Wind.deserialize(wind_json) assert wind2 == wind
def test_serialize_deserialize(wind_circ, do): ''' wind_circ is a fixture create - it creates new object after serializing original object and tests equality of the two update - tests serialize/deserialize and from_dict methods don't fail. It doesn't update any properties. ''' json_ = wind_circ['wind'].serialize(do) dict_ = Wind.deserialize(json_) if do == 'create': new_w = Wind.new_from_dict(dict_) assert new_w == wind_circ['wind'] else: wind_circ['wind'].from_dict(dict_) assert True
def test_serialize_deseriailize(): 'test serialize/deserialize for webapi' e = Evaporation() wind = constant_wind(1., 0) water = Water() json_ = e.serialize() json_['wind'] = wind.serialize() json_['water'] = water.serialize() # deserialize and ensure the dict's are correct d_ = Evaporation.deserialize(json_) assert d_['wind'] == Wind.deserialize(json_['wind']) assert d_['water'] == Water.deserialize(json_['water']) d_['wind'] = wind d_['water'] = water e.update_from_dict(d_) assert e.wind is wind assert e.water is water
def test_serialize_deseriailize(): "test serialize/deserialize for webapi" wind = constant_wind(1.0, 0) water = Water() w = Waves(wind, water) json_ = w.serialize() json_["wind"] = wind.serialize() json_["water"] = water.serialize() # deserialize and ensure the dict's are correct d_ = Waves.deserialize(json_) print "d_" print d_ assert d_["wind"] == Wind.deserialize(json_["wind"]) assert d_["water"] == Water.deserialize(json_["water"]) d_["wind"] = wind d_["water"] = water w.update_from_dict(d_) assert w.wind is wind assert w.water is water
def test_serialize_deseriailize(): 'test serialize/deserialize for webapi' wind = constant_wind(1., 0) water = Water() w = Waves(wind, water) json_ = w.serialize() json_['wind'] = wind.serialize() json_['water'] = water.serialize() # deserialize and ensure the dict's are correct d_ = Waves.deserialize(json_) print 'd_' print d_ assert d_['wind'] == Wind.deserialize(json_['wind']) assert d_['water'] == Water.deserialize(json_['water']) d_['wind'] = wind d_['water'] = water w.update_from_dict(d_) assert w.wind is wind assert w.water is water
def test_new_from_dict_with_dst_fall_transition(): """ checking a time series crossing over fall DST transition. This creates duplicate times, which we can't deal with. """ wind_json = {'obj_type': 'gnome.environment.Wind', 'description': 'fall dst transition test', 'latitude': 90, 'longitude': 90, 'updated_at': '2016-03-12T12:52:45.385126', 'source_type': u'manual', 'source_id': u'unknown', 'timeseries': gen_timeseries_for_dst('fall'), 'units': 'knots', 'json_': u'webapi' } wind = Wind.deserialize(wind_json) assert wind.description == 'fall dst transition test' assert wind.units == 'knots'
def test_new_from_dict_with_dst_fall_transition(): """ checking a time series crossing over fall DST transition. This creates duplicate times, which we can't deal with. """ wind_json = { 'obj_type': 'gnome.environment.Wind', 'description': 'fall dst transition test', 'latitude': 90, 'longitude': 90, 'updated_at': '2016-03-12T12:52:45.385126', 'source_type': u'manual', 'source_id': u'unknown', 'timeseries': gen_timeseries_for_dst('fall'), 'units': 'knots', 'json_': u'webapi' } wind = Wind.deserialize(wind_json) assert wind.description == 'fall dst transition test' assert wind.units == 'knots'