From bd6e4fbd64bb9b5c601981ecc5cccd50d77c79fa Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 1 Aug 2023 13:37:59 +0500 Subject: [PATCH] tests for system.get_connected_to / get_connected_from --- .../ifcopenshell/util/system.py | 2 -- .../test/util/test_system.py | 28 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/system.py b/src/ifcopenshell-python/ifcopenshell/util/system.py index bc25575367..5f75b342db 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/system.py +++ b/src/ifcopenshell-python/ifcopenshell/util/system.py @@ -84,7 +84,6 @@ def get_connected_port(port): return rel.RelatingPort -# TODO: cover in tests def get_connected_to(element): results = [] for port in ifcopenshell.util.system.get_ports(element): @@ -102,7 +101,6 @@ def get_connected_to(element): return results -# TODO: cover in tests def get_connected_from(element): results = [] for port in ifcopenshell.util.system.get_ports(element): diff --git a/src/ifcopenshell-python/test/util/test_system.py b/src/ifcopenshell-python/test/util/test_system.py index 172c34bb2e..a3951f5e88 100644 --- a/src/ifcopenshell-python/test/util/test_system.py +++ b/src/ifcopenshell-python/test/util/test_system.py @@ -79,3 +79,31 @@ class TestGetConnectedPort(test.bootstrap.IFC4): ifcopenshell.api.run("system.connect_port", self.file, port1=port1, port2=port2) assert subject.get_connected_port(port1) == port2 assert subject.get_connected_port(port2) == port1 + + +class TestGetConnectedToFrom(test.bootstrap.IFC4): + def test_run(self): + port1 = ifcopenshell.api.run("system.add_port", self.file) + element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment") + ifcopenshell.api.run("system.assign_port", self.file, element=element1, port=port1) + + port2 = ifcopenshell.api.run("system.add_port", self.file) + element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment") + ifcopenshell.api.run("system.assign_port", self.file, element=element2, port=port2) + + ifcopenshell.api.run("system.connect_port", self.file, port1=port1, port2=port2, direction="SOURCE") + assert subject.get_connected_to(element1) == [element2] + assert subject.get_connected_from(element1) == [] + assert subject.get_connected_to(element2) == [] + assert subject.get_connected_from(element2) == [element1] + + ifcopenshell.api.run("system.connect_port", self.file, port1=port1, port2=port2, direction="SINK") + assert subject.get_connected_to(element1) == [] + assert subject.get_connected_from(element1) == [element2] + assert subject.get_connected_to(element2) == [element1] + assert subject.get_connected_from(element2) == [] + + +class TestGetConnectedToFromIFC2X3(test.bootstrap.IFC2X3): + def test_run(self): + TestGetConnectedToFrom.test_run(self)