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,19 +17,19 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.document
class TestAddInformation(test.bootstrap.IFC4):
def test_adding_information(self):
project = self.file.createIfcProject()
element = ifcopenshell.api.run("document.add_information", self.file, parent=None)
element = ifcopenshell.api.document.add_information(self.file, parent=None)
assert element.is_a("IfcDocumentInformation")
assert len(self.file.by_type("IfcDocumentInformation")) == 1
def test_adding_information_to_the_project(self):
project = self.file.createIfcProject()
element = ifcopenshell.api.run("document.add_information", self.file, parent=None)
element = ifcopenshell.api.document.add_information(self.file, parent=None)
rel = self.file.by_type("IfcRelAssociatesDocument")[0]
assert rel.is_a("IfcRelAssociatesDocument")
assert rel.RelatingDocument == element
@@ -37,13 +37,13 @@ class TestAddInformation(test.bootstrap.IFC4):
def test_adding_a_subdocument(self):
project = self.file.createIfcProject()
parent = ifcopenshell.api.run("document.add_information", self.file, parent=None)
element = ifcopenshell.api.run("document.add_information", self.file, parent=parent)
parent = ifcopenshell.api.document.add_information(self.file, parent=None)
element = ifcopenshell.api.document.add_information(self.file, parent=parent)
assert element.is_a("IfcDocumentInformation")
assert len(self.file.by_type("IfcDocumentInformation")) == 2
assert element.IsPointedTo[0].RelatingDocument == parent
assert parent.IsPointer[0].RelatedDocuments[0] == element
element2 = ifcopenshell.api.run("document.add_information", self.file, parent=parent)
element2 = ifcopenshell.api.document.add_information(self.file, parent=parent)
assert element in parent.IsPointer[0].RelatedDocuments
assert element2 in parent.IsPointer[0].RelatedDocuments
@@ -17,19 +17,19 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.document
class TestAddReference(test.bootstrap.IFC4):
def test_adding_a_reference(self):
element = ifcopenshell.api.run("document.add_reference", self.file, information=None)
element = ifcopenshell.api.document.add_reference(self.file, information=None)
assert element.is_a("IfcDocumentReference")
assert len(self.file.by_type("IfcDocumentReference")) == 1
def test_adding_a_reference_to_an_information(self):
self.file.createIfcProject()
information = ifcopenshell.api.run("document.add_information", self.file, parent=None)
element = ifcopenshell.api.run("document.add_reference", self.file, information=information)
information = ifcopenshell.api.document.add_information(self.file, parent=None)
element = ifcopenshell.api.document.add_reference(self.file, information=information)
assert element.is_a("IfcDocumentReference")
assert len(self.file.by_type("IfcDocumentReference")) == 1
ifc2x3 = self.file.schema == "IFC2X3"
@@ -17,23 +17,24 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.api.document
import ifcopenshell.util.element
class TestAssignDocument(test.bootstrap.IFC4):
def test_assigning_a_document(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
reference = ifcopenshell.api.run("document.add_reference", self.file, information=None)
ifcopenshell.api.run("document.assign_document", self.file, products=[element], document=reference)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
reference = ifcopenshell.api.document.add_reference(self.file, information=None)
ifcopenshell.api.document.assign_document(self.file, products=[element], document=reference)
assert element.HasAssociations[0].RelatingDocument == reference
assert ifcopenshell.util.element.get_referenced_elements(reference) == {element}
def test_assigning_multiple_documents(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")
reference = ifcopenshell.api.run("document.add_reference", self.file, information=None)
ifcopenshell.api.run("document.assign_document", self.file, products=[element, element2], document=reference)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
reference = ifcopenshell.api.document.add_reference(self.file, information=None)
ifcopenshell.api.document.assign_document(self.file, products=[element, element2], document=reference)
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 1
assert ifcopenshell.util.element.get_referenced_elements(reference) == {element, element2}
@@ -17,45 +17,45 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.document
class TestRemoveInformation(test.bootstrap.IFC4):
def test_remove_information(self):
self.file.createIfcProject()
element = ifcopenshell.api.run("document.add_information", self.file, parent=None)
ifcopenshell.api.run("document.remove_information", self.file, information=element)
element = ifcopenshell.api.document.add_information(self.file, parent=None)
ifcopenshell.api.document.remove_information(self.file, information=element)
assert len(self.file.by_type("IfcDocumentInformation")) == 0
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 0
def test_removing_all_references_of_an_information(self):
self.file.createIfcProject()
information = ifcopenshell.api.run("document.add_information", self.file, parent=None)
ifcopenshell.api.run("document.add_reference", self.file, information=information)
ifcopenshell.api.run("document.remove_information", self.file, information=information)
information = ifcopenshell.api.document.add_information(self.file, parent=None)
ifcopenshell.api.document.add_reference(self.file, information=information)
ifcopenshell.api.document.remove_information(self.file, information=information)
assert len(self.file.by_type("IfcDocumentInformation")) == 0
assert len(self.file.by_type("IfcDocumentReference")) == 0
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 0
# test removing relationship to another information if it was the only relating element
information = ifcopenshell.api.run("document.add_information", self.file, parent=None)
information1 = ifcopenshell.api.run("document.add_information", self.file, parent=information)
information2 = ifcopenshell.api.run("document.add_information", self.file, parent=information)
information = ifcopenshell.api.document.add_information(self.file, parent=None)
information1 = ifcopenshell.api.document.add_information(self.file, parent=information)
information2 = ifcopenshell.api.document.add_information(self.file, parent=information)
ifcopenshell.api.run("document.remove_information", self.file, information=information1)
ifcopenshell.api.document.remove_information(self.file, information=information1)
assert len(self.file.by_type("IfcDocumentInformation")) == 2
assert len(self.file.by_type("IfcDocumentInformationRelationship")) == 1
ifcopenshell.api.run("document.remove_information", self.file, information=information2)
ifcopenshell.api.document.remove_information(self.file, information=information2)
assert len(self.file.by_type("IfcDocumentInformation")) == 1
assert len(self.file.by_type("IfcDocumentInformationRelationship")) == 0
def test_removing_all_subdocuments_and_their_references_too(self):
self.file.createIfcProject()
information = ifcopenshell.api.run("document.add_information", self.file, parent=None)
information2 = ifcopenshell.api.run("document.add_information", self.file, parent=information)
ifcopenshell.api.run("document.add_reference", self.file, information=information2)
ifcopenshell.api.run("document.remove_information", self.file, information=information)
information = ifcopenshell.api.document.add_information(self.file, parent=None)
information2 = ifcopenshell.api.document.add_information(self.file, parent=information)
ifcopenshell.api.document.add_reference(self.file, information=information2)
ifcopenshell.api.document.remove_information(self.file, information=information)
assert len(self.file.by_type("IfcDocumentInformation")) == 0
assert len(self.file.by_type("IfcDocumentReference")) == 0
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 0
@@ -17,15 +17,15 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.document
class TestRemoveReference(test.bootstrap.IFC4):
def test_removing_reference(self):
project = self.file.createIfcProject()
information = ifcopenshell.api.run("document.add_information", self.file, parent=None)
reference = ifcopenshell.api.run("document.add_reference", self.file, information=information)
ifcopenshell.api.run("document.remove_reference", self.file, reference=reference)
information = ifcopenshell.api.document.add_information(self.file, parent=None)
reference = ifcopenshell.api.document.add_reference(self.file, information=information)
ifcopenshell.api.document.remove_reference(self.file, reference=reference)
assert len(self.file.by_type("IfcDocumentReference")) == 0
assert len(self.file.by_type("IfcDocumentInformation")) == 1
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 1
@@ -33,11 +33,11 @@ class TestRemoveReference(test.bootstrap.IFC4):
def test_removing_a_reference_assigned_to_an_object(self):
project = self.file.createIfcProject()
wall = self.file.createIfcWall()
information = ifcopenshell.api.run("document.add_information", self.file, parent=None)
reference = ifcopenshell.api.run("document.add_reference", self.file, information=information)
ifcopenshell.api.run("document.assign_document", self.file, products=[wall], document=reference)
information = ifcopenshell.api.document.add_information(self.file, parent=None)
reference = ifcopenshell.api.document.add_reference(self.file, information=information)
ifcopenshell.api.document.assign_document(self.file, products=[wall], document=reference)
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 2
ifcopenshell.api.run("document.remove_reference", self.file, reference=reference)
ifcopenshell.api.document.remove_reference(self.file, reference=reference)
assert len(self.file.by_type("IfcDocumentReference")) == 0
assert len(self.file.by_type("IfcDocumentInformation")) == 1
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 1
@@ -17,28 +17,29 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.api.document
import ifcopenshell.util.element
class TestUnassignDocument(test.bootstrap.IFC4):
def test_unassigning_a_document(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
reference = ifcopenshell.api.run("document.add_reference", self.file, information=None)
ifcopenshell.api.run("document.assign_document", self.file, products=[element], document=reference)
ifcopenshell.api.run("document.unassign_document", self.file, products=[element], document=reference)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
reference = ifcopenshell.api.document.add_reference(self.file, information=None)
ifcopenshell.api.document.assign_document(self.file, products=[element], document=reference)
ifcopenshell.api.document.unassign_document(self.file, products=[element], document=reference)
assert not element.HasAssociations
assert not len(self.file.by_type("IfcRelAssociatesDocument"))
def test_unassigning_a_document_used_by_multiple_entities(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")
reference = ifcopenshell.api.run("document.add_reference", self.file, information=None)
ifcopenshell.api.run(
"document.assign_document", self.file, products=[element, element2, element3], document=reference
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")
reference = ifcopenshell.api.document.add_reference(self.file, information=None)
ifcopenshell.api.document.assign_document(
self.file, products=[element, element2, element3], document=reference
)
ifcopenshell.api.run("document.unassign_document", self.file, products=[element, element2], document=reference)
ifcopenshell.api.document.unassign_document(self.file, products=[element, element2], document=reference)
assert ifcopenshell.util.element.get_referenced_elements(reference) == {element3}