diff --git a/src/ifctester/ifctester/facet.py b/src/ifctester/ifctester/facet.py index b69943b210..08d28e434c 100644 --- a/src/ifctester/ifctester/facet.py +++ b/src/ifctester/ifctester/facet.py @@ -126,14 +126,16 @@ class Facet: ) -> str: if clause_type == "applicability": templates = self.applicability_templates - elif clause_type == "requirement": - is_prohibited = False if specification and specification.maxOccurs == 0: - is_prohibited = not is_prohibited - if requirement and requirement.cardinality == "prohibited": - is_prohibited = not is_prohibited - templates = self.prohibited_templates if is_prohibited else self.requirement_templates - if requirement and requirement.cardinality == "optional": + templates = self.prohibited_templates + elif clause_type == "requirement": + if specification and specification.maxOccurs == 0: + return "The requirement is not applicable" + if (not requirement) or isinstance(requirement, Entity) or requirement.cardinality == "required": + templates = self.requirement_templates + elif requirement.cardinality == "prohibited": + templates = self.prohibited_templates + elif requirement.cardinality == "optional": templates = [ t.replace("shall", "may").replace("Shall", "May").replace("must", "may") for t in templates ] diff --git a/src/ifctester/test/test_facet.py b/src/ifctester/test/test_facet.py index c14a7853c2..3daa2d213f 100644 --- a/src/ifctester/test/test_facet.py +++ b/src/ifctester/test/test_facet.py @@ -32,6 +32,7 @@ import ifcopenshell.api.type import ifcopenshell.api.unit import ifcopenshell.guid import ifcopenshell.util.pset +import ifctester.ids import ifctester.facet from ifctester.facet import Entity, Attribute, Classification, Property, PartOf, Material, Restriction @@ -229,6 +230,31 @@ class TestEntity: wall3 = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall", predefined_type="BAZFOO") run("Restrictions an be specified for the predefined type 3/3", facet=facet, inst=wall3, expected=False) + def test_to_string_required_applicability(self): + spec = ifctester.ids.Specification(name="Foo", minOccurs=1, maxOccurs="unbounded") + facet = Entity(name="IFCWALL") + assert facet.to_string("applicability", spec) == "All IFCWALL data" + + def test_to_string_optional_applicability(self): + spec = ifctester.ids.Specification(name="Foo", minOccurs=0, maxOccurs="unbounded") + facet = Entity(name="IFCWALL") + assert facet.to_string("applicability", spec) == "All IFCWALL data" + + def test_to_string_prohibited_applicability(self): + spec = ifctester.ids.Specification(name="Foo", minOccurs=0, maxOccurs=0) + facet = Entity(name="IFCWALL") + assert facet.to_string("applicability", spec) == "Shall not be IFCWALL data" + + def test_to_string_ignored_requirement(self): + spec = ifctester.ids.Specification(name="Foo", minOccurs=0, maxOccurs=0) + facet = Entity(name="IFCWALL") + assert facet.to_string("requirement", spec) == "The requirement is not applicable" + + def test_to_string_required_requirement(self): + spec = ifctester.ids.Specification(name="Foo") + facet = Entity(name="IFCWALL") + assert facet.to_string("requirement", spec) == "Shall be IFCWALL data" + class TestAttribute: def test_creating_an_attribute_facet(self):