Example #1
0
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_dict = Wind.deserialize(wind_json)
    wind = Wind.new_from_dict(wind_dict.copy())  # new munges the dict! (pop?)

    # now re-serialize:
    wind_dict2 = wind.serialize('webapi')

    # now make one from the new dict...
    wind_dict2 = Wind.deserialize(wind_json)
    wind2 = Wind.new_from_dict(wind_dict2.copy())

    assert wind2 == wind
Example #2
0
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_dict = Wind.deserialize(wind_json)
    wind = Wind.new_from_dict(wind_dict)

    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.
Example #3
0
def test_new_from_dict_timeseries():
    """
    test to_dict function for Wind object
    create a new wind object and make sure it has same properties
    """

    wm = ConstantWind(10, 45, 'knots')
    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
Example #4
0
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
Example #5
0
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
Example #6
0
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_dict = Wind.deserialize(wind_json)
    wind = Wind.new_from_dict(wind_dict)

    assert wind.description == 'fall dst transition test'
    assert wind.units == 'knots'