mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 19:07:57 +00:00
Replace all ifcopenshell.api.run with ifcopenshell.api static functions.
This commit is contained in:
@@ -17,52 +17,53 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.type
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestReassignClass(test.bootstrap.IFC4):
|
||||
def test_reassigning_a_simple_class(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
n_elements = len([e for e in self.file])
|
||||
original_id = element.id()
|
||||
new = ifcopenshell.api.run("root.reassign_class", self.file, product=element, ifc_class="IfcSlab")
|
||||
new = ifcopenshell.api.root.reassign_class(self.file, product=element, ifc_class="IfcSlab")
|
||||
assert len([e for e in self.file]) == n_elements
|
||||
assert new.id() == original_id
|
||||
assert new.is_a("IfcSlab")
|
||||
|
||||
def test_reassigning_a_predefined_type(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
new = ifcopenshell.api.run(
|
||||
"root.reassign_class", self.file, product=element, ifc_class="IfcSlab", predefined_type="FLOOR"
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
new = ifcopenshell.api.root.reassign_class(
|
||||
self.file, product=element, ifc_class="IfcSlab", predefined_type="FLOOR"
|
||||
)
|
||||
assert new.PredefinedType == "FLOOR"
|
||||
|
||||
def test_falling_back_to_userdefined_if_the_predefined_type_cannot_be_reassigned_for_occurrence_class(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
new = ifcopenshell.api.run(
|
||||
"root.reassign_class", self.file, product=element, ifc_class="IfcSlab", predefined_type="FOO"
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
new = ifcopenshell.api.root.reassign_class(
|
||||
self.file, product=element, ifc_class="IfcSlab", predefined_type="FOO"
|
||||
)
|
||||
assert new.PredefinedType == "USERDEFINED"
|
||||
assert new.ObjectType == "FOO"
|
||||
|
||||
def test_falling_back_to_userdefined_if_the_predefined_type_cannot_be_reassigned_for_type_class(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
new = ifcopenshell.api.run(
|
||||
"root.reassign_class", self.file, product=element, ifc_class="IfcSlabType", predefined_type="FOO"
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
new = ifcopenshell.api.root.reassign_class(
|
||||
self.file, product=element, ifc_class="IfcSlabType", predefined_type="FOO"
|
||||
)
|
||||
assert new.PredefinedType == "USERDEFINED"
|
||||
assert new.ElementType == "FOO"
|
||||
|
||||
def test_reassign_class_for_type_occurrences(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element1], relating_type=element_type)
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element2], relating_type=element_type)
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1], relating_type=element_type)
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element2], relating_type=element_type)
|
||||
|
||||
element_type = ifcopenshell.api.run(
|
||||
"root.reassign_class", self.file, product=element_type, ifc_class="IfcSlabType"
|
||||
element_type = ifcopenshell.api.root.reassign_class(
|
||||
self.file, product=element_type, ifc_class="IfcSlabType"
|
||||
)
|
||||
|
||||
# type occurrences have reassigned classes
|
||||
@@ -75,13 +76,13 @@ class TestReassignClass(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcWallType")) == 0
|
||||
|
||||
def test_reassigning_type_class_and_its_occurrences_classes_if_entity_was_typed(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element1], relating_type=element_type)
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element2], relating_type=element_type)
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1], relating_type=element_type)
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element2], relating_type=element_type)
|
||||
|
||||
element1 = ifcopenshell.api.run("root.reassign_class", self.file, product=element1, ifc_class="IfcSlab")
|
||||
element1 = ifcopenshell.api.root.reassign_class(self.file, product=element1, ifc_class="IfcSlab")
|
||||
|
||||
# occurrence type has reassigned class
|
||||
element_type = ifcopenshell.util.element.get_type(element1)
|
||||
|
||||
Reference in New Issue
Block a user