Replace all ifcopenshell.api.run with ifcopenshell.api static functions.

This commit is contained in:
Dion Moult
2024-06-28 12:36:31 +10:00
parent b5d613989e
commit 07060fc769
432 changed files with 4633 additions and 4856 deletions
@@ -17,22 +17,22 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.cost
import ifcopenshell.util.element
class TestAddCostItem(test.bootstrap.IFC4):
def test_add_a_cost_item(self):
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo")
item1 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
schedule = ifcopenshell.api.cost.add_cost_schedule(self.file, name="Foo")
item1 = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=schedule)
assert item1.is_a("IfcCostItem")
assert item1.HasAssignments[0].is_a("IfcRelAssignsToControl")
assert item1.HasAssignments[0].RelatingControl == schedule
def test_add_a_sub_cost_item(self):
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo")
item1 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
item2 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_item=item1)
schedule = ifcopenshell.api.cost.add_cost_schedule(self.file, name="Foo")
item1 = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=schedule)
item2 = ifcopenshell.api.cost.add_cost_item(self.file, cost_item=item1)
assert item2.is_a("IfcCostItem")
assert ifcopenshell.util.element.get_nest(item2) == item1
@@ -17,22 +17,24 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.cost
import ifcopenshell.api.root
import ifcopenshell.api.control
class TestAddCostItemQuantity(test.bootstrap.IFC4):
def test_run(self):
schema = ifcopenshell.schema_by_name(self.file.schema)
quantity_types = [t.name() for t in schema.declaration_by_name("IfcPhysicalSimpleQuantity").subtypes()]
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file)
item = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("control.assign_control", self.file, relating_control=item, related_object=wall)
schedule = ifcopenshell.api.cost.add_cost_schedule(self.file)
item = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=schedule)
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.control.assign_control(self.file, relating_control=item, related_object=wall)
quantities = []
for quantity_type in quantity_types:
quantity = ifcopenshell.api.run(
"cost.add_cost_item_quantity", self.file, cost_item=item, ifc_class=quantity_type
quantity = ifcopenshell.api.cost.add_cost_item_quantity(
self.file, cost_item=item, ifc_class=quantity_type
)
assert quantity.is_a(quantity_type)
assert quantity.Name == "Unnamed"
@@ -17,18 +17,18 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.cost
class TestAddCostSchedule(test.bootstrap.IFC4):
def test_add_a_cost_schedule(self):
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="BUDGET")
schedule = ifcopenshell.api.cost.add_cost_schedule(self.file, name="Foo", predefined_type="BUDGET")
assert schedule.is_a("IfcCostSchedule")
assert schedule.Name == "Foo"
assert schedule.PredefinedType == "BUDGET"
def test_adding_a_userdefined_type(self):
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="FOO")
schedule = ifcopenshell.api.cost.add_cost_schedule(self.file, name="Foo", predefined_type="FOO")
assert schedule.is_a("IfcCostSchedule")
assert schedule.Name == "Foo"
assert schedule.PredefinedType == "USERDEFINED"
@@ -17,31 +17,31 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.cost
class TestRemoveCostItem(test.bootstrap.IFC4):
def test_remove_a_cost_item(self):
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="BUDGET")
item1 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
ifcopenshell.api.run("cost.remove_cost_item", self.file, cost_item=item1)
schedule = ifcopenshell.api.cost.add_cost_schedule(self.file, name="Foo", predefined_type="BUDGET")
item1 = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=schedule)
ifcopenshell.api.cost.remove_cost_item(self.file, cost_item=item1)
assert not self.file.by_type("IfcCostItem")
assert not self.file.by_type("IfcRelAssignsToControl")
def test_remove_a_sub_cost_item(self):
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="BUDGET")
item1 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
item2 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_item=item1)
ifcopenshell.api.run("cost.remove_cost_item", self.file, cost_item=item2)
schedule = ifcopenshell.api.cost.add_cost_schedule(self.file, name="Foo", predefined_type="BUDGET")
item1 = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=schedule)
item2 = ifcopenshell.api.cost.add_cost_item(self.file, cost_item=item1)
ifcopenshell.api.cost.remove_cost_item(self.file, cost_item=item2)
assert self.file.by_type("IfcCostItem") == [item1]
assert self.file.by_type("IfcRelAssignsToControl")
assert not self.file.by_type("IfcRelNests")
def test_remove_a_parent_cost_item(self):
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="BUDGET")
item1 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
item2 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_item=item1)
ifcopenshell.api.run("cost.remove_cost_item", self.file, cost_item=item1)
schedule = ifcopenshell.api.cost.add_cost_schedule(self.file, name="Foo", predefined_type="BUDGET")
item1 = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=schedule)
item2 = ifcopenshell.api.cost.add_cost_item(self.file, cost_item=item1)
ifcopenshell.api.cost.remove_cost_item(self.file, cost_item=item1)
assert not self.file.by_type("IfcCostItem")
assert not self.file.by_type("IfcRelAssignsToControl")
assert not self.file.by_type("IfcRelNests")
@@ -18,19 +18,20 @@
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.cost
class TestRemoveCostSchedule(test.bootstrap.IFC4):
def test_remove_a_cost_schedule(self):
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="BUDGET")
ifcopenshell.api.run("cost.remove_cost_schedule", self.file, cost_schedule=schedule)
schedule = ifcopenshell.api.cost.add_cost_schedule(self.file, name="Foo", predefined_type="BUDGET")
ifcopenshell.api.cost.remove_cost_schedule(self.file, cost_schedule=schedule)
assert not self.file.by_type("IfcCostSchedule")
def test_remove_a_schedule_with_items(self):
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="BUDGET")
item1 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
item2 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_item=item1)
ifcopenshell.api.run("cost.remove_cost_schedule", self.file, cost_schedule=schedule)
schedule = ifcopenshell.api.cost.add_cost_schedule(self.file, name="Foo", predefined_type="BUDGET")
item1 = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=schedule)
item2 = ifcopenshell.api.cost.add_cost_item(self.file, cost_item=item1)
ifcopenshell.api.cost.remove_cost_schedule(self.file, cost_schedule=schedule)
assert not self.file.by_type("IfcCostSchedule")
assert not self.file.by_type("IfcCostItem")
assert not self.file.by_type("IfcRelNests")