def test_validate_a_period_monthly(): """Test the validate_a_period methods for monthly collections.""" a_per = AnalysisPeriod(6, 1, 0, 7, 1, 23) v1, v2 = 20, 25 dt1, dt2 = 6, 7 # Test that the validate method correctly sorts reversed datetimes. dc1 = MonthlyCollection(Header(Temperature(), 'C', a_per), [v1, v2], [dt2, dt1]) dc1_new = dc1.validate_analysis_period() assert dc1.validated_a_period is False assert dc1_new.validated_a_period is True assert dc1.datetimes == (dt2, dt1) assert dc1_new.datetimes == (dt1, dt2) # Test that the validate method correctly updates analysis_period range. a_per_2 = AnalysisPeriod(6, 1, 0, 6, 1, 23) dc1 = MonthlyCollection(Header(Temperature(), 'C', a_per_2), [v1, v2], [dt1, dt2]) dc1_new = dc1.validate_analysis_period() assert dc1.validated_a_period is False assert dc1_new.validated_a_period is True assert dc1.header.analysis_period == a_per_2 assert dc1_new.header.analysis_period == AnalysisPeriod(6, 1, 0, 7, 31, 23) # Test that the validate method with reversed analysis_periods. a_per_3 = AnalysisPeriod(6, 1, 0, 2, 28, 23) dt5 = 1 dc1 = MonthlyCollection(Header(Temperature(), 'C', a_per_3), [v1, v2, v2], [dt5, dt1, dt2]) dc1_new = dc1.validate_analysis_period() assert dc1_new.header.analysis_period == a_per_3 assert dc1_new.datetimes == (dt1, dt2, dt5) dc1 = MonthlyCollection(Header(Temperature(), 'C', a_per_3), [v1, v2], [dt1, dt2]) dc1_new = dc1.validate_analysis_period() assert dc1_new.header.analysis_period == a_per_3 assert dc1_new.datetimes == (dt1, dt2) dc1 = MonthlyCollection(Header(Temperature(), 'C', a_per_3), [v1, v2], [dt5, 2]) dc1_new = dc1.validate_analysis_period() assert dc1_new.datetimes == (dt5, 2) assert dc1_new.header.analysis_period == a_per_3 dc1 = MonthlyCollection(Header(Temperature(), 'C', a_per_3), [v1, v2], [dt5, 4]) dc1_new = dc1.validate_analysis_period() assert dc1_new.header.analysis_period == AnalysisPeriod() assert dc1_new.datetimes == (dt5, 4) # Test that duplicated datetimes are caught dc1 = MonthlyCollection(Header(Temperature(), 'C', a_per), [v1, v2], [dt1, dt1]) with pytest.raises(Exception): dc1_new = dc1.validate_analysis_period()
def test_init_prevailing_temperature_monthly(): """Test the PrevailingTemperature object with monthly inputs.""" outdoor_header = Header(Temperature(), 'C', AnalysisPeriod()) outdoor_temp = MonthlyCollection(outdoor_header, range(12), AnalysisPeriod().months_int) outdoor_temp = outdoor_temp.validate_analysis_period() prevail_obj = PrevailingTemperature(outdoor_temp, True) assert isinstance(prevail_obj.hourly_prevailing_temperature, HourlyContinuousCollection) assert len(prevail_obj.hourly_prevailing_temperature.values) == 8760 assert isinstance(prevail_obj.daily_prevailing_temperature, DailyCollection) assert len(prevail_obj.daily_prevailing_temperature.values) == 365 assert isinstance(prevail_obj.monthly_prevailing_temperature, MonthlyCollection) assert len(prevail_obj.monthly_prevailing_temperature.values) == 12 assert isinstance(prevail_obj.monthly_per_hour_prevailing_temperature, MonthlyPerHourCollection) assert len( prevail_obj.monthly_per_hour_prevailing_temperature.values) == 288 with pytest.raises(Exception): prevail_obj = PrevailingTemperature(outdoor_temp, False)