|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 |
|
| 5 | +import ifcopenshell |
5 | 6 | from ifcopenshell.mvd import rule, template |
6 | 7 |
|
7 | 8 |
|
@@ -117,7 +118,46 @@ def test_from_graphviz_reports_unknown_reference() -> None: |
117 | 118 | ``` |
118 | 119 | """ |
119 | 120 |
|
120 | | - with pytest.raises( |
121 | | - ValueError, match="Unknown Graphviz template reference: Surface_Color_Style" |
122 | | - ): |
| 121 | + with pytest.raises(ValueError, match="Unknown Graphviz template reference: Surface_Color_Style"): |
123 | 122 | template.from_graphviz(source) |
| 123 | + |
| 124 | + |
| 125 | +def test_from_graphviz_entity_leaf_filters_ifc_type() -> None: |
| 126 | + source = """\ |
| 127 | +``` |
| 128 | +concept { |
| 129 | + IfcRelDefinesByProperties:RelatingPropertyDefinition -> IfcPropertySetDefinitionSet |
| 130 | +} |
| 131 | +``` |
| 132 | +""" |
| 133 | + parsed = template.from_graphviz(source) |
| 134 | + |
| 135 | + class entity(ifcopenshell.entity_instance): |
| 136 | + def __init__(self, ifc_class: str): |
| 137 | + self.ifc_class = ifc_class |
| 138 | + |
| 139 | + def is_a(self, ifc_class: str) -> bool: |
| 140 | + return self.ifc_class == ifc_class |
| 141 | + |
| 142 | + class relationship: |
| 143 | + def __init__(self, relating_property_definition: entity): |
| 144 | + self.RelatingPropertyDefinition = relating_property_definition |
| 145 | + |
| 146 | + assert parsed.extract(relationship(entity("IfcPropertySetDefinitionSet"))) |
| 147 | + assert not parsed.extract(relationship(entity("IfcPropertySet"))) |
| 148 | + |
| 149 | + |
| 150 | +def test_from_graphviz_leaf_uses_parent_attribute_binding() -> None: |
| 151 | + source = """\ |
| 152 | +``` |
| 153 | +concept { |
| 154 | + IfcPointByDistanceExpression:BasisCurve -> IfcCurve |
| 155 | + IfcPointByDistanceExpression:BasisCurve[binding="BasisCurve"] |
| 156 | +} |
| 157 | +``` |
| 158 | +""" |
| 159 | + |
| 160 | + parsed = template.from_graphviz(source) |
| 161 | + leaf = parsed.rules[0].nodes[0] |
| 162 | + |
| 163 | + assert parsed.binding_for(leaf) == "BasisCurve" |