mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 10:33:20 +00:00
Replace all ifcopenshell.api.run with ifcopenshell.api static functions.
This commit is contained in:
@@ -17,20 +17,21 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.classification
|
||||
|
||||
|
||||
class TestAddClassification(test.bootstrap.IFC4):
|
||||
def test_adding_a_classification(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.classification.add_classification(self.file, classification="Name")
|
||||
assert self.file.by_type("IfcClassification")[0].Name == "Name"
|
||||
|
||||
def test_adding_a_classification_from_a_library(self):
|
||||
library = ifcopenshell.file()
|
||||
classification = library.createIfcClassification(Name="Name")
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.run("classification.add_classification", self.file, classification=classification)
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.classification.add_classification(self.file, classification=classification)
|
||||
assert self.file.by_type("IfcClassification")[0].Name == "Name"
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.classification
|
||||
import ifcopenshell.util.classification
|
||||
|
||||
|
||||
@@ -26,12 +27,11 @@ class TestAddReference(test.bootstrap.IFC4):
|
||||
def test_adding_a_reference(self):
|
||||
is_ifc2x3 = self.file.schema == "IFC2X3"
|
||||
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
result = ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
result = ifcopenshell.api.classification.add_classification(self.file, classification="Name")
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element, element2],
|
||||
identification="X",
|
||||
@@ -64,12 +64,11 @@ class TestAddReference(test.bootstrap.IFC4):
|
||||
classification = library.createIfcClassification(Name="Name")
|
||||
reference = library.createIfcClassificationReference(Identification="1", ReferencedSource=classification)
|
||||
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
result = ifcopenshell.api.run("classification.add_classification", self.file, classification=classification)
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
result = ifcopenshell.api.classification.add_classification(self.file, classification=classification)
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element, element2],
|
||||
reference=reference,
|
||||
@@ -94,16 +93,15 @@ class TestAddReference(test.bootstrap.IFC4):
|
||||
assert len(rel.RelatedObjects) == 2
|
||||
|
||||
def test_adding_a_reference_to_a_resource_and_to_a_root(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
element = self.file.createIfcMaterial()
|
||||
element2 = self.file.createIfcCostValue()
|
||||
element3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
result = ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
||||
element3 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
result = ifcopenshell.api.classification.add_classification(self.file, classification="Name")
|
||||
|
||||
if self.file.schema == "IFC2X3":
|
||||
with pytest.raises(TypeError):
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element, element2, element3],
|
||||
identification="X",
|
||||
@@ -112,8 +110,7 @@ class TestAddReference(test.bootstrap.IFC4):
|
||||
)
|
||||
return
|
||||
else:
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element, element2, element3],
|
||||
identification="X",
|
||||
|
||||
@@ -17,46 +17,45 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.classification
|
||||
|
||||
|
||||
class TestRemoveClassification(test.bootstrap.IFC4):
|
||||
def test_removing_a_classification(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
||||
ifcopenshell.api.run("classification.remove_classification", self.file, classification=element)
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.classification.add_classification(self.file, classification="Name")
|
||||
ifcopenshell.api.classification.remove_classification(self.file, classification=element)
|
||||
assert not self.file.by_type("IfcClassification")
|
||||
|
||||
def test_removing_a_classification_and_all_of_its_references(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
result = ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
result = ifcopenshell.api.classification.add_classification(self.file, classification="Name")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element],
|
||||
identification="X",
|
||||
name="Foobar",
|
||||
classification=result,
|
||||
)
|
||||
ifcopenshell.api.run("classification.remove_classification", self.file, classification=result)
|
||||
ifcopenshell.api.classification.remove_classification(self.file, classification=result)
|
||||
assert not self.file.by_type("IfcClassification")
|
||||
assert not self.file.by_type("IfcClassificationReference")
|
||||
assert not self.file.by_type("IfcRelAssociatesClassification")
|
||||
|
||||
def test_removing_a_classification_and_all_of_its_references_when_associated_with_a_resource(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
result = ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
result = ifcopenshell.api.classification.add_classification(self.file, classification="Name")
|
||||
element = self.file.create_entity("IfcWall", Name="Wall")
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element],
|
||||
identification="X",
|
||||
name="Foobar",
|
||||
classification=result,
|
||||
)
|
||||
ifcopenshell.api.run("classification.remove_classification", self.file, classification=result)
|
||||
ifcopenshell.api.classification.remove_classification(self.file, classification=result)
|
||||
assert not self.file.by_type("IfcClassification")
|
||||
assert not self.file.by_type("IfcClassificationReference")
|
||||
if self.file.schema != "IFC2X3":
|
||||
|
||||
@@ -18,41 +18,40 @@
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.classification
|
||||
import ifcopenshell.util.classification
|
||||
|
||||
|
||||
class TestRemoveReference(test.bootstrap.IFC4):
|
||||
def test_removing_a_reference(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
result = ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
||||
reference = ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
result = ifcopenshell.api.classification.add_classification(self.file, classification="Name")
|
||||
reference = ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element, element2],
|
||||
identification="X",
|
||||
name="Foobar",
|
||||
classification=result,
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"classification.remove_reference", self.file, products=[element, element2], reference=reference
|
||||
ifcopenshell.api.classification.remove_reference(
|
||||
self.file, products=[element, element2], reference=reference
|
||||
)
|
||||
assert len(ifcopenshell.util.classification.get_references(element)) == 0
|
||||
assert len(ifcopenshell.util.classification.get_references(element2)) == 0
|
||||
assert len(self.file.by_type("IfcClassificationReference")) == 0
|
||||
|
||||
def test_removing_a_reference_from_a_resource_and_from_a_root(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
element = self.file.createIfcMaterial()
|
||||
element2 = self.file.createIfcCostValue()
|
||||
element3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
result = ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
||||
element3 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
result = ifcopenshell.api.classification.add_classification(self.file, classification="Name")
|
||||
if self.file.schema == "IFC2X3":
|
||||
with pytest.raises(TypeError):
|
||||
reference = ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
reference = ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element, element2, element3],
|
||||
identification="X",
|
||||
@@ -61,8 +60,7 @@ class TestRemoveReference(test.bootstrap.IFC4):
|
||||
)
|
||||
return
|
||||
else:
|
||||
reference = ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
reference = ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element, element2, element3],
|
||||
identification="X",
|
||||
@@ -70,8 +68,8 @@ class TestRemoveReference(test.bootstrap.IFC4):
|
||||
classification=result,
|
||||
)
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"classification.remove_reference", self.file, products=[element, element2, element3], reference=reference
|
||||
ifcopenshell.api.classification.remove_reference(
|
||||
self.file, products=[element, element2, element3], reference=reference
|
||||
)
|
||||
assert len(ifcopenshell.util.classification.get_references(element)) == 0
|
||||
assert len(ifcopenshell.util.classification.get_references(element2)) == 0
|
||||
@@ -79,13 +77,12 @@ class TestRemoveReference(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcClassificationReference")) == 0
|
||||
|
||||
def test_retaining_the_reference_if_still_in_use(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
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")
|
||||
result = ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
||||
reference = ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
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")
|
||||
result = ifcopenshell.api.classification.add_classification(self.file, classification="Name")
|
||||
reference = ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element, element2, element3],
|
||||
identification="X",
|
||||
@@ -93,11 +90,11 @@ class TestRemoveReference(test.bootstrap.IFC4):
|
||||
classification=result,
|
||||
)
|
||||
assert len(self.file.by_type("IfcClassificationReference")) == 1
|
||||
ifcopenshell.api.run(
|
||||
"classification.remove_reference", self.file, products=[element, element2], reference=reference
|
||||
ifcopenshell.api.classification.remove_reference(
|
||||
self.file, products=[element, element2], reference=reference
|
||||
)
|
||||
assert len(self.file.by_type("IfcClassificationReference")) == 1
|
||||
ifcopenshell.api.run("classification.remove_reference", self.file, products=[element3], reference=reference)
|
||||
ifcopenshell.api.classification.remove_reference(self.file, products=[element3], reference=reference)
|
||||
assert len(self.file.by_type("IfcClassificationReference")) == 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user