def test_dict_to_object_sch(): """Test the dict_to_object method with ScheduleRuleset objects.""" sch_obj = ScheduleRuleset.from_constant_value( 'Office Heating', 21, schedule_types.temperature) sch_dict = sch_obj.to_dict() new_sch = dict_to_object(sch_dict) assert isinstance(new_sch, ScheduleRuleset)
def test_dict_to_object_load(): """Test the dict_to_object method with Setpoint objects.""" heat_setpt = ScheduleRuleset.from_constant_value( 'Office Heating', 21, schedule_types.temperature) cool_setpt = ScheduleRuleset.from_constant_value( 'Office Cooling', 24, schedule_types.temperature) setpoint = Setpoint('Office Setpoint', heat_setpt, cool_setpt) setpoint_dict = setpoint.to_dict() new_setpoint = dict_to_object(setpoint_dict) assert isinstance(new_setpoint, Setpoint)
elif model_ver != hb_ver: msg = 'Imported Model schema version "{}" is older than that with the ' \ 'currently installed Honeybee "{}".\nThe Model will be upgraded upon ' \ 'import.'.format(data['version'], folders.honeybee_schema_version_str) print msg if all_required_inputs(ghenv.Component) and _load: with open(_hb_file, 'rb') as pkl_file: data = pickle.load(pkl_file) version_check(data) # try to check the version try: hb_objs = hb_dict_util.dict_to_object( data, False) # re-serialize as a core object if hb_objs is None: # try to re-serialize it as an energy object hb_objs = energy_dict_util.dict_to_object(data, False) if hb_objs is None: # try to re-serialize it as a radiance object hb_objs = radiance_dict_util.dict_to_object(data, False) elif isinstance(hb_objs, Model): model_units_tolerance_check(hb_objs) except ValueError: # no 'type' key; assume that its a group of objects hb_objs = [] for hb_dict in data.values(): hb_obj = hb_dict_util.dict_to_object( hb_dict, False) # re-serialize as a core object if hb_obj is None: # try to re-serialize it as an energy object hb_obj = energy_dict_util.dict_to_object(hb_dict, False) if hb_obj is None: # try to re-serialize it as a radiance object hb_obj = radiance_dict_util.dict_to_object(hb_dict, False) hb_objs.append(hb_obj)
elif model_ver != df_ver: msg = 'Imported Model schema version "{}" is older than that with the ' \ 'currently installed Dragonfly "{}".\nThe Model will be upgraded upon ' \ 'import.'.format(data['version'], folders.dragonfly_schema_version_str) print msg if all_required_inputs(ghenv.Component) and _load: with open(_df_file) as json_file: data = json.load(json_file) version_check(data) # try to check the version try: df_objs = df_dict_util.dict_to_object( data, False) # re-serialize as a core object if df_objs is None: # try to re-serialize it as an energy object df_objs = energy_dict_util.dict_to_object(data, False) if df_objs is None: # try to re-serialize it as a radiance object df_objs = radiance_dict_util.dict_to_object(data, False) elif isinstance(df_objs, Model): model_units_tolerance_check(df_objs) except ValueError: # no 'type' key; assume that its a group of objects df_objs = [] for df_dict in data.values(): df_obj = df_dict_util.dict_to_object( df_dict, False) # re-serialize as a core object if df_obj is None: # try to re-serialize it as an energy object df_obj = energy_dict_util.dict_to_object(df_dict, False) if df_obj is None: # try to re-serialize it as a radiance object df_obj = radiance_dict_util.dict_to_object(df_dict, False) df_objs.append(df_obj)
data: Dictionary of the object, which optionally has the "version" key. """ if 'version' in data and data['version'] is not None: model_ver = tuple(int(d) for d in data['version'].split('.')) hb_ver = folders.honeybee_schema_version if model_ver > hb_ver: msg = 'Imported Model schema version "{}" is newer than that with the ' \ 'currently installed Honeybee "{}".\nThe Model may fail to import ' \ 'or (worse) some newer features of the Model might not be imported ' \ 'without detection.'.format(data['version'], folders.honeybee_schema_version_str) print msg give_warning(ghenv.Component, msg) elif model_ver != hb_ver: msg = 'Imported Model schema version "{}" is older than that with the ' \ 'currently installed Honeybee "{}".\nThe Model will be upgraded upon ' \ 'import.'.format(data['version'], folders.honeybee_schema_version_str) print msg if all_required_inputs(ghenv.Component): hb_dict = json.loads(_hb_str) version_check(hb_dict) # try to check the version hb_obj = hb_dict_util.dict_to_object( hb_dict, False) # re-serialize as a core object if hb_obj is None: # try to re-serialize it as an energy object hb_obj = energy_dict_util.dict_to_object(hb_dict, False) if hb_obj is None: # try to re-serialize it as a radiance object hb_obj = radiance_dict_util.dict_to_object(hb_dict, False) elif isinstance(hb_obj, Model): model_units_tolerance_check(hb_obj)
def test_dict_to_object_construction(): """Test the dict_to_object method with AirBoundaryConstruction objects.""" construction_obj = AirBoundaryConstruction('Test Air Wall') construction_dict = construction_obj.to_dict() new_construction = dict_to_object(construction_dict) assert isinstance(new_construction, AirBoundaryConstruction)
def test_dict_to_object_material(): """Test the dict_to_object method with EnergyWindowMaterialBlind objects.""" material_obj = EnergyWindowMaterialBlind('Test Blind') material_dict = material_obj.to_dict() new_material = dict_to_object(material_dict) assert isinstance(new_material, EnergyWindowMaterialBlind)
def test_dict_to_object_sim_par(): """Test the dict_to_object method with SimulationParameter objects.""" sim_par_obj = SimulationParameter() sim_par_dict = sim_par_obj.to_dict() new_sim_par = dict_to_object(sim_par_dict) assert isinstance(new_sim_par, SimulationParameter)
def test_dict_to_object_constr_set(): """Test the dict_to_object method with ConstructionSet objects.""" constr_set_obj = ConstructionSet('Test ConstructionSet') constr_set_dict = constr_set_obj.to_dict() new_constr_set = dict_to_object(constr_set_dict) assert isinstance(new_constr_set, ConstructionSet)
def test_dict_to_object_program_type(): """Test the dict_to_object method with ProgramType objects.""" program_type_obj = ProgramType('Test Program') program_type_dict = program_type_obj.to_dict() new_prog_type = dict_to_object(program_type_dict) assert isinstance(new_prog_type, ProgramType)