def test_dict_to_object_view(): """Test the dict_to_object method with View objects.""" v_obj = View('test_view', (0, 0, 10), (0, 1, 0), (0, 0, 1), 'l', 240, 300, -10, -25) v_dict = v_obj.to_dict() new_v = dict_to_object(v_dict) assert isinstance(new_v, View)
def test_dict_to_object_sensor_grid(): """Test the dict_to_object method with SensorGrid objects.""" sensors = [Sensor((0, 0, 0), (0, 0, 1)), Sensor((0, 0, 10), (0, 0, 1))] sg_obj = SensorGrid('sg_1', sensors) sg_dict = sg_obj.to_dict() new_sg = dict_to_object(sg_dict) assert isinstance(new_sg, SensorGrid)
def test_dict_to_object_sky_mtx(): """Test the dict_to_object method with SkyMatrix objects.""" wea = './tests/assets/wea/denver.wea' wea = Wea.from_file(wea) sky_mtx_obj = SkyMatrix(wea) sky_mtx_dict = sky_mtx_obj.to_dict() new_sky_mtx = dict_to_object(sky_mtx_dict) assert isinstance(new_sky_mtx, SkyMatrix)
def test_dict_to_object_modifier_set(): """Test the dict_to_object method with Modifier objects.""" default_set = ModifierSet('Tinted_Window_Set') glass_material = Glass.from_single_transmittance('test_glass', 0.6) glass_material_dark = Glass.from_single_transmittance( 'test_glass_dark', 0.3) default_set.aperture_set.exterior_modifier = glass_material default_set.aperture_set.skylight_modifier = glass_material_dark mod_set_dict = default_set.to_dict() new_mod_set = dict_to_object(mod_set_dict) assert isinstance(new_mod_set, ModifierSet)
def test_dict_to_object_cie_sky(): """Test the dict_to_object method with Sky objects.""" sky_obj = CIE(38.186734, 270.410387) sky_dict = sky_obj.to_dict() new_sky = dict_to_object(sky_dict) assert isinstance(new_sky, CIE)
def test_dict_to_object_modifier(): """Test the dict_to_object method with Modifier objects.""" gl_obj = Glass('test_glass', 0.6, 0.7, 0.8, 1.52) gl_dict = gl_obj.to_dict() new_gl = dict_to_object(gl_dict) assert isinstance(new_gl, Glass)
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)