def test_error_handling(correct, incorrect): with pytest.raises(AssertionError, match='sensible_heat must be a number got *'): TrafficPar(incorrect['sensible_heat'], correct['weekday_schedule'], correct['saturday_schedule'], correct['sunday_schedule']) with pytest.raises( ValueError, match='schedule value must be between 0 and 1. Current value is *' ): TrafficPar(correct['sensible_heat'], incorrect['non_fractional'], correct['saturday_schedule'], correct['sunday_schedule']) with pytest.raises( Exception, match= 'Current schedule has length \d*. Daily schedules must be lists of 24 values' ): TrafficPar(correct['sensible_heat'], correct['weekday_schedule'], incorrect['too_short'], correct['sunday_schedule']) with pytest.raises( Exception, match= 'Current schedule has length \d*. Daily schedules must be lists of 24 values' ): TrafficPar(correct['sensible_heat'], correct['weekday_schedule'], incorrect['too_long'], correct['sunday_schedule'])
def test_json(correct): parameters = TrafficPar(correct['sensible_heat'], correct['weekday_schedule'], correct['saturday_schedule'], correct['sunday_schedule']) param_json = parameters.to_json() assert param_json == correct assert TrafficPar.from_json(param_json).to_json() == correct
def correct(): typology1 = Typology(average_height=35.0, footprint_area=20000.0, facade_area=45000.0, bldg_program='Hospital', bldg_era='1980sPresent', floor_to_floor=3.0) typology2 = Typology(average_height=35.0, footprint_area=5000.0, facade_area=15000.0, bldg_program='SmallOffice', bldg_era='NewConstruction', floor_to_floor=3.0) site_area = 90000.0 return { 'typologies': [typology1, typology2], 'site_area': site_area, 'climate_zone': '5A', 'tree_coverage_ratio': 0.3, 'grass_coverage_ratio': 0.1, 'traffic_parameters': TrafficPar(4.0), 'vegetation_parameters': VegetationPar(), 'pavement_parameters': PavementPar(), 'characteristic_length': 300.0 }
def test_initialise(correct): correct_parameters = TrafficPar(correct['sensible_heat'], correct['weekday_schedule'], correct['saturday_schedule'], correct['sunday_schedule']) assert correct_parameters.sensible_heat == correct['sensible_heat'] assert correct_parameters.weekday_schedule == correct['weekday_schedule'] assert correct_parameters.saturday_schedule == correct['saturday_schedule'] assert correct_parameters.sunday_schedule == correct['sunday_schedule']
def default(): return { 'average_bldg_height': 35.0, 'site_coverage_ratio': 0.3, 'facade_to_site_ratio': 4.0, 'bldg_type_ratios': { 'MidRiseApartment,Pre1980s': 0.7, 'LargeOffice,1980sPresent': 0.3 }, 'climate_zone': '5A', 'tree_coverage_ratio': 0., 'grass_coverage_ratio': 0., 'traffic_parameters': TrafficPar(10.0), 'vegetation_parameters': VegetationPar(), 'pavement_parameters': PavementPar(), 'characteristic_length': 500 }
def test_default(default): default_parameters = TrafficPar(4) assert default_parameters.weekday_schedule == default['weekday_schedule'] assert default_parameters.saturday_schedule == default['saturday_schedule'] assert default_parameters.sunday_schedule == default['sunday_schedule']