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,15 +17,16 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.api.system
import ifcopenshell.util.system
class TestConnectPort(test.bootstrap.IFC4):
def test_connecting_a_port(self):
port = ifcopenshell.api.run("system.add_port", self.file)
port2 = ifcopenshell.api.run("system.add_port", self.file)
ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port2)
port = ifcopenshell.api.system.add_port(self.file)
port2 = ifcopenshell.api.system.add_port(self.file)
ifcopenshell.api.system.connect_port(self.file, port1=port, port2=port2)
assert port.ConnectedTo[0].RelatedPort == port2
assert port2.ConnectedFrom[0].RelatingPort == port
assert port2.ConnectedTo[0].RelatedPort == port
@@ -35,11 +36,11 @@ class TestConnectPort(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcRelConnectsPorts")) == 2
def test_not_connecting_a_port_twice(self):
port = ifcopenshell.api.run("system.add_port", self.file)
port2 = ifcopenshell.api.run("system.add_port", self.file)
ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port2)
ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port2)
ifcopenshell.api.run("system.connect_port", self.file, port1=port2, port2=port)
port = ifcopenshell.api.system.add_port(self.file)
port2 = ifcopenshell.api.system.add_port(self.file)
ifcopenshell.api.system.connect_port(self.file, port1=port, port2=port2)
ifcopenshell.api.system.connect_port(self.file, port1=port, port2=port2)
ifcopenshell.api.system.connect_port(self.file, port1=port2, port2=port)
assert port.ConnectedTo[0].RelatedPort == port2
assert port2.ConnectedFrom[0].RelatingPort == port
assert port2.ConnectedTo[0].RelatedPort == port
@@ -49,9 +50,9 @@ class TestConnectPort(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcRelConnectsPorts")) == 2
def test_connecting_a_port_from_source_to_sink(self):
port = ifcopenshell.api.run("system.add_port", self.file)
port2 = ifcopenshell.api.run("system.add_port", self.file)
ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port2, direction="SOURCE")
port = ifcopenshell.api.system.add_port(self.file)
port2 = ifcopenshell.api.system.add_port(self.file)
ifcopenshell.api.system.connect_port(self.file, port1=port, port2=port2, direction="SOURCE")
assert port.ConnectedTo[0].RelatedPort == port2
assert port2.ConnectedFrom[0].RelatingPort == port
assert port.FlowDirection == "SOURCE"
@@ -59,9 +60,9 @@ class TestConnectPort(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcRelConnectsPorts")) == 1
def test_connecting_a_port_from_sink_to_source(self):
port = ifcopenshell.api.run("system.add_port", self.file)
port2 = ifcopenshell.api.run("system.add_port", self.file)
ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port2, direction="SINK")
port = ifcopenshell.api.system.add_port(self.file)
port2 = ifcopenshell.api.system.add_port(self.file)
ifcopenshell.api.system.connect_port(self.file, port1=port, port2=port2, direction="SINK")
assert port2.ConnectedTo[0].RelatedPort == port
assert port.ConnectedFrom[0].RelatingPort == port2
assert port.FlowDirection == "SINK"
@@ -69,9 +70,9 @@ class TestConnectPort(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcRelConnectsPorts")) == 1
def test_connecting_a_port_as_both_source_and_sink(self):
port = ifcopenshell.api.run("system.add_port", self.file)
port2 = ifcopenshell.api.run("system.add_port", self.file)
ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port2, direction="SOURCEANDSINK")
port = ifcopenshell.api.system.add_port(self.file)
port2 = ifcopenshell.api.system.add_port(self.file)
ifcopenshell.api.system.connect_port(self.file, port1=port, port2=port2, direction="SOURCEANDSINK")
assert port.ConnectedTo[0].RelatedPort == port2
assert port2.ConnectedFrom[0].RelatingPort == port
assert port2.ConnectedTo[0].RelatedPort == port
@@ -81,11 +82,11 @@ class TestConnectPort(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcRelConnectsPorts")) == 2
def test_ports_can_only_connect_to_one_port_at_a_time(self):
port = ifcopenshell.api.run("system.add_port", self.file)
port2 = ifcopenshell.api.run("system.add_port", self.file)
port3 = ifcopenshell.api.run("system.add_port", self.file)
ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port3, direction="SOURCEANDSINK")
ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port2, direction="SOURCE")
port = ifcopenshell.api.system.add_port(self.file)
port2 = ifcopenshell.api.system.add_port(self.file)
port3 = ifcopenshell.api.system.add_port(self.file)
ifcopenshell.api.system.connect_port(self.file, port1=port, port2=port3, direction="SOURCEANDSINK")
ifcopenshell.api.system.connect_port(self.file, port1=port, port2=port2, direction="SOURCE")
assert port.ConnectedTo[0].RelatedPort == port2
assert port2.ConnectedFrom[0].RelatingPort == port
assert port.FlowDirection == "SOURCE"
@@ -95,10 +96,10 @@ class TestConnectPort(test.bootstrap.IFC4):
assert not port3.ConnectedFrom
def test_changing_a_port_from_source_and_sink_to_only_source(self):
port = ifcopenshell.api.run("system.add_port", self.file)
port2 = ifcopenshell.api.run("system.add_port", self.file)
ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port2, direction="SOURCEANDSINK")
ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port2, direction="SOURCE")
port = ifcopenshell.api.system.add_port(self.file)
port2 = ifcopenshell.api.system.add_port(self.file)
ifcopenshell.api.system.connect_port(self.file, port1=port, port2=port2, direction="SOURCEANDSINK")
ifcopenshell.api.system.connect_port(self.file, port1=port, port2=port2, direction="SOURCE")
assert port.ConnectedTo[0].RelatedPort == port2
assert port2.ConnectedFrom[0].RelatingPort == port
assert port.FlowDirection == "SOURCE"
@@ -106,12 +107,12 @@ class TestConnectPort(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcRelConnectsPorts")) == 1
def test_connecting_ports_with_a_realising_element(self):
port = ifcopenshell.api.run("system.add_port", self.file)
port2 = ifcopenshell.api.run("system.add_port", self.file)
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowFitting")
ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port2, element=element)
port = ifcopenshell.api.system.add_port(self.file)
port2 = ifcopenshell.api.system.add_port(self.file)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcFlowFitting")
ifcopenshell.api.system.connect_port(self.file, port1=port, port2=port2, element=element)
assert self.file.by_type("IfcRelConnectsPorts")[0].RealizingElement == element
ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port2)
ifcopenshell.api.system.connect_port(self.file, port1=port, port2=port2)
assert self.file.by_type("IfcRelConnectsPorts")[0].RealizingElement is None