def test_to_from_dict(): """Test the to/from dict of Room objects.""" room = Room.from_box('Shoe Box Zone', 5, 10, 3) room_dict = room.to_dict() new_room = Room.from_dict(room_dict) assert isinstance(new_room, Room) assert new_room.to_dict() == room_dict
def test_from_dict(): """Test the Room from_dict method with radiance properties.""" custom_set = ModifierSet('CustomModifierSet') room = Room.from_box('Shoe_Box', 5, 10, 3) room.properties.radiance.modifier_set = custom_set rd = room.to_dict() new_room = Room.from_dict(rd) assert new_room.properties.radiance.modifier_set.identifier == 'CustomModifierSet' assert new_room.to_dict() == rd
def test_from_dict(): """Test the Room from_dict method with energy properties.""" mass_set = ConstructionSet('Thermal Mass Construction Set') room = Room.from_box('ShoeBox', 5, 10, 3) room.properties.energy.construction_set = mass_set rd = room.to_dict() new_room = Room.from_dict(rd) assert new_room.properties.energy.construction_set.identifier == \ 'Thermal Mass Construction Set' assert new_room.to_dict() == rd
def dict_to_object(honeybee_dict, raise_exception=True): """Re-serialize a dictionary of almost any object within honeybee. This includes any Model, Room, Face, Aperture, Door, Shade, or boundary condition object. Args: honeybee_dict: A dictionary of any Honeybee object. Note that this should be a non-abridged dictionary to be valid. raise_exception: Boolean to note whether an excpetion should be raised if the object is not identified as a part of honeybee. Default: True. Returns: A Python object derived from the input honeybee_dict. """ try: # get the type key from the dictionary obj_type = honeybee_dict['type'] except KeyError: raise ValueError('Honeybee dictionary lacks required "type" key.') if obj_type == 'Model': return Model.from_dict(honeybee_dict) elif obj_type == 'Room': return Room.from_dict(honeybee_dict) elif obj_type == 'Face': return Face.from_dict(honeybee_dict) elif obj_type == 'Aperture': return Aperture.from_dict(honeybee_dict) elif obj_type == 'Door': return Door.from_dict(honeybee_dict) elif obj_type == 'Shade': return Shade.from_dict(honeybee_dict) elif hasattr(hbc, obj_type): bc_class = getattr(hbc, obj_type) return bc_class.from_dict(honeybee_dict) elif raise_exception: raise ValueError( '{} is not a recognized honeybee object'.format(obj_type))