def test_given_precipitationlist_serialize_precipitation_per_timestep( self): precipitation_list = [["2.4"]] * 4 serialzied_pl = BuiEventSerializer.serialize_precipitation_per_timestep( precipitation_list) expected_string = "2.4\n2.4\n2.4\n2.4" assert serialzied_pl == expected_string
def test_given_duration_get_timedelta_fields(self): duration = timedelta(days=4, hours=2, minutes=2, seconds=4) dict_duration = BuiEventSerializer.get_timedelta_fields(duration) assert dict_duration["d_seconds"] == 4 assert dict_duration["d_minutes"] == 2 assert dict_duration["d_hours"] == 2 assert dict_duration["d_days"] == 4
def test_given_dict_serialize_into_text(self): precipitation_event_list = dict( start_time=datetime(1996, 1, 1), timeseries_length=timedelta(1, 10800), precipitation_per_timestep=[ [0.2], [0.2], [0.2], [0.2], ], ) serialized_text = BuiEventSerializer.serialize( precipitation_event_list) expected_string = inspect.cleandoc(""" * Event 1 duration days:1 hours:3 minutes:0 seconds:0 * Start date and time of the event: yyyy mm dd hh mm ss * Duration of the event : dd hh mm ss * Rainfall value per time step [mm/time step] 1996 1 1 0 0 0 1 3 0 0 0.2 0.2 0.2 0.2 """) assert serialized_text == expected_string
def test_given_timedelta_serialize_timeseries_length(self): duration = timedelta(days=4, hours=2, minutes=2, seconds=4) serialized_td = BuiEventSerializer.serialize_timeseries_length( duration) expected_string = "4 2 2 4" assert serialized_td == expected_string
def test_given_datetime_serialize_start_time(self): starttime = datetime(2021, 12, 20, 4, 2, 24) serialized_st = BuiEventSerializer.serialize_start_time(starttime) expected_string = "2021 12 20 4 2 24" assert serialized_st == expected_string
def test_given_timeseries_length_serialize_into_text(self): timeseries_length = timedelta(4, 2000) expected_string = "4 0 33 20" serialized_text = BuiEventSerializer.serialize_timeseries_length( timeseries_length) assert serialized_text == expected_string
def test_given_start_time_serialize_into_text(self): first_event = datetime(2021, 12, 20, 0, 42, 24) expected_string = "2021 12 20 0 42 24" serialized_text = BuiEventSerializer.serialize_start_time( first_event) assert serialized_text == expected_string
def test_given_precipitation_serialize_into_text(self): precipitation_per_timestep = [["0.2"], ["0.2"], ["0.2"], ["0.2"]] serialized_text = BuiEventSerializer.serialize_precipitation_per_timestep( precipitation_per_timestep) assert serialized_text == "0.2\n0.2\n0.2\n0.2"