set_element_value for enums - add a test

This commit is contained in:
Andrej730
2024-12-06 15:59:22 +05:00
parent 6fe5af3170
commit c7af55183b
@@ -29,6 +29,7 @@ import ifcopenshell.api.geometry
import ifcopenshell.api.aggregate
import ifcopenshell.api.group
import ifcopenshell.api.sequence
import ifcopenshell.util.element
import ifcopenshell.util.selector as subject
import ifcopenshell.util.placement
import ifcopenshell.util.pset
@@ -405,3 +406,22 @@ class TestSetElementValuePredefinedType(test.bootstrap.IFC4):
assert element_type.ElementType == "FOOBAR"
assert element.PredefinedType == None
assert element.ObjectType == None
class TestSetElementValueEnum(test.bootstrap.IFC4):
def test_setting_an_element_enum(self):
element = self.file.create_entity("IfcWindow")
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Pset_WallCommon")
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Status": ("NEW",)})
subject.set_element_value(self.file, element, "Pset_WallCommon.Status", "DEMOLISH, OTHER")
pset_data = ifcopenshell.util.element.get_pset(element, "Pset_WallCommon")
assert pset_data["Status"] == ["DEMOLISH", "OTHER"]
# Wrong value for enum.
with pytest.raises(Exception):
subject.set_element_value(self.file, element, "Pset_WallCommon.Status", "NON_EXISTENT_VALUE")
# String is using wrong concatenations tring and it should be identified as non-existent value.
with pytest.raises(Exception):
subject.set_element_value(self.file, element, "Pset_WallCommon.Status", "DEMOLISH,OTHER")