Run black on IOS-Python

This commit is contained in:
Dion Moult
2024-07-26 12:00:28 +10:00
parent d51fa2c5f7
commit a6286293d8
83 changed files with 603 additions and 637 deletions
@@ -36,9 +36,7 @@ class TestRemoveReference(test.bootstrap.IFC4):
name="Foobar",
classification=result,
)
ifcopenshell.api.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
@@ -90,9 +88,7 @@ class TestRemoveReference(test.bootstrap.IFC4):
classification=result,
)
assert len(self.file.by_type("IfcClassificationReference")) == 1
ifcopenshell.api.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.classification.remove_reference(self.file, products=[element3], reference=reference)
assert len(self.file.by_type("IfcClassificationReference")) == 0
@@ -27,9 +27,7 @@ class TestAssignConstraint(test.bootstrap.IFC4):
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
constraint = ifcopenshell.api.constraint.add_objective(self.file)
ifcopenshell.api.constraint.assign_constraint(
self.file, products=[element, element2], constraint=constraint
)
ifcopenshell.api.constraint.assign_constraint(self.file, products=[element, element2], constraint=constraint)
assert ifcopenshell.util.constraint.get_constrained_elements(constraint) == {element, element2}
assert len(self.file.by_type("IfcRelAssociatesConstraint")) == 1
@@ -37,13 +35,9 @@ class TestAssignConstraint(test.bootstrap.IFC4):
constraint = ifcopenshell.api.constraint.add_objective(self.file)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.constraint.assign_constraint(
self.file, products=[element, element2], constraint=constraint
)
ifcopenshell.api.constraint.assign_constraint(self.file, products=[element, element2], constraint=constraint)
total_elements = len([e for e in self.file])
ifcopenshell.api.constraint.assign_constraint(
self.file, products=[element, element2], constraint=constraint
)
ifcopenshell.api.constraint.assign_constraint(self.file, products=[element, element2], constraint=constraint)
assert len([e for e in self.file]) == total_elements
def test_that_old_relationships_are_updated_if_they_still_contain_elements(self):
@@ -54,9 +48,7 @@ class TestAssignConstraint(test.bootstrap.IFC4):
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element3 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.constraint.assign_constraint(
self.file, products=[element2, element3], constraint=constraint
)
ifcopenshell.api.constraint.assign_constraint(self.file, products=[element2, element3], constraint=constraint)
assert len(rel.RelatedObjects) == 3
@@ -27,12 +27,8 @@ class TestUnassignConstraint(test.bootstrap.IFC4):
constraint = ifcopenshell.api.constraint.add_objective(self.file)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.constraint.assign_constraint(
self.file, products=[element, element2], constraint=constraint
)
ifcopenshell.api.constraint.unassign_constraint(
self.file, products=[element, element2], constraint=constraint
)
ifcopenshell.api.constraint.assign_constraint(self.file, products=[element, element2], constraint=constraint)
ifcopenshell.api.constraint.unassign_constraint(self.file, products=[element, element2], constraint=constraint)
assert ifcopenshell.util.constraint.get_constrained_elements(element) == set()
assert len(self.file.by_type("IfcRelAssociatesConstraint")) == 0
@@ -40,9 +36,7 @@ class TestUnassignConstraint(test.bootstrap.IFC4):
constraint = ifcopenshell.api.constraint.add_objective(self.file)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.constraint.unassign_constraint(
self.file, products=[element, element2], constraint=constraint
)
ifcopenshell.api.constraint.unassign_constraint(self.file, products=[element, element2], constraint=constraint)
assert ifcopenshell.util.constraint.get_constrained_elements(element) == set()
assert ifcopenshell.util.constraint.get_constrained_elements(element2) == set()
@@ -54,12 +48,8 @@ class TestUnassignConstraint(test.bootstrap.IFC4):
ifcopenshell.api.constraint.assign_constraint(self.file, products=[element1], constraint=constraint)
rel = self.file.by_type("IfcRelAssociatesConstraint")[0]
ifcopenshell.api.constraint.assign_constraint(
self.file, products=[element2, element3], constraint=constraint
)
ifcopenshell.api.constraint.unassign_constraint(
self.file, products=[element1, element2], constraint=constraint
)
ifcopenshell.api.constraint.assign_constraint(self.file, products=[element2, element3], constraint=constraint)
ifcopenshell.api.constraint.unassign_constraint(self.file, products=[element1, element2], constraint=constraint)
assert rel.RelatedObjects == (element3,)
@@ -27,24 +27,18 @@ class TestAssignControl(test.bootstrap.IFC4):
control = ifcopenshell.api.cost.add_cost_schedule(self.file)
# simple assignment
relation = ifcopenshell.api.control.assign_control(
self.file, relating_control=control, related_object=wall
)
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_object=wall)
assert len(self.file.by_type("IfcRelAssignsToControl")) == 1
assert relation.RelatingControl == control
assert relation.RelatedObjects == (wall,)
# trying to establish existing relationship
relation = ifcopenshell.api.control.assign_control(
self.file, relating_control=control, related_object=wall
)
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_object=wall)
assert relation is None
# assigning same control to another object
wall1 = self.file.createIfcWall()
relation = ifcopenshell.api.control.assign_control(
self.file, relating_control=control, related_object=wall1
)
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_object=wall1)
assert relation is not None
assert len(self.file.by_type("IfcRelAssignsToControl")) == 1
assert relation.RelatingControl == control
@@ -27,17 +27,13 @@ class TestUnassignControl(test.bootstrap.IFC4):
control = ifcopenshell.api.cost.add_cost_schedule(self.file)
# assign and unassign
relation = ifcopenshell.api.control.assign_control(
self.file, relating_control=control, related_object=wall
)
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_object=wall)
ifcopenshell.api.control.unassign_control(self.file, relating_control=control, related_object=wall)
assert len(self.file.by_type("IfcRelAssignsToControl")) == 0
# 1 control 2 related objects
wall1 = self.file.createIfcWall()
relation = ifcopenshell.api.control.assign_control(
self.file, relating_control=control, related_object=wall
)
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_object=wall)
ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_object=wall1)
ifcopenshell.api.control.unassign_control(self.file, relating_control=control, related_object=wall1)
assert len(self.file.by_type("IfcRelAssignsToControl")) == 1
@@ -33,9 +33,7 @@ class TestAddCostItemQuantity(test.bootstrap.IFC4):
quantities = []
for quantity_type in quantity_types:
quantity = ifcopenshell.api.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"
if quantity_type == "IfcQuantityCount":
@@ -36,9 +36,7 @@ class TestUnassignDocument(test.bootstrap.IFC4):
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.document.assign_document(self.file, products=[element, element2, element3], document=reference)
ifcopenshell.api.document.unassign_document(self.file, products=[element, element2], document=reference)
assert ifcopenshell.util.element.get_referenced_elements(reference) == {element3}
@@ -30,9 +30,7 @@ class TestUnassignRepresentation(test.bootstrap.IFC4):
)
ifcopenshell.api.geometry.unassign_representation(self.file, product=wall, representation=representation)
assert representation not in wall.Representation.Representations
ifcopenshell.api.geometry.unassign_representation(
self.file, product=wall, representation=representation2
)
ifcopenshell.api.geometry.unassign_representation(self.file, product=wall, representation=representation2)
assert not wall.Representation
assert len(self.file.by_type("IfcShapeRepresentation")) == 2
assert len(self.file.by_type("IfcProductDefinitionShape")) == 0
@@ -42,9 +40,7 @@ class TestUnassignRepresentation(test.bootstrap.IFC4):
origin = self.file.createIfcAxis2Placement3D()
repmap = self.file.createIfcRepresentationMap(MappedRepresentation=representation, MappingOrigin=origin)
walltype = self.file.createIfcWallType(RepresentationMaps=[repmap])
ifcopenshell.api.geometry.unassign_representation(
self.file, product=walltype, representation=representation
)
ifcopenshell.api.geometry.unassign_representation(self.file, product=walltype, representation=representation)
assert not walltype.RepresentationMaps
assert len(self.file.by_type("IfcAxis2Placement3D")) == 0
assert len(self.file.by_type("IfcRepresentationMap")) == 0
@@ -59,9 +55,7 @@ class TestUnassignRepresentation(test.bootstrap.IFC4):
rep = self.file.createIfcShapeRepresentation(Items=[mapped_item])
prodrep = self.file.createIfcProductDefinitionShape(Representations=[rep])
wall = self.file.createIfcWall(Representation=prodrep)
ifcopenshell.api.geometry.unassign_representation(
self.file, product=walltype, representation=representation
)
ifcopenshell.api.geometry.unassign_representation(self.file, product=walltype, representation=representation)
assert not walltype.RepresentationMaps
assert len(self.file.by_type("IfcAxis2Placement3D")) == 0
assert len(self.file.by_type("IfcRepresentationMap")) == 0
@@ -33,5 +33,6 @@ class TestUnassignReference(test.bootstrap.IFC4):
assert ifcopenshell.util.element.get_referenced_elements(reference) == set()
assert len(self.file.by_type("IfcRelAssociatesLibrary")) == 0
class TestUnassignReferenceIFC2X3(test.bootstrap.IFC2X3, TestUnassignReference):
pass
@@ -111,9 +111,7 @@ class TestRemoveMaterialIFC4(test.bootstrap.IFC4, TestRemoveMaterialIFC2X3):
def test_removing_material_in_constituent(self):
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
material = ifcopenshell.api.material.add_material(self.file)
material_set = ifcopenshell.api.material.add_material_set(
self.file, set_type="IfcMaterialConstituentSet"
)
material_set = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialConstituentSet")
ifcopenshell.api.material.add_constituent(self.file, constituent_set=material_set, material=material)
ifcopenshell.api.material.assign_material(self.file, products=[wall], material=material_set)
assert len(self.file.by_type("IfcMaterialConstituentSet")[0].MaterialConstituents) == 1
@@ -79,9 +79,7 @@ class TestAssignObject(test.bootstrap.IFC4):
# maintain the order in the affected relationships too
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcTask")
ifcopenshell.api.nest.assign_object(
self.file, related_objects=subelements[2:3], relating_object=element2
)
ifcopenshell.api.nest.assign_object(self.file, related_objects=subelements[2:3], relating_object=element2)
assert rel.RelatedObjects == tuple(subelements[:2] + subelements[3:])
@@ -24,9 +24,7 @@ class TestAddPersonAndOrganisation(test.bootstrap.IFC4):
def test_adding(self):
person = self.file.createIfcPerson()
organisation = self.file.createIfcOrganization()
ifcopenshell.api.owner.add_person_and_organisation(
self.file, person=person, organisation=organisation
)
ifcopenshell.api.owner.add_person_and_organisation(self.file, person=person, organisation=organisation)
class TestAddPersonAndOrganisationIFC2X3(test.bootstrap.IFC2X3, TestAddPersonAndOrganisation):
@@ -57,9 +57,7 @@ class TestAssignDeclaration(test.bootstrap.IFC4):
def test_that_old_relationships_are_updated_if_they_still_contain_elements(self):
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
library = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProjectLibrary")
ifcopenshell.api.project.assign_declaration(
self.file, definitions=[element_type], relating_context=library
)
ifcopenshell.api.project.assign_declaration(self.file, definitions=[element_type], relating_context=library)
rel = self.file.by_type("IfcRelDeclares")[0]
element_type2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
@@ -61,9 +61,7 @@ class TestUnassignDeclaration(test.bootstrap.IFC4):
element_type1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
element_type2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
element_type3 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
ifcopenshell.api.project.assign_declaration(
self.file, definitions=[element_type1], relating_context=library
)
ifcopenshell.api.project.assign_declaration(self.file, definitions=[element_type1], relating_context=library)
rel = self.file.by_type("IfcRelDeclares")[0]
ifcopenshell.api.project.assign_declaration(
@@ -183,9 +183,7 @@ class TestEditPset(test.bootstrap.IFC4):
assert pset.HasProperties[0].NominalValue.wrappedValue == 34
def test_editing_list_valued_properties(self):
cable = ifcopenshell.api.root.create_entity(
self.file, ifc_class="IfcDistributionPort", predefined_type="CABLE"
)
cable = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcDistributionPort", predefined_type="CABLE")
pset = ifcopenshell.api.pset.add_pset(self.file, product=cable, name="Pset_DistributionPortTypeCable")
ifcopenshell.api.pset.edit_pset(
self.file,
@@ -29,9 +29,7 @@ class TestEditPropTemplate(test.bootstrap.IFC4):
prop_template=prop,
attributes={"Name": "DemoA", "PrimaryMeasureType": "IfcLabel"},
)
ifcopenshell.api.pset_template.edit_prop_template(
self.file, prop_template=prop, attributes={"Name": "DemoB"}
)
ifcopenshell.api.pset_template.edit_prop_template(self.file, prop_template=prop, attributes={"Name": "DemoB"})
assert prop.Name == "DemoB"
def test_editing_an_enumeration(self):
@@ -62,9 +62,7 @@ class TestReassignClass(test.bootstrap.IFC4):
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.type.assign_type(self.file, related_objects=[element2], relating_type=element_type)
element_type = ifcopenshell.api.root.reassign_class(
self.file, product=element_type, ifc_class="IfcSlabType"
)
element_type = ifcopenshell.api.root.reassign_class(self.file, product=element_type, ifc_class="IfcSlabType")
# type occurrences have reassigned classes
occurrences = ifcopenshell.util.element.get_types(element_type)
@@ -93,12 +93,8 @@ class TestAssignContainer(test.bootstrap.IFC4):
(0.0, 0.0, 0.0, 1.0),
)
)
ifcopenshell.api.geometry.edit_object_placement(
self.file, product=element1, matrix=matrix1.copy(), is_si=False
)
ifcopenshell.api.geometry.edit_object_placement(
self.file, product=element2, matrix=matrix2.copy(), is_si=False
)
ifcopenshell.api.geometry.edit_object_placement(self.file, product=element1, matrix=matrix1.copy(), is_si=False)
ifcopenshell.api.geometry.edit_object_placement(self.file, product=element2, matrix=matrix2.copy(), is_si=False)
ifcopenshell.api.geometry.edit_object_placement(
self.file, product=subelement, matrix=matrix1.copy(), is_si=False
)
@@ -51,9 +51,7 @@ class TestDereferenceStructure(test.bootstrap.IFC4):
subelement1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
subelement2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
subelement3 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.spatial.reference_structure(
self.file, products=[subelement1], relating_structure=element
)
ifcopenshell.api.spatial.reference_structure(self.file, products=[subelement1], relating_structure=element)
ifcopenshell.api.spatial.reference_structure(
self.file, products=[subelement2, subelement3], relating_structure=element
)
@@ -82,9 +82,7 @@ class TestAssignMaterialStyleIFC4(test.bootstrap.IFC4, TestAssignMaterialStyleIF
style = self.file.createIfcSurfaceStyle()
material = ifcopenshell.api.material.add_material(self.file)
material_set = ifcopenshell.api.material.add_material_set(
self.file, set_type="IfcMaterialConstituentSet"
)
material_set = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialConstituentSet")
constituent = ifcopenshell.api.material.add_constituent(
self.file, constituent_set=material_set, material=material
)
@@ -61,9 +61,7 @@ class TestAssignPort(test.bootstrap.IFC4):
(0.0, 0.0, 0.0, 1.0),
)
)
ifcopenshell.api.geometry.edit_object_placement(
self.file, product=element, matrix=matrix.copy(), is_si=False
)
ifcopenshell.api.geometry.edit_object_placement(self.file, product=element, matrix=matrix.copy(), is_si=False)
ifcopenshell.api.geometry.edit_object_placement(
self.file, product=subelement, matrix=submatrix.copy(), is_si=False
)
@@ -51,9 +51,7 @@ class TestAssignType(test.bootstrap.IFC4):
element_type2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.type.assign_type(
self.file, related_objects=[element1, element2], relating_type=element_type1
)
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1, element2], relating_type=element_type1)
rel = element1.IsDefinedBy[0] if self.file.schema == "IFC2X3" else element1.IsTypedBy[0]
assert len(rel.RelatedObjects) == 2
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1], relating_type=element_type2)
@@ -110,9 +108,7 @@ class TestAssignType(test.bootstrap.IFC4):
mapped_rep_id = mapped_rep.id()
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.type.assign_type(
self.file, related_objects=[element1, element2], relating_type=element_type
)
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1, element2], relating_type=element_type)
assert (mapped_rep := ifcopenshell.util.representation.get_representation(element1, context=context))
assert mapped_rep.id() == mapped_rep_id
@@ -139,9 +135,7 @@ class TestAssignType(test.bootstrap.IFC4):
# use 2 elements to trigger material assignment code block
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.type.assign_type(
self.file, related_objects=[element1, element2], relating_type=element_type
)
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1, element2], relating_type=element_type)
assert (material := ifcopenshell.util.element.get_material(element1))
assert material.id() == material_id
@@ -29,9 +29,7 @@ class TestUnassignType(test.bootstrap.IFC4):
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.type.assign_type(
self.file, related_objects=[element1, element2], relating_type=element_type
)
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1, element2], relating_type=element_type)
ifcopenshell.api.type.unassign_type(self.file, related_objects=[element1, element2])
assert ifcopenshell.util.element.get_type(element1) is None
assert ifcopenshell.util.element.get_type(element2) is None
@@ -61,12 +61,8 @@ class TestAddOpening(test.bootstrap.IFC4):
(0.0, 0.0, 0.0, 1.0),
)
)
ifcopenshell.api.geometry.edit_object_placement(
self.file, product=wall, matrix=matrix1.copy(), is_si=False
)
ifcopenshell.api.geometry.edit_object_placement(
self.file, product=opening, matrix=matrix1.copy(), is_si=False
)
ifcopenshell.api.geometry.edit_object_placement(self.file, product=wall, matrix=matrix1.copy(), is_si=False)
ifcopenshell.api.geometry.edit_object_placement(self.file, product=opening, matrix=matrix1.copy(), is_si=False)
ifcopenshell.api.void.add_opening(self.file, opening=opening, element=wall)
assert opening.ObjectPlacement.PlacementRelTo.PlacesObject[0] == wall
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(opening.ObjectPlacement), matrix1)