mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-17 02:49:12 +00:00
Replace all ifcopenshell.api.run with ifcopenshell.api static functions.
This commit is contained in:
@@ -17,18 +17,18 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.group
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestAddGroup(test.bootstrap.IFC4):
|
||||
def test_add_group_no_arguments(self):
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
group = ifcopenshell.api.group.add_group(self.file)
|
||||
assert group.Name == "Unnamed"
|
||||
assert group.Description == None
|
||||
|
||||
def test_add_group(self):
|
||||
group = ifcopenshell.api.run("group.add_group", self.file, name="Name", description="Description")
|
||||
group = ifcopenshell.api.group.add_group(self.file, name="Name", description="Description")
|
||||
assert group.Name == "Name"
|
||||
assert group.Description == "Description"
|
||||
|
||||
|
||||
@@ -17,27 +17,28 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.group
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestAssignGroup(test.bootstrap.IFC4):
|
||||
def test_assign_group_for_multiple_elements(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
group = ifcopenshell.api.group.add_group(self.file)
|
||||
|
||||
# assign group for multiple elements
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=[element, element2], group=group)
|
||||
ifcopenshell.api.group.assign_group(self.file, products=[element, element2], group=group)
|
||||
assert len(self.file.by_type("IfcRelAssignsToGroup")) == 1
|
||||
assert set(ifcopenshell.util.element.get_grouped_by(group)) == set(self.file.by_type("IfcWall"))
|
||||
|
||||
def test_reuse_existing_relationship(self):
|
||||
self.test_assign_group_for_multiple_elements()
|
||||
rel = self.file.by_type("IfcRelAssignsToGroup")[0]
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
group = self.file.by_type("IfcGroup")[0]
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=[element], group=group)
|
||||
ifcopenshell.api.group.assign_group(self.file, products=[element], group=group)
|
||||
|
||||
assert len(self.file.by_type("IfcRelAssignsToGroup")) == 1
|
||||
assert set(ifcopenshell.util.element.get_grouped_by(group)) == set(self.file.by_type("IfcWall"))
|
||||
|
||||
@@ -17,27 +17,29 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.group
|
||||
|
||||
|
||||
class TestRemoveGroup(test.bootstrap.IFC4):
|
||||
def test_removing_a_group(self):
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
ifcopenshell.api.run("group.remove_group", self.file, group=group)
|
||||
group = ifcopenshell.api.group.add_group(self.file)
|
||||
ifcopenshell.api.group.remove_group(self.file, group=group)
|
||||
assert len(self.file.by_type("IfcGroup")) == 0
|
||||
|
||||
def test_removing_orphaned_group_relationships(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=[element], group=group)
|
||||
ifcopenshell.api.run("group.remove_group", self.file, group=group)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
group = ifcopenshell.api.group.add_group(self.file)
|
||||
ifcopenshell.api.group.assign_group(self.file, products=[element], group=group)
|
||||
ifcopenshell.api.group.remove_group(self.file, group=group)
|
||||
assert not self.file.by_type("IfcRelAssignsToGroup")
|
||||
|
||||
def test_removing_orphaned_property_relationships(self):
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=group, name="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
ifcopenshell.api.run("group.remove_group", self.file, group=group)
|
||||
group = ifcopenshell.api.group.add_group(self.file)
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=group, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
ifcopenshell.api.group.remove_group(self.file, group=group)
|
||||
assert not self.file.by_type("IfcRelDefinesByProperties")
|
||||
assert not self.file.by_type("IfcPropertySet")
|
||||
assert not self.file.by_type("IfcPropertySingleValue")
|
||||
|
||||
@@ -17,17 +17,18 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.group
|
||||
|
||||
|
||||
class TestAssignGroup(test.bootstrap.IFC4):
|
||||
def test_group_unassignment(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=[element, element2, element3], group=group)
|
||||
ifcopenshell.api.run("group.unassign_group", self.file, products=[element2, element3], group=group)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element3 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
group = ifcopenshell.api.group.add_group(self.file)
|
||||
ifcopenshell.api.group.assign_group(self.file, products=[element, element2, element3], group=group)
|
||||
ifcopenshell.api.group.unassign_group(self.file, products=[element2, element3], group=group)
|
||||
|
||||
assert len(rels := self.file.by_type("IfcRelAssignsToGroup")) == 1
|
||||
rel = rels[0]
|
||||
@@ -35,11 +36,11 @@ class TestAssignGroup(test.bootstrap.IFC4):
|
||||
assert rel.RelatedObjects == (element,)
|
||||
|
||||
def test_remove_relationship_unassigning_last_element(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=[element, element2], group=group)
|
||||
ifcopenshell.api.run("group.unassign_group", self.file, products=[element, element2], group=group)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
group = ifcopenshell.api.group.add_group(self.file)
|
||||
ifcopenshell.api.group.assign_group(self.file, products=[element, element2], group=group)
|
||||
ifcopenshell.api.group.unassign_group(self.file, products=[element, element2], group=group)
|
||||
assert len(self.file.by_type("IfcRelAssignsToGroup")) == 0
|
||||
|
||||
|
||||
|
||||
@@ -17,22 +17,23 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.group
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestUpdateGroupProductsIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_update_group_without_products(self):
|
||||
elements = [ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") for i in range(4)]
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
ifcopenshell.api.run("group.update_group_products", self.file, products=elements, group=group)
|
||||
elements = [ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall") for i in range(4)]
|
||||
group = ifcopenshell.api.group.add_group(self.file)
|
||||
ifcopenshell.api.group.update_group_products(self.file, products=elements, group=group)
|
||||
assert set(ifcopenshell.util.element.get_grouped_by(group)) == set(elements)
|
||||
|
||||
def test_update_group_products(self):
|
||||
elements = [ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") for i in range(4)]
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=elements[:2], group=group)
|
||||
ifcopenshell.api.run("group.update_group_products", self.file, products=elements[2:], group=group)
|
||||
elements = [ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall") for i in range(4)]
|
||||
group = ifcopenshell.api.group.add_group(self.file)
|
||||
ifcopenshell.api.group.assign_group(self.file, products=elements[:2], group=group)
|
||||
ifcopenshell.api.group.update_group_products(self.file, products=elements[2:], group=group)
|
||||
assert set(ifcopenshell.util.element.get_grouped_by(group)) == set(elements[2:])
|
||||
assert ifcopenshell.util.element.get_groups(elements[0]) == []
|
||||
assert ifcopenshell.util.element.get_groups(elements[1]) == []
|
||||
@@ -41,13 +42,13 @@ class TestUpdateGroupProductsIFC2X3(test.bootstrap.IFC2X3):
|
||||
class TestUpdateGroupProductsIFC4(test.bootstrap.IFC4, TestUpdateGroupProductsIFC2X3):
|
||||
def test_update_group_products(self):
|
||||
# in ifc4 IfcGroup can have multiple rels
|
||||
elements = [ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") for i in range(4)]
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
elements = [ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall") for i in range(4)]
|
||||
group = ifcopenshell.api.group.add_group(self.file)
|
||||
|
||||
self.file.create_entity("IfcRelAssignsToGroup", RelatingGroup=group, RelatedObjects=elements[:1])
|
||||
self.file.create_entity("IfcRelAssignsToGroup", RelatingGroup=group, RelatedObjects=elements[1:2])
|
||||
|
||||
ifcopenshell.api.run("group.update_group_products", self.file, products=elements[2:], group=group)
|
||||
ifcopenshell.api.group.update_group_products(self.file, products=elements[2:], group=group)
|
||||
assert len(self.file.by_type("IfcRelAssignsToGroup")) == 1
|
||||
assert set(ifcopenshell.util.element.get_grouped_by(group)) == set(elements[2:])
|
||||
assert ifcopenshell.util.element.get_groups(elements[0]) == []
|
||||
|
||||
Reference in New Issue
Block a user