From a6286293d8c6417185c248e1c6d77e80e1f88cc7 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 26 Jul 2024 12:00:28 +1000 Subject: [PATCH] Run black on IOS-Python --- pyproject.toml | 1 + src/ifcopenshell-python/docs/conf.py | 12 +- .../ifcopenshell/api/cost/add_cost_item.py | 4 +- .../ifcopenshell/api/geometry/__init__.py | 3 + .../api/geometry/add_representation.py | 12 +- .../api/georeference/edit_true_north.py | 2 +- .../ifcopenshell/api/grid/__init__.py | 1 + .../ifcopenshell/api/material/add_material.py | 11 +- .../api/material/assign_profile.py | 1 + .../api/material/edit_assigned_material.py | 4 +- .../ifcopenshell/api/owner/add_role.py | 4 +- .../api/owner/edit_organisation.py | 4 +- .../ifcopenshell/api/pset/add_pset.py | 8 +- .../api/pset_template/edit_prop_template.py | 4 +- .../structural/add_structural_load_case.py | 5 +- .../ifcopenshell/entity_instance.py | 33 +++-- .../ifcopenshell/geom/app.py | 3 - src/ifcopenshell-python/ifcopenshell/guid.py | 2 +- .../ifcopenshell/settings.py | 2 +- .../ifcopenshell/stream.py | 126 +++++++++--------- .../ifcopenshell/transition_curve.py | 28 ++-- .../util/ifc4x3dev_scrape_data_for_docs.py | 2 + .../ifcopenshell/util/sequence.py | 69 +++------- .../classification/test_remove_reference.py | 8 +- .../api/constraint/test_assign_constraint.py | 16 +-- .../constraint/test_unassign_constraint.py | 20 +-- .../test/api/control/test_assign_control.py | 12 +- .../test/api/control/test_unassign_control.py | 8 +- .../api/cost/test_add_cost_item_quantity.py | 4 +- .../api/document/test_unassign_document.py | 4 +- .../geometry/test_unassign_representation.py | 12 +- .../api/library/test_unassign_reference.py | 1 + .../test/api/material/test_remove_material.py | 4 +- .../test/api/nest/test_assign_object.py | 4 +- .../owner/test_add_person_and_organisation.py | 4 +- .../api/project/test_assign_declaration.py | 4 +- .../api/project/test_unassign_declaration.py | 4 +- .../test/api/pset/test_edit_pset.py | 4 +- .../pset_template/test_edit_prop_template.py | 4 +- .../test/api/root/test_reassign_class.py | 4 +- .../test/api/spatial/test_assign_container.py | 8 +- .../api/spatial/test_dereference_structure.py | 4 +- .../api/style/test_assign_material_style.py | 4 +- .../test/api/system/test_assign_port.py | 4 +- .../test/api/type/test_assign_type.py | 12 +- .../test/api/type/test_unassign_type.py | 4 +- .../test/api/void/test_add_opening.py | 8 +- .../test/fixtures/rules/generate_00.py | 40 +++--- .../test/fixtures/rules/generate_01.py | 11 +- .../test/fixtures/rules/generate_02.py | 21 ++- .../test/fixtures/rules/generate_03.py | 15 +-- .../test/fixtures/rules/generate_04.py | 6 +- .../test/fixtures/rules/generate_05.py | 18 ++- .../test/fixtures/rules/generate_06.py | 6 +- .../test/fixtures/rules/generate_07.py | 14 +- .../test/fixtures/rules/generate_08.py | 6 +- .../test/fixtures/rules/generate_09.py | 22 ++- .../test/fixtures/rules/generate_10.py | 8 +- .../test/fixtures/rules/generate_11.py | 25 ++-- .../test/fixtures/rules/generate_12.py | 30 ++--- .../test/fixtures/rules/generate_13.py | 52 ++++---- .../test/fixtures/rules/generate_14.py | 23 ++-- .../test/fixtures/rules/generate_15.py | 113 ++++++++-------- .../test/fixtures/rules/generate_16.py | 14 +- .../test/fixtures/rules/generate_17.py | 14 +- .../test/fixtures/rules/generate_18.py | 10 +- .../test/fixtures/rules/generate_19.py | 14 +- .../test/fixtures/rules/generate_20.py | 6 +- .../test/fixtures/rules/generate_21.py | 27 +++- .../test/fixtures/rules/generate_22.py | 49 +++++-- .../test/fixtures/rules/generate_23.py | 10 +- .../test/fixtures/rules/generate_24.py | 61 ++++++--- .../test/fixtures/rules/generate_25.py | 12 +- .../test/global_id_updates.py | 7 +- .../test/instance_string_formatting.py | 8 +- .../test/test_file_inverse.py | 10 +- src/ifcopenshell-python/test/test_open.py | 16 +-- src/ifcopenshell-python/test/test_rules.py | 21 +-- .../test/test_wall_opening.py | 6 +- .../test/util/test_element.py | 28 +--- .../test/util/test_pset.py | 2 +- .../test/util/test_selector.py | 8 +- .../test/util/test_unit.py | 5 +- 83 files changed, 603 insertions(+), 637 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 518164504f..c31d922077 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,6 @@ [tool.black] line-length = 120 +extend-exclude = 'src/ifcopenshell-python/ifcopenshell/express/*' [tool.pyright] reportInvalidTypeForm = false diff --git a/src/ifcopenshell-python/docs/conf.py b/src/ifcopenshell-python/docs/conf.py index 7a31cbb0e2..bfdb4219cc 100644 --- a/src/ifcopenshell-python/docs/conf.py +++ b/src/ifcopenshell-python/docs/conf.py @@ -81,13 +81,21 @@ autoapi_add_toctree_entry = True autoapi_type = "python" # autoapi works by reading source code instead of importing modules -autoapi_dirs = ['../ifcopenshell', '../../bcf/bcf', '../../bsdd', '../../ifccsv', '../../ifcdiff', '../../ifcpatch/ifcpatch', '../../ifctester/ifctester'] +autoapi_dirs = [ + "../ifcopenshell", + "../../bcf/bcf", + "../../bsdd", + "../../ifccsv", + "../../ifcdiff", + "../../ifcpatch/ifcpatch", + "../../ifctester/ifctester", +] # autoapi_dirs = ['../../ifcdiff'] # autoapi_dirs = ['../../ifcdiff', '../ifcopenshell/util'] # autoapi_dirs = ['../../bcf/bcf', '../../bsdd', '../../ifccsv', '../../ifcdiff', '../../ifcpatch/ifcpatch', '../../ifctester/ifctester'] # These are auto-generated based on the IFC schema, so exclude them -autoapi_ignore = ['*ifcopenshell/express/rules*'] +autoapi_ignore = ["*ifcopenshell/express/rules*"] # Custom autoapi templates to make it easier to read our docs autoapi_template_dir = "_autoapi_templates" diff --git a/src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_item.py b/src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_item.py index 444f42a589..9008aa99b2 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_item.py +++ b/src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_item.py @@ -74,7 +74,5 @@ def add_cost_item( }, ) elif settings["cost_item"]: - ifcopenshell.api.nest.assign_object( - file, related_objects=[cost_item], relating_object=settings["cost_item"] - ) + ifcopenshell.api.nest.assign_object(file, related_objects=[cost_item], relating_object=settings["cost_item"]) return cost_item diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/__init__.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/__init__.py index 3e99728f37..87bc9e607d 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/__init__.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/__init__.py @@ -26,6 +26,7 @@ geometry extrusions). from .. import wrap_usecases from .add_axis_representation import add_axis_representation from .add_boolean import add_boolean + try: from .add_door_representation import add_door_representation except ModuleNotFoundError as e: @@ -33,6 +34,7 @@ except ModuleNotFoundError as e: from .add_footprint_representation import add_footprint_representation from .add_mesh_representation import add_mesh_representation from .add_profile_representation import add_profile_representation + try: from .add_railing_representation import add_railing_representation except ModuleNotFoundError as e: @@ -44,6 +46,7 @@ except ModuleNotFoundError as e: print(f"Note: API not available due to missing dependencies: geometry.add_representation - {e}") from .add_slab_representation import add_slab_representation from .add_wall_representation import add_wall_representation + try: from .add_window_representation import add_window_representation except ModuleNotFoundError as e: diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_representation.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_representation.py index d3b12fa261..a06deca887 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_representation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_representation.py @@ -857,13 +857,19 @@ class Usecase: z = self.convert_si_to_unit(z) return self.file.createIfcCartesianPoint((x, y, z)) - def create_cartesian_point_list_from_vertices(self, vertices: list[bpy.types.MeshVertex], is_2d=False, is_model_coords=True): + def create_cartesian_point_list_from_vertices( + self, vertices: list[bpy.types.MeshVertex], is_2d=False, is_model_coords=True + ): if is_model_coords and self.settings["coordinate_offset"]: if is_2d: xy_offset = Vector((self.settings["coordinate_offset"][0:2])) - return self.file.createIfcCartesianPointList2D([self.convert_si_to_unit(v.co.xy + xy_offset) for v in vertices]) + return self.file.createIfcCartesianPointList2D( + [self.convert_si_to_unit(v.co.xy + xy_offset) for v in vertices] + ) xyz_offset = Vector((self.settings["coordinate_offset"][0:3])) - return self.file.createIfcCartesianPointList3D([self.convert_si_to_unit(v.co.xyz + xyz_offset) for v in vertices]) + return self.file.createIfcCartesianPointList3D( + [self.convert_si_to_unit(v.co.xyz + xyz_offset) for v in vertices] + ) if is_2d: return self.file.createIfcCartesianPointList2D([self.convert_si_to_unit(v.co.xy) for v in vertices]) return self.file.createIfcCartesianPointList3D([self.convert_si_to_unit(v.co) for v in vertices]) diff --git a/src/ifcopenshell-python/ifcopenshell/api/georeference/edit_true_north.py b/src/ifcopenshell-python/ifcopenshell/api/georeference/edit_true_north.py index acffecb063..d4da8ecc3c 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/georeference/edit_true_north.py +++ b/src/ifcopenshell-python/ifcopenshell/api/georeference/edit_true_north.py @@ -57,7 +57,7 @@ def edit_true_north(file: ifcopenshell.file, true_north: Optional[Union[tuple[fl for context in file.by_type("IfcGeometricRepresentationContext", include_subtypes=False): if context.TrueNorth and true_north is None: - old_true_north = context.TrueNorth + old_true_north = context.TrueNorth context.TrueNorth = None if not file.get_total_inverses(old_true_north): ifcopenshell.util.element.remove_deep2(file, old_true_north) diff --git a/src/ifcopenshell-python/ifcopenshell/api/grid/__init__.py b/src/ifcopenshell-python/ifcopenshell/api/grid/__init__.py index 3b01281460..5cd7199e63 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/grid/__init__.py +++ b/src/ifcopenshell-python/ifcopenshell/api/grid/__init__.py @@ -22,6 +22,7 @@ A grid in IFC may contain two or more axes running in two or more directions. """ from .. import wrap_usecases + try: from .create_axis_curve import create_axis_curve except ModuleNotFoundError as e: diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/add_material.py b/src/ifcopenshell-python/ifcopenshell/api/material/add_material.py index c18b54fbad..d938c75380 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/add_material.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/add_material.py @@ -20,7 +20,10 @@ from typing import Optional def add_material( - file: ifcopenshell.file, name: Optional[str] = None, category: Optional[str] = None, description: Optional[str] = None + file: ifcopenshell.file, + name: Optional[str] = None, + category: Optional[str] = None, + description: Optional[str] = None, ) -> ifcopenshell.entity_instance: """Adds a new material @@ -50,8 +53,8 @@ def add_material( Note that categories are not available in IFC2X3. This shortcoming is one of the big reasons projects should upgrade to IFC4. - Additionally, a material's description provides more information beyond - its name or category. + Additionally, a material's description provides more information beyond + its name or category. :param name: The name of the material, typically tagged in a finishes drawing or schedule. @@ -78,7 +81,7 @@ def add_material( # "Style" has been specified. ifcopenshell.api.material.assign_material(model, products=[concrete_bench], material=concrete) """ - settings = {"name": name or "Unnamed", "category": category, "description": description } + settings = {"name": name or "Unnamed", "category": category, "description": description} material = file.create_entity("IfcMaterial", **{"Name": settings["name"] or "Unnamed"}) if settings["category"]: diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/assign_profile.py b/src/ifcopenshell-python/ifcopenshell/api/material/assign_profile.py index 4d478d421a..7719fd86c8 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/assign_profile.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/assign_profile.py @@ -97,6 +97,7 @@ def assign_profile( class Usecase: file: ifcopenshell.file + def execute(self) -> None: # TODO: handle composite profiles old_profile = self.settings["material_profile"].Profile diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/edit_assigned_material.py b/src/ifcopenshell-python/ifcopenshell/api/material/edit_assigned_material.py index bd4ac85b7d..939e995a06 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/edit_assigned_material.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/edit_assigned_material.py @@ -19,7 +19,9 @@ import ifcopenshell from typing import Any -def edit_assigned_material(file: ifcopenshell.file, element: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None: +def edit_assigned_material( + file: ifcopenshell.file, element: ifcopenshell.entity_instance, attributes: dict[str, Any] +) -> None: """Edits the attributes of an IfcMaterial For more information about the attributes and data types of an diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/add_role.py b/src/ifcopenshell-python/ifcopenshell/api/owner/add_role.py index f627a07146..7105e5e78d 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/owner/add_role.py +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/add_role.py @@ -18,7 +18,9 @@ import ifcopenshell -def add_role(file: ifcopenshell.file, assigned_object: ifcopenshell.entity_instance, role: str = "ARCHITECT") -> ifcopenshell.entity_instance: +def add_role( + file: ifcopenshell.file, assigned_object: ifcopenshell.entity_instance, role: str = "ARCHITECT" +) -> ifcopenshell.entity_instance: """Adds and assigns a new role People and organisations must play one or more roles on a project. Roles diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/edit_organisation.py b/src/ifcopenshell-python/ifcopenshell/api/owner/edit_organisation.py index 5e92a31e04..9cfbfff48d 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/owner/edit_organisation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/edit_organisation.py @@ -19,7 +19,9 @@ import ifcopenshell from typing import Any -def edit_organisation(file: ifcopenshell.file, organisation: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None: +def edit_organisation( + file: ifcopenshell.file, organisation: ifcopenshell.entity_instance, attributes: dict[str, Any] +) -> None: """Edits the attributes of an IfcOrganization For more information about the attributes and data types of an diff --git a/src/ifcopenshell-python/ifcopenshell/api/pset/add_pset.py b/src/ifcopenshell-python/ifcopenshell/api/pset/add_pset.py index 1d4f650029..776c611e78 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/pset/add_pset.py +++ b/src/ifcopenshell-python/ifcopenshell/api/pset/add_pset.py @@ -95,7 +95,7 @@ def add_pset(file: ifcopenshell.file, product: ifcopenshell.entity_instance, nam "GlobalId": ifcopenshell.guid.new(), "OwnerHistory": ifcopenshell.api.owner.create_owner_history(file), "Name": settings["name"], - } + }, ) file.create_entity( "IfcRelDefinesByProperties", @@ -104,7 +104,7 @@ def add_pset(file: ifcopenshell.file, product: ifcopenshell.entity_instance, nam "OwnerHistory": ifcopenshell.api.owner.create_owner_history(file), "RelatedObjects": [settings["product"]], "RelatingPropertyDefinition": pset, - } + }, ) return pset elif settings["product"].is_a("IfcTypeObject"): @@ -118,7 +118,7 @@ def add_pset(file: ifcopenshell.file, product: ifcopenshell.entity_instance, nam "GlobalId": ifcopenshell.guid.new(), "OwnerHistory": ifcopenshell.api.owner.create_owner_history(file), "Name": settings["name"], - } + }, ) has_property_sets = list(settings["product"].HasPropertySets or []) has_property_sets.append(pset) @@ -142,7 +142,7 @@ def add_pset(file: ifcopenshell.file, product: ifcopenshell.entity_instance, nam **{ "Name": settings["name"], "Material": settings["product"], - } + }, ) elif settings["product"].is_a("IfcProfileDef"): # in IFC2X3 IfcProfileProperties doesn't have Name and we cannot identify them diff --git a/src/ifcopenshell-python/ifcopenshell/api/pset_template/edit_prop_template.py b/src/ifcopenshell-python/ifcopenshell/api/pset_template/edit_prop_template.py index e5429b948c..1984506c30 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/pset_template/edit_prop_template.py +++ b/src/ifcopenshell-python/ifcopenshell/api/pset_template/edit_prop_template.py @@ -50,7 +50,9 @@ def edit_prop_template( if enum_values := attributes.get("Enumerators", None): prop_name = attributes.get("Name", None) or getattr(prop_template, "Name", None) or "Unnamed" primary_measure_type = ( - attributes.get("PrimaryMeasureType", None) or getattr(prop_template, "PrimaryMeasureType", None) or "IfcLabel" + attributes.get("PrimaryMeasureType", None) + or getattr(prop_template, "PrimaryMeasureType", None) + or "IfcLabel" ) enum_values = [file.create_entity(primary_measure_type, v) for v in enum_values] if enumerators := prop_template.Enumerators: diff --git a/src/ifcopenshell-python/ifcopenshell/api/structural/add_structural_load_case.py b/src/ifcopenshell-python/ifcopenshell/api/structural/add_structural_load_case.py index d8823a11f1..56022446ec 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/structural/add_structural_load_case.py +++ b/src/ifcopenshell-python/ifcopenshell/api/structural/add_structural_load_case.py @@ -38,10 +38,7 @@ def add_structural_load_case( """ load_case = ifcopenshell.api.root.create_entity( - file, - ifc_class="IfcStructuralLoadCase", - predefined_type="LOAD_CASE", - name=name + file, ifc_class="IfcStructuralLoadCase", predefined_type="LOAD_CASE", name=name ) load_case.ActionType = action_type load_case.ActionSource = action_source diff --git a/src/ifcopenshell-python/ifcopenshell/entity_instance.py b/src/ifcopenshell-python/ifcopenshell/entity_instance.py index 3c53a96cc1..1e826fc655 100644 --- a/src/ifcopenshell-python/ifcopenshell/entity_instance.py +++ b/src/ifcopenshell-python/ifcopenshell/entity_instance.py @@ -83,11 +83,15 @@ def register_schema_attributes(schema: ifcopenshell_wrapper.schema_definition) - # resolve to actual functions in wrapper functions = [ - set_derived_attribute - if mname == "setArgumentAsDerived" - else set_unsupported_attribute - if mname == "setArgumentAsUnknown" - else getattr(ifcopenshell_wrapper.entity_instance, mname) + ( + set_derived_attribute + if mname == "setArgumentAsDerived" + else ( + set_unsupported_attribute + if mname == "setArgumentAsUnknown" + else getattr(ifcopenshell_wrapper.entity_instance, mname) + ) + ) for mname in fn_names ] @@ -203,15 +207,20 @@ class entity_instance: rules = importlib.import_module(f"ifcopenshell.express.rules.{schema_name}") except: import os - current_dir_files = {fn.lower(): fn for fn in os.listdir('.')} - exp_filename = schema_name.lower() + '.exp' + + current_dir_files = {fn.lower(): fn for fn in os.listdir(".")} + exp_filename = schema_name.lower() + ".exp" schema_path = current_dir_files.get(exp_filename) if schema_path is None: - raise Exception(f"Couldn't find express file '{schema_name.lower()}.exp' in the current folder: '{os.getcwd()}'.") - fn = schema_path[:-4] + '.py' + raise Exception( + f"Couldn't find express file '{schema_name.lower()}.exp' in the current folder: '{os.getcwd()}'." + ) + fn = schema_path[:-4] + ".py" if not os.path.exists(fn): - subprocess.run([sys.executable, "-m", "ifcopenshell.express.rule_compiler", schema_path, fn], check=True) - time.sleep(1.) + subprocess.run( + [sys.executable, "-m", "ifcopenshell.express.rule_compiler", schema_path, fn], check=True + ) + time.sleep(1.0) rules = importlib.import_module(schema_name) def yield_supertypes(): @@ -255,7 +264,7 @@ class entity_instance: # Define condition and transformation functions condition = lambda v: v == old transform = lambda v: new - + # Usage example attribute_value = element.RelatedElements print(old in attribute_value, new in attribute_value) # True, False diff --git a/src/ifcopenshell-python/ifcopenshell/geom/app.py b/src/ifcopenshell-python/ifcopenshell/geom/app.py index 298b5b37ab..6c873597cd 100644 --- a/src/ifcopenshell-python/ifcopenshell/geom/app.py +++ b/src/ifcopenshell-python/ifcopenshell/geom/app.py @@ -204,7 +204,6 @@ class application(QtWidgets.QApplication): with two tree views and a graphical 3d view""" class abstract_treeview(QtWidgets.QTreeWidget): - """Base class for the two treeview controls""" instanceSelected = QtCore.pyqtSignal([object]) @@ -255,7 +254,6 @@ class application(QtWidgets.QApplication): ) class decomposition_treeview(abstract_treeview): - """Treeview with typical IFC decomposition relationships""" ATTRIBUTES = ["Entity", "GlobalId", "Name"] @@ -301,7 +299,6 @@ class application(QtWidgets.QApplication): self.expandAll() class type_treeview(abstract_treeview): - """Treeview with typical IFC decomposition relationships""" ATTRIBUTES = ["Name"] diff --git a/src/ifcopenshell-python/ifcopenshell/guid.py b/src/ifcopenshell-python/ifcopenshell/guid.py index eb11f31ba1..d31f744166 100644 --- a/src/ifcopenshell-python/ifcopenshell/guid.py +++ b/src/ifcopenshell-python/ifcopenshell/guid.py @@ -37,7 +37,7 @@ def compress(g): bs = [int(g[i : i + 2], 16) for i in range(0, len(g), 2)] def b64(v, l=4): - return "".join([chars[(v // (64 ** i)) % 64] for i in range(l)][::-1]) + return "".join([chars[(v // (64**i)) % 64] for i in range(l)][::-1]) return "".join([b64(bs[0], 2)] + [b64((bs[i] << 16) + (bs[i + 1] << 8) + bs[i + 2]) for i in range(1, 16, 3)]) diff --git a/src/ifcopenshell-python/ifcopenshell/settings.py b/src/ifcopenshell-python/ifcopenshell/settings.py index 7d4ae8bbd3..1364f59872 100644 --- a/src/ifcopenshell-python/ifcopenshell/settings.py +++ b/src/ifcopenshell-python/ifcopenshell/settings.py @@ -33,4 +33,4 @@ element or None. Example: #2=IfcRelAssignsToGroup($,$,$,$,$,$,#1) """ -unpack_non_aggregate_inverses = False \ No newline at end of file +unpack_non_aggregate_inverses = False diff --git a/src/ifcopenshell-python/ifcopenshell/stream.py b/src/ifcopenshell-python/ifcopenshell/stream.py index f221a6ffd4..01c5ce1ca9 100644 --- a/src/ifcopenshell-python/ifcopenshell/stream.py +++ b/src/ifcopenshell-python/ifcopenshell/stream.py @@ -11,19 +11,19 @@ try: class StreamTransformer(Transformer): def string(self, items): return str(items[0])[1:-1] - + def float(self, items): return float(items[0]) - + def ifcint(self, items): return int(items[0]) - + def null(self, items): return None - + def derived(self, items): return None - + def enum(self, items): if items[0] == ".T.": return True @@ -32,7 +32,7 @@ try: elif items[0] == ".U.": return "UNKNOWN" return str(items[0])[1:-1] - + def list(self, items): # List is always called twice, I think due to an ambiguity in the Lark # definition between a list and an arg, but I'm not quite sure. @@ -40,7 +40,7 @@ try: if items and isinstance(items[0], dict): return tuple(items[0]["list"]) return {"list": items} - + def inline_type(self, items): # inline_type is also always called twice. Why? if items and isinstance(items[0], dict): @@ -48,20 +48,19 @@ try: entity = ifcopenshell.create_entity(items[0]) entity[0] = items[1] return {"inline_type": entity} - + def reference(self, items): return self.file.by_id(int(items[0][1:])) - + def arg(self, items): return items[0] - + def args(self, items): return items - + def start(self, items): return (int(items[0]), str(items[1]), items[2]) - - + class stream(file): def __init__(self, filepath): self.wrapped_data = None @@ -69,9 +68,9 @@ try: self.history = [] self.future = [] self.transaction = None - + self.filepath = filepath - + self.file = open(filepath, "r") self.id_map = {} self.class_map = {} @@ -80,7 +79,7 @@ try: self.reference_pattern = re.compile(r"#(\d+)") self.entity_cache = {} self.inverses = {} - + # common.INT doesn't support negative integers. grammar = r""" start: "#" NUMBER "=" TYPE "(" args ")" ";" @@ -114,11 +113,11 @@ try: %import common.INT %import common.CNAME """ - + transformer = StreamTransformer() transformer.file = self self.parser = Lark(grammar, parser="lalr", transformer=transformer) - + exclude_classes = [ "IfcObjectPlacement", "IfcPresentationItem", @@ -128,9 +127,9 @@ try: "IfcRepresentationItem", ] exclude_classes = [] - + exclude = set() - + offset = 0 for line in self.file: line = line.strip() @@ -138,14 +137,14 @@ try: step_id, ifc_class = line.split("(")[0].split("=") step_id = int(step_id.strip()[1:]) ifc_class = ifc_class.strip() - + if ifc_class in exclude: offset += len(line) + 1 # +1 for the newline character continue - + for reference_id in self.reference_pattern.findall(line[1:]): self.inverses.setdefault(int(reference_id), []).append(step_id) - + self.id_map[step_id] = ifc_class self.class_map.setdefault(ifc_class, []).append(step_id) self.id_offset[step_id] = offset @@ -156,9 +155,9 @@ try: declaration = self.ifc_schema.declaration_by_name(ifc_class) exclude.update([st.name().upper() for st in ifcopenshell.util.schema.get_subtypes(declaration)]) offset += len(line) + 1 # +1 for the newline character - + self.preprocess_schema() - + def preprocess_schema(self): self.ifc_class_names = {} self.ifc_class_subtypes = {} @@ -166,32 +165,32 @@ try: self.ifc_class_inverse_attributes = {} self.ifc_class_references = {} self.ifc_class_inverses = {} - + for declaration in self.ifc_schema.entities(): self.ifc_class_names[declaration.name().upper()] = declaration.name() - + self.ifc_class_subtypes[declaration.name()] = ifcopenshell.util.schema.get_subtypes(declaration) self.ifc_class_attributes[declaration.name()] = {a.name(): a for a in declaration.all_attributes()} self.ifc_class_inverse_attributes[declaration.name()] = { a.name(): a for a in declaration.all_inverse_attributes() } - + entity = [] entity_list = [] for attribute in declaration.all_attributes(): primitive = ifcopenshell.util.attribute.get_primitive_type(attribute) if primitive == "entity": entity.append(attribute.name()) - + attribute_entity = attribute.type_of_attribute().declared_type() for subtype in ifcopenshell.util.schema.get_subtypes(attribute_entity): self.ifc_class_inverses.setdefault(subtype.name(), {}) self.ifc_class_inverses[subtype.name()].setdefault(declaration.name(), []) self.ifc_class_inverses[subtype.name()][declaration.name()].append(attribute.name()) - + elif self.is_entity_list(attribute): entity_list.append(attribute.name()) - + for entity_name in re.findall("", str(attribute)): attribute_entity = self.ifc_schema.declaration_by_name(entity_name) for subtype in ifcopenshell.util.schema.get_subtypes(attribute_entity): @@ -199,15 +198,15 @@ try: self.ifc_class_inverses.setdefault(subtype.name(), {}) self.ifc_class_inverses[subtype.name()].setdefault(declaration.name(), []) self.ifc_class_inverses[subtype.name()][declaration.name()].append(attribute.name()) - + self.ifc_class_references[declaration.name()] = {"entity": entity, "entity_list": entity_list} - + def clear_cache(self): self.entity_cache = {} - + def create_entity(self, type, *args, **kawrgs): assert False - + def by_id(self, id): entity = self.entity_cache.get(id, None) if entity: @@ -217,35 +216,35 @@ try: entity = stream_entity(id, self.ifc_class_names[ifc_class], self) self.entity_cache[id] = entity return entity - + def by_type(self, type, include_subtypes=True): results = [] subtypes = self.ifc_class_subtypes[type] if include_subtypes else self.ifc_class_subtypes[type][0:1] for subtype in subtypes: results.extend([self.by_id(i) for i in self.class_map.get(subtype.name().upper(), [])]) return results - + def traverse(self, inst, max_levels=None, breadth_first=False): results = [inst] queue = [inst] while queue: if max_levels is not None: max_levels -= 1 - + cur = queue.pop() level_results = set() - + for reference_id in self.reference_pattern.findall(str(cur)[1:]): result = self.by_id(int(reference_id)) results.append(result) if max_levels is None or max_levels: queue.append(result) - + return results - + def get_inverse(self, inst, allow_duplicate=False, with_attribute_indices=False): return {self.by_id(e) for e in self.inverses.get(inst.stream_wrapper.id, [])} - + def is_entity_list(self, attribute): attribute = str(attribute.type_of_attribute()) if (attribute.startswith(" Union[str, None]: md = _original_get_resource_path(resource, abort_on_error) if md and resource == "IfcURIReference": diff --git a/src/ifcopenshell-python/ifcopenshell/util/sequence.py b/src/ifcopenshell-python/ifcopenshell/util/sequence.py index 61f72b55b5..f476df5792 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/sequence.py +++ b/src/ifcopenshell-python/ifcopenshell/util/sequence.py @@ -74,8 +74,7 @@ def get_calendar(task: ifcopenshell.entity_instance) -> Union[ifcopenshell.entit calendar = [ rel.RelatingControl for rel in task.HasAssignments or [] - if rel.is_a("IfcRelAssignsToControl") - and rel.RelatingControl.is_a("IfcWorkCalendar") + if rel.is_a("IfcRelAssignsToControl") and rel.RelatingControl.is_a("IfcWorkCalendar") ] if calendar: return calendar[0] @@ -88,11 +87,7 @@ def count_working_days(start, finish, calendar: ifcopenshell.entity_instance) -> current_date = datetime.date(start.year, start.month, start.day) finish_date = datetime.date(finish.year, finish.month, finish.day) while current_date <= finish_date: - if ( - calendar - and calendar.WorkingTimes - and is_working_day(current_date, calendar) - ): + if calendar and calendar.WorkingTimes and is_working_day(current_date, calendar): result += 1 elif not calendar or not is_calendar_applicable(current_date, calendar): result += 1 @@ -132,9 +127,7 @@ def offset_date(start, duration, duration_type: DURATION_TYPE, calendar: ifcopen abs_duration = abs((duration.days + months * 30 + years * 12 * 30)) date_offset = datetime.timedelta(days=1 if duration.days > 0 else -1) while abs_duration > 0: - if duration_type == "ELAPSEDTIME" or not is_calendar_applicable( - current_date, calendar - ): + if duration_type == "ELAPSEDTIME" or not is_calendar_applicable(current_date, calendar): abs_duration -= 1 elif is_working_day(current_date, calendar): abs_duration -= 1 @@ -245,16 +238,13 @@ def is_work_time_applicable_to_day(work_time: ifcopenshell.entity_instance, day) return False # TODO elif recurrence_type == "MONTHLY_BY_POSITION": if not recurrence.Interval and not recurrence.Occurrences: - return (day.weekday() + 1) in recurrence.WeekdayComponent and floor( - day.day / 7 - ) + 1 == recurrence["Position"] + return (day.weekday() + 1) in recurrence.WeekdayComponent and floor(day.day / 7) + 1 == recurrence[ + "Position" + ] return False # TODO elif recurrence_type == "YEARLY_BY_DAY_OF_MONTH": if not recurrence.Interval and not recurrence.Occurrences: - return ( - day.month in recurrence.MonthComponent - and day.day in recurrence.DayComponent - ) + return day.month in recurrence.MonthComponent and day.day in recurrence.DayComponent return False # TODO elif recurrence_type == "YEARLY_BY_POSITION": if not recurrence.Interval and not recurrence.Occurrences: @@ -272,9 +262,7 @@ def get_task_work_schedule(task: ifcopenshell.entity_instance) -> Union[ifcopens return get_task_work_schedule(parent_task) or get_task_work_schedule(task) else: for rel in task.HasAssignments: - if rel.is_a("IfcRelAssignsToControl") and rel.RelatingControl.is_a( - "IfcWorkSchedule" - ): + if rel.is_a("IfcRelAssignsToControl") and rel.RelatingControl.is_a("IfcWorkSchedule"): return rel.RelatingControl return None @@ -304,21 +292,11 @@ def get_work_schedule_tasks(work_schedule: ifcopenshell.entity_instance) -> list def get_root_tasks(work_schedule: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]: - return [ - obj - for rel in work_schedule.Controls - for obj in rel.RelatedObjects - if obj.is_a("IfcTask") - ] + return [obj for rel in work_schedule.Controls for obj in rel.RelatedObjects if obj.is_a("IfcTask")] def get_root_tasks_ids(work_schedule: ifcopenshell.entity_instance) -> list[int]: - return [ - obj.id() - for rel in work_schedule.Controls - for obj in rel.RelatedObjects - if obj.is_a("IfcTask") - ] + return [obj.id() for rel in work_schedule.Controls for obj in rel.RelatedObjects if obj.is_a("IfcTask")] def guess_date_range(work_schedule: ifcopenshell.entity_instance): @@ -344,22 +322,14 @@ def guess_date_range(work_schedule: ifcopenshell.entity_instance): def get_direct_task_outputs(task: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]: - return [ - rel.RelatingProduct - for rel in task.HasAssignments - if rel.is_a("IfcRelAssignsToProduct") - ] + return [rel.RelatingProduct for rel in task.HasAssignments if rel.is_a("IfcRelAssignsToProduct")] def get_task_outputs(task: ifcopenshell.entity_instance, is_deep: bool = False) -> list[ifcopenshell.entity_instance]: if not is_deep: return get_direct_task_outputs(task) else: - return [ - output - for nested_task in get_all_nested_tasks(task) - for output in get_direct_task_outputs(nested_task) - ] + return [output for nested_task in get_all_nested_tasks(task) for output in get_direct_task_outputs(nested_task)] def get_task_inputs(task: ifcopenshell.entity_instance, is_deep: bool = False) -> list[ifcopenshell.entity_instance]: @@ -434,8 +404,7 @@ def get_tasks_for_product( inputs = [ assignement.RelatingProcess for assignement in product.HasAssignments - if assignement.is_a("IfcRelAssignsToProcess") - and assignement.RelatingProcess.is_a("IfcTask") + if assignement.is_a("IfcRelAssignsToProcess") and assignement.RelatingProcess.is_a("IfcTask") ] outputs = [ obj @@ -446,16 +415,8 @@ def get_tasks_for_product( ] if schedule: - inputs = [ - task - for task in inputs - if get_task_work_schedule(task).id() == schedule.id() - ] - outputs = [ - task - for task in outputs - if get_task_work_schedule(task).id() == schedule.id() - ] + inputs = [task for task in inputs if get_task_work_schedule(task).id() == schedule.id()] + outputs = [task for task in outputs if get_task_work_schedule(task).id() == schedule.id()] return inputs, outputs diff --git a/src/ifcopenshell-python/test/api/classification/test_remove_reference.py b/src/ifcopenshell-python/test/api/classification/test_remove_reference.py index 3382883af8..6812805594 100644 --- a/src/ifcopenshell-python/test/api/classification/test_remove_reference.py +++ b/src/ifcopenshell-python/test/api/classification/test_remove_reference.py @@ -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 diff --git a/src/ifcopenshell-python/test/api/constraint/test_assign_constraint.py b/src/ifcopenshell-python/test/api/constraint/test_assign_constraint.py index d8a24e48a2..41d594098e 100644 --- a/src/ifcopenshell-python/test/api/constraint/test_assign_constraint.py +++ b/src/ifcopenshell-python/test/api/constraint/test_assign_constraint.py @@ -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 diff --git a/src/ifcopenshell-python/test/api/constraint/test_unassign_constraint.py b/src/ifcopenshell-python/test/api/constraint/test_unassign_constraint.py index 0114acfa0b..bf311f2870 100644 --- a/src/ifcopenshell-python/test/api/constraint/test_unassign_constraint.py +++ b/src/ifcopenshell-python/test/api/constraint/test_unassign_constraint.py @@ -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,) diff --git a/src/ifcopenshell-python/test/api/control/test_assign_control.py b/src/ifcopenshell-python/test/api/control/test_assign_control.py index e607e53ef4..a0afc2c74a 100644 --- a/src/ifcopenshell-python/test/api/control/test_assign_control.py +++ b/src/ifcopenshell-python/test/api/control/test_assign_control.py @@ -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 diff --git a/src/ifcopenshell-python/test/api/control/test_unassign_control.py b/src/ifcopenshell-python/test/api/control/test_unassign_control.py index 2037556a76..76302c06b5 100644 --- a/src/ifcopenshell-python/test/api/control/test_unassign_control.py +++ b/src/ifcopenshell-python/test/api/control/test_unassign_control.py @@ -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 diff --git a/src/ifcopenshell-python/test/api/cost/test_add_cost_item_quantity.py b/src/ifcopenshell-python/test/api/cost/test_add_cost_item_quantity.py index 7b803a000b..e61a4dc2c5 100644 --- a/src/ifcopenshell-python/test/api/cost/test_add_cost_item_quantity.py +++ b/src/ifcopenshell-python/test/api/cost/test_add_cost_item_quantity.py @@ -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": diff --git a/src/ifcopenshell-python/test/api/document/test_unassign_document.py b/src/ifcopenshell-python/test/api/document/test_unassign_document.py index a8fecd8ad2..a5671a2b89 100644 --- a/src/ifcopenshell-python/test/api/document/test_unassign_document.py +++ b/src/ifcopenshell-python/test/api/document/test_unassign_document.py @@ -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} diff --git a/src/ifcopenshell-python/test/api/geometry/test_unassign_representation.py b/src/ifcopenshell-python/test/api/geometry/test_unassign_representation.py index d43df03c6f..579cee589b 100644 --- a/src/ifcopenshell-python/test/api/geometry/test_unassign_representation.py +++ b/src/ifcopenshell-python/test/api/geometry/test_unassign_representation.py @@ -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 diff --git a/src/ifcopenshell-python/test/api/library/test_unassign_reference.py b/src/ifcopenshell-python/test/api/library/test_unassign_reference.py index 480ddb6eec..e7e1b9cf63 100644 --- a/src/ifcopenshell-python/test/api/library/test_unassign_reference.py +++ b/src/ifcopenshell-python/test/api/library/test_unassign_reference.py @@ -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 diff --git a/src/ifcopenshell-python/test/api/material/test_remove_material.py b/src/ifcopenshell-python/test/api/material/test_remove_material.py index 2498a6dbdd..01f3621a81 100644 --- a/src/ifcopenshell-python/test/api/material/test_remove_material.py +++ b/src/ifcopenshell-python/test/api/material/test_remove_material.py @@ -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 diff --git a/src/ifcopenshell-python/test/api/nest/test_assign_object.py b/src/ifcopenshell-python/test/api/nest/test_assign_object.py index 73759a3bc7..a6abfde611 100644 --- a/src/ifcopenshell-python/test/api/nest/test_assign_object.py +++ b/src/ifcopenshell-python/test/api/nest/test_assign_object.py @@ -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:]) diff --git a/src/ifcopenshell-python/test/api/owner/test_add_person_and_organisation.py b/src/ifcopenshell-python/test/api/owner/test_add_person_and_organisation.py index dd3518b167..ac97b7a317 100644 --- a/src/ifcopenshell-python/test/api/owner/test_add_person_and_organisation.py +++ b/src/ifcopenshell-python/test/api/owner/test_add_person_and_organisation.py @@ -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): diff --git a/src/ifcopenshell-python/test/api/project/test_assign_declaration.py b/src/ifcopenshell-python/test/api/project/test_assign_declaration.py index aa2e48c638..8bbaf521cc 100644 --- a/src/ifcopenshell-python/test/api/project/test_assign_declaration.py +++ b/src/ifcopenshell-python/test/api/project/test_assign_declaration.py @@ -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") diff --git a/src/ifcopenshell-python/test/api/project/test_unassign_declaration.py b/src/ifcopenshell-python/test/api/project/test_unassign_declaration.py index 0b10c23f07..6a1683840b 100644 --- a/src/ifcopenshell-python/test/api/project/test_unassign_declaration.py +++ b/src/ifcopenshell-python/test/api/project/test_unassign_declaration.py @@ -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( diff --git a/src/ifcopenshell-python/test/api/pset/test_edit_pset.py b/src/ifcopenshell-python/test/api/pset/test_edit_pset.py index 5a45ab489a..c7d5bae2e9 100644 --- a/src/ifcopenshell-python/test/api/pset/test_edit_pset.py +++ b/src/ifcopenshell-python/test/api/pset/test_edit_pset.py @@ -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, diff --git a/src/ifcopenshell-python/test/api/pset_template/test_edit_prop_template.py b/src/ifcopenshell-python/test/api/pset_template/test_edit_prop_template.py index 1ff555f6b4..ac076964c7 100644 --- a/src/ifcopenshell-python/test/api/pset_template/test_edit_prop_template.py +++ b/src/ifcopenshell-python/test/api/pset_template/test_edit_prop_template.py @@ -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): diff --git a/src/ifcopenshell-python/test/api/root/test_reassign_class.py b/src/ifcopenshell-python/test/api/root/test_reassign_class.py index 87cf46656d..196a60f154 100644 --- a/src/ifcopenshell-python/test/api/root/test_reassign_class.py +++ b/src/ifcopenshell-python/test/api/root/test_reassign_class.py @@ -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) diff --git a/src/ifcopenshell-python/test/api/spatial/test_assign_container.py b/src/ifcopenshell-python/test/api/spatial/test_assign_container.py index e4dc44eef5..4e0ba57666 100644 --- a/src/ifcopenshell-python/test/api/spatial/test_assign_container.py +++ b/src/ifcopenshell-python/test/api/spatial/test_assign_container.py @@ -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 ) diff --git a/src/ifcopenshell-python/test/api/spatial/test_dereference_structure.py b/src/ifcopenshell-python/test/api/spatial/test_dereference_structure.py index ccec00e697..9e618033e1 100644 --- a/src/ifcopenshell-python/test/api/spatial/test_dereference_structure.py +++ b/src/ifcopenshell-python/test/api/spatial/test_dereference_structure.py @@ -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 ) diff --git a/src/ifcopenshell-python/test/api/style/test_assign_material_style.py b/src/ifcopenshell-python/test/api/style/test_assign_material_style.py index ee18811a32..47f26ee6ac 100644 --- a/src/ifcopenshell-python/test/api/style/test_assign_material_style.py +++ b/src/ifcopenshell-python/test/api/style/test_assign_material_style.py @@ -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 ) diff --git a/src/ifcopenshell-python/test/api/system/test_assign_port.py b/src/ifcopenshell-python/test/api/system/test_assign_port.py index 5366800cbb..d17f2775d8 100644 --- a/src/ifcopenshell-python/test/api/system/test_assign_port.py +++ b/src/ifcopenshell-python/test/api/system/test_assign_port.py @@ -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 ) diff --git a/src/ifcopenshell-python/test/api/type/test_assign_type.py b/src/ifcopenshell-python/test/api/type/test_assign_type.py index 23fd6b9501..1237b000fe 100644 --- a/src/ifcopenshell-python/test/api/type/test_assign_type.py +++ b/src/ifcopenshell-python/test/api/type/test_assign_type.py @@ -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 diff --git a/src/ifcopenshell-python/test/api/type/test_unassign_type.py b/src/ifcopenshell-python/test/api/type/test_unassign_type.py index d4f3b0cfa8..c37ae7214d 100644 --- a/src/ifcopenshell-python/test/api/type/test_unassign_type.py +++ b/src/ifcopenshell-python/test/api/type/test_unassign_type.py @@ -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 diff --git a/src/ifcopenshell-python/test/api/void/test_add_opening.py b/src/ifcopenshell-python/test/api/void/test_add_opening.py index c36912d5b9..d1abe2aeea 100644 --- a/src/ifcopenshell-python/test/api/void/test_add_opening.py +++ b/src/ifcopenshell-python/test/api/void/test_add_opening.py @@ -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) diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_00.py b/src/ifcopenshell-python/test/fixtures/rules/generate_00.py index 9938c40635..251f501bec 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_00.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_00.py @@ -1,18 +1,28 @@ import time import ifcopenshell + for i in range(3): - f = ifcopenshell.file(schema="IFC2X3") - p = f.createIfcPerson(Id="tfk", GivenName="Thomas") - o = f.createIfcOrganization(Name="AECgeeks") - pando = f.createIfcPersonAndOrganization(p, o) - appl = f.createIfcApplication(o, ifcopenshell.version, "IfcOpenShell", f"IfcOpenShell {ifcopenshell.version}") - units = f.createIfcUnitAssignment(Units=[f.createIfcSIUnit(None, "LENGTHUNIT", None, "METRE")]) - ownerhist = f.createIfcOwnerHistory(pando, appl, ChangeAction="ADDED", CreationDate=int(time.time())) - for j in range(i): - f.createIfcProject(ifcopenshell.guid.new(), ownerhist, 'My Project', UnitsInContext=units, RepresentationContexts=[ - f.createIfcGeometricRepresentationContext( - None, None, 3, None, - f.create_entity(f'IfcAxis2Placement3D', f.createIfcCartesianPoint((0., 0., 0.))), - ) - ]) - f.write(f"{'fail' if i == 2 else 'pass'}-{i}-projects-ifc2x3.ifc") + f = ifcopenshell.file(schema="IFC2X3") + p = f.createIfcPerson(Id="tfk", GivenName="Thomas") + o = f.createIfcOrganization(Name="AECgeeks") + pando = f.createIfcPersonAndOrganization(p, o) + appl = f.createIfcApplication(o, ifcopenshell.version, "IfcOpenShell", f"IfcOpenShell {ifcopenshell.version}") + units = f.createIfcUnitAssignment(Units=[f.createIfcSIUnit(None, "LENGTHUNIT", None, "METRE")]) + ownerhist = f.createIfcOwnerHistory(pando, appl, ChangeAction="ADDED", CreationDate=int(time.time())) + for j in range(i): + f.createIfcProject( + ifcopenshell.guid.new(), + ownerhist, + "My Project", + UnitsInContext=units, + RepresentationContexts=[ + f.createIfcGeometricRepresentationContext( + None, + None, + 3, + None, + f.create_entity(f"IfcAxis2Placement3D", f.createIfcCartesianPoint((0.0, 0.0, 0.0))), + ) + ], + ) + f.write(f"{'fail' if i == 2 else 'pass'}-{i}-projects-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_01.py b/src/ifcopenshell-python/test/fixtures/rules/generate_01.py index 5b2ed5dfc3..e6c92455f7 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_01.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_01.py @@ -1,13 +1,14 @@ import ifcopenshell -for i, box_alignment in enumerate(['top-left', 'center', 'invalid', 'CENTER']): + +for i, box_alignment in enumerate(["top-left", "center", "invalid", "CENTER"]): f = ifcopenshell.file(schema="IFC2X3") f.createIfcTextLiteralWithExtent( "My presentable text", - f.createIfcAxis2Placement2D(f.createIfcCartesianPoint((0., 0.))), - 'RIGHT', - f.createIfcPlanarExtent(10., 10.), - box_alignment + f.createIfcAxis2Placement2D(f.createIfcCartesianPoint((0.0, 0.0))), + "RIGHT", + f.createIfcPlanarExtent(10.0, 10.0), + box_alignment, ) f.write(f"{'pass' if i in (0,1) else 'fail'}-{i}-box-alignment-{box_alignment}-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_02.py b/src/ifcopenshell-python/test/fixtures/rules/generate_02.py index 3f6cd94011..298fee7eba 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_02.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_02.py @@ -28,11 +28,20 @@ for i, (is_valid, lat) in enumerate(latitudes): ownerhist = f.createIfcOwnerHistory(pando, appl, ChangeAction="ADDED", CreationDate=int(time.time())) units = f.createIfcUnitAssignment(Units=[f.createIfcSIUnit(None, "LENGTHUNIT", None, "METRE")]) site = f.createIfcSite(ifcopenshell.guid.new(), ownerhist, RefLatitude=lat) - proj = f.createIfcProject(ifcopenshell.guid.new(), ownerhist, 'My Project', UnitsInContext=units, RepresentationContexts=[ - f.createIfcGeometricRepresentationContext( - None, None, 3, None, - f.create_entity(f'IfcAxis2Placement3D', f.createIfcCartesianPoint((0., 0., 0.))), - ) - ]) + proj = f.createIfcProject( + ifcopenshell.guid.new(), + ownerhist, + "My Project", + UnitsInContext=units, + RepresentationContexts=[ + f.createIfcGeometricRepresentationContext( + None, + None, + 3, + None, + f.create_entity(f"IfcAxis2Placement3D", f.createIfcCartesianPoint((0.0, 0.0, 0.0))), + ) + ], + ) f.createIfcRelAggregates(ifcopenshell.guid.new(), ownerhist, None, None, proj, [site]) f.write(f"{'pass' if is_valid else 'fail'}-site-latitude-{i}-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_03.py b/src/ifcopenshell-python/test/fixtures/rules/generate_03.py index 27888b3e31..38f83f85c6 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_03.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_03.py @@ -1,18 +1,13 @@ import ifcopenshell -for depth in (-1., 0., 1.): +for depth in (-1.0, 0.0, 1.0): f = ifcopenshell.file(schema="IFC2X3") f.createIfcExtrudedAreaSolid( f.createIfcRectangleProfileDef( - "AREA", None, - f.createIfcAxis2Placement2D( - f.createIfcCartesianPoint((0., 0.)) - ), 1., 1. + "AREA", None, f.createIfcAxis2Placement2D(f.createIfcCartesianPoint((0.0, 0.0))), 1.0, 1.0 ), - f.createIfcAxis2Placement3D( - f.createIfcCartesianPoint((0., 0., 0.)) - ), - f.createIfcDirection((0., 0., 1.)), - depth + f.createIfcAxis2Placement3D(f.createIfcCartesianPoint((0.0, 0.0, 0.0))), + f.createIfcDirection((0.0, 0.0, 1.0)), + depth, ) f.write(f"{'pass' if depth > 0. else 'fail'}-extrusion-depth-{depth}-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_04.py b/src/ifcopenshell-python/test/fixtures/rules/generate_04.py index 6d44e6a68d..aa62299073 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_04.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_04.py @@ -1,6 +1,8 @@ import ifcopenshell -for i, (r1, r2) in enumerate([("SUPPLIER", None), ("SUPPLIER", "Valid"), ("USERDEFINED", "Valid"), ("USERDEFINED", None)]): +for i, (r1, r2) in enumerate( + [("SUPPLIER", None), ("SUPPLIER", "Valid"), ("USERDEFINED", "Valid"), ("USERDEFINED", None)] +): f = ifcopenshell.file(schema="IFC2X3") f.createIfcActorRole(r1, r2) - f.write(f"{'fail' if i == 3 else 'pass'}-actor-role-{r1}-{r2}-ifc2x3.ifc") \ No newline at end of file + f.write(f"{'fail' if i == 3 else 'pass'}-actor-role-{r1}-{r2}-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_05.py b/src/ifcopenshell-python/test/fixtures/rules/generate_05.py index 3982db43ea..b6b6fb9c50 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_05.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_05.py @@ -1,18 +1,22 @@ import ifcopenshell options = { - 'IfcPostalAddress': ({}, {'Country': 'The Netherlands'}, {'Country': 'The Netherlands', 'Town': 'Eindhoven'}), - 'IfcTelecomAddress': ({}, {'TelephoneNumbers': ['040-12345678']}, {'TelephoneNumbers': ['040-12345678'], 'PagerNumber': '12345'}) + "IfcPostalAddress": ({}, {"Country": "The Netherlands"}, {"Country": "The Netherlands", "Town": "Eindhoven"}), + "IfcTelecomAddress": ( + {}, + {"TelephoneNumbers": ["040-12345678"]}, + {"TelephoneNumbers": ["040-12345678"], "PagerNumber": "12345"}, + ), } -for ent in ('IfcPostalAddress', 'IfcTelecomAddress'): - for purpose in (None, 'USERDEFINED', 'HOME'): - for ud in (None, 'SomethingUserdefined'): +for ent in ("IfcPostalAddress", "IfcTelecomAddress"): + for purpose in (None, "USERDEFINED", "HOME"): + for ud in (None, "SomethingUserdefined"): f = ifcopenshell.file(schema="IFC2X3") f.create_entity(ent, purpose, None, ud, **options[ent][1]) - valid = not (purpose == 'USERDEFINED' and ud is None) + valid = not (purpose == "USERDEFINED" and ud is None) f.write(f"{'pass' if valid else 'fail'}-{ent}-{purpose}-{ud}-ifc2x3.ifc") @@ -21,5 +25,5 @@ for ent in ('IfcPostalAddress', 'IfcTelecomAddress'): f.create_entity(ent, **kwargs) valid = len(kwargs) >= 1 if not valid: - kwargs = {'all-unset': 1} + kwargs = {"all-unset": 1} f.write(f"{'pass' if valid else 'fail'}-{ent}-{'-'.join(kwargs.keys())}-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_06.py b/src/ifcopenshell-python/test/fixtures/rules/generate_06.py index 9a5d0bc6f6..b36c5108cb 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_06.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_06.py @@ -2,13 +2,13 @@ import itertools import time import ifcopenshell -for pty, ety in itertools.product(('GRILLE', 'USERDEFINED'), (None, 'Something')): +for pty, ety in itertools.product(("GRILLE", "USERDEFINED"), (None, "Something")): f = ifcopenshell.file(schema="IFC2X3") p = f.createIfcPerson(Id="tfk", GivenName="Thomas") o = f.createIfcOrganization(Name="AECgeeks") pando = f.createIfcPersonAndOrganization(p, o) appl = f.createIfcApplication(o, ifcopenshell.version, "IfcOpenShell", f"IfcOpenShell {ifcopenshell.version}") ownerhist = f.createIfcOwnerHistory(pando, appl, ChangeAction="ADDED", CreationDate=int(time.time())) - f.createIfcAirTerminalType(ifcopenshell.guid.new(), ownerhist, 'My Type', ElementType=ety, PredefinedType=pty) - valid = pty != 'USERDEFINED' or ety is not None + f.createIfcAirTerminalType(ifcopenshell.guid.new(), ownerhist, "My Type", ElementType=ety, PredefinedType=pty) + valid = pty != "USERDEFINED" or ety is not None f.write(f"{'pass' if valid else 'fail'}-air-terminal-type-{pty}-{ety}-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_07.py b/src/ifcopenshell-python/test/fixtures/rules/generate_07.py index a768700a71..c7fac5d49e 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_07.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_07.py @@ -1,10 +1,16 @@ import ifcopenshell create_none = lambda f: None -create_polyline = lambda f: f.createIfcPolyline((f.createIfcCartesianPoint((0., 0.)), f.createIfcCartesianPoint((1., 0.)))) -create_point = lambda f: f.createIfcCartesianPoint((0., 0.)) +create_polyline = lambda f: f.createIfcPolyline( + (f.createIfcCartesianPoint((0.0, 0.0)), f.createIfcCartesianPoint((1.0, 0.0))) +) +create_point = lambda f: f.createIfcCartesianPoint((0.0, 0.0)) for i, make_item in enumerate((create_none, create_polyline, create_point)): f = ifcopenshell.file(schema="IFC2X3") - inst = f.createIfcAnnotationCurveOccurrence(make_item(f), [f.createIfcPresentationStyleAssignment([f.createIfcCurveStyle()])]) - f.write(f"{'fail' if i == 2 else 'pass'}-annotation-curve-occurence-{'None' if inst.Item is None else inst.Item.is_a()}-ifc2x3.ifc") + inst = f.createIfcAnnotationCurveOccurrence( + make_item(f), [f.createIfcPresentationStyleAssignment([f.createIfcCurveStyle()])] + ) + f.write( + f"{'fail' if i == 2 else 'pass'}-annotation-curve-occurence-{'None' if inst.Item is None else inst.Item.is_a()}-ifc2x3.ifc" + ) diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_08.py b/src/ifcopenshell-python/test/fixtures/rules/generate_08.py index aa3f134fca..c616f75113 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_08.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_08.py @@ -1,7 +1,9 @@ import ifcopenshell -create_plane = lambda f: f.createIfcPlane(f.createIfcAxis2Placement3D(f.createIfcCartesianPoint((0., 0., 0.)))) -create_polyline = lambda f: f.createIfcPolyline((f.createIfcCartesianPoint((0., 0.)), f.createIfcCartesianPoint((1., 0.)))) +create_plane = lambda f: f.createIfcPlane(f.createIfcAxis2Placement3D(f.createIfcCartesianPoint((0.0, 0.0, 0.0)))) +create_polyline = lambda f: f.createIfcPolyline( + (f.createIfcCartesianPoint((0.0, 0.0)), f.createIfcCartesianPoint((1.0, 0.0))) +) for i, make_item in enumerate((create_plane, create_polyline)): f = ifcopenshell.file(schema="IFC2X3") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_09.py b/src/ifcopenshell-python/test/fixtures/rules/generate_09.py index 23ea530323..5ab9a2fe40 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_09.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_09.py @@ -1,22 +1,16 @@ import ifcopenshell -pts = [(0., 0.), (1., 0.), (1., 1.)] -dims = [ - (2,3,3), - (3,3,2), - (2,2,2), - (3,3,3) -] +pts = [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0)] +dims = [(2, 3, 3), (3, 3, 2), (2, 2, 2), (3, 3, 3)] + def make_point(xy, dim): - return f.createIfcCartesianPoint((xy + (0.,))[0:dim]) + return f.createIfcCartesianPoint((xy + (0.0,))[0:dim]) + for d in dims: f = ifcopenshell.file(schema="IFC2X3") - inst = f.createIfcBSplineCurve(1, - list(map(lambda t: make_point(*t), zip(pts, d))), - "POLYLINE_FORM", - False, - False + inst = f.createIfcBSplineCurve(1, list(map(lambda t: make_point(*t), zip(pts, d))), "POLYLINE_FORM", False, False) + f.write( + f"{'pass' if len(set(d)) == 1 else 'fail'}-bspline-curve-point-dimensions-{'-'.join(map(str, d))}-ifc2x3.ifc" ) - f.write(f"{'pass' if len(set(d)) == 1 else 'fail'}-bspline-curve-point-dimensions-{'-'.join(map(str, d))}-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_10.py b/src/ifcopenshell-python/test/fixtures/rules/generate_10.py index 06b111bd17..674271c812 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_10.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_10.py @@ -1,8 +1,8 @@ import itertools import ifcopenshell -defaults = {'Girth': 1., 'WallThickness': 0.11} -depths = [2., 3.] +defaults = {"Girth": 1.0, "WallThickness": 0.11} +depths = [2.0, 3.0] widths = [0.2, 0.3] for d, w in itertools.product(depths, widths): @@ -12,9 +12,9 @@ for d, w in itertools.product(depths, widths): f = ifcopenshell.file(schema="IFC2X3") - valid = (Girth < (Depth / 2.)) and ((WallThickness < Width/2.) and (WallThickness < Depth/2.)) + valid = (Girth < (Depth / 2.0)) and ((WallThickness < Width / 2.0) and (WallThickness < Depth / 2.0)) inst = f.createIfcCShapeProfileDef( - 'AREA', None, f.createIfcAxis2Placement2D(f.createIfcCartesianPoint((0., 0.))), **D + "AREA", None, f.createIfcAxis2Placement2D(f.createIfcCartesianPoint((0.0, 0.0))), **D ) f.write(f"{'pass' if valid else 'fail'}-cshape-profile-width-{w}-depth-{d}-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_11.py b/src/ifcopenshell-python/test/fixtures/rules/generate_11.py index 908a4297e4..b70f71d6e4 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_11.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_11.py @@ -1,34 +1,29 @@ import ifcopenshell depth = 1.0 -for (dir_x, dir_z) in ((0., -1.), (0., 0.), (1., 0.), (1., 0.001), (0., 1.)): +for dir_x, dir_z in ((0.0, -1.0), (0.0, 0.0), (1.0, 0.0), (1.0, 0.001), (0.0, 1.0)): - schemas = ['IFC2X3'] - if (dir_x, dir_z) == (0., 0.): - schemas.append('IFC4') + schemas = ["IFC2X3"] + if (dir_x, dir_z) == (0.0, 0.0): + schemas.append("IFC4") for schema in schemas: f = ifcopenshell.file(schema=schema) f.createIfcExtrudedAreaSolid( f.createIfcRectangleProfileDef( - "AREA", None, - f.createIfcAxis2Placement2D( - f.createIfcCartesianPoint((0., 0.)) - ), 1., 1. + "AREA", None, f.createIfcAxis2Placement2D(f.createIfcCartesianPoint((0.0, 0.0))), 1.0, 1.0 ), - f.createIfcAxis2Placement3D( - f.createIfcCartesianPoint((0., 0., 0.)) - ), - f.createIfcDirection((dir_x, 0., dir_z)), - depth + f.createIfcAxis2Placement3D(f.createIfcCartesianPoint((0.0, 0.0, 0.0))), + f.createIfcDirection((dir_x, 0.0, dir_z)), + depth, ) # Due to the way IfcDotProduct and IfcNormalise interact, (0 0 0) actually # results into indeterminate. But in IFC4 onwars there is a rule in IfcDirection # for non-zero magnitude - valid = dir_z != 0. - if f.schema == 'IFC2X3' and (dir_x, dir_z) == (0., 0.): + valid = dir_z != 0.0 + if f.schema == "IFC2X3" and (dir_x, dir_z) == (0.0, 0.0): valid = True f.write(f"{'pass' if valid else 'fail'}-extrusion-dir-{dir_x}-{dir_z}-{f.schema.lower()}.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_12.py b/src/ifcopenshell-python/test/fixtures/rules/generate_12.py index 8569bef667..798385d498 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_12.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_12.py @@ -1,9 +1,9 @@ import ifcopenshell -coords = [(0., 0.), (10., 0.), (10., 10.), (0., 10.)] -make_3d = lambda cs: [c + (0.,) for c in cs] -inner_1 = [(1., 1.), (2., 1.), (2., 2.), (1., 2.)] -inner_2 = [(3., 3.), (4., 3.), (4., 4.), (3., 4.)] +coords = [(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0)] +make_3d = lambda cs: [c + (0.0,) for c in cs] +inner_1 = [(1.0, 1.0), (2.0, 1.0), (2.0, 2.0), (1.0, 2.0)] +inner_2 = [(3.0, 3.0), (4.0, 3.0), (4.0, 4.0), (3.0, 4.0)] old_map = map map = lambda fn, *args: list(old_map(fn, *args)) @@ -16,7 +16,7 @@ f.createIfcArbitraryProfileDefWithVoids( [ f.createIfcPolyline(map(f.createIfcCartesianPoint, inner_1)), f.createIfcPolyline(map(f.createIfcCartesianPoint, inner_2)), - ] + ], ) f.write(f"pass-arbitrary-profile-with-voids-ifc2x3.ifc") @@ -28,7 +28,7 @@ f.createIfcArbitraryProfileDefWithVoids( [ f.createIfcPolyline(map(f.createIfcCartesianPoint, inner_1)), f.createIfcPolyline(map(f.createIfcCartesianPoint, inner_2)), - ] + ], ) f.write(f"fail-arbitrary-profile-with-voids-curve-ifc2x3.ifc") @@ -40,7 +40,7 @@ f.createIfcArbitraryProfileDefWithVoids( [ f.createIfcPolyline(map(f.createIfcCartesianPoint, inner_1)), f.createIfcPolyline(map(f.createIfcCartesianPoint, inner_2)), - ] + ], ) f.write(f"fail-arbitrary-profile-with-voids-3d-outer-ifc2x3.ifc") @@ -52,7 +52,7 @@ f.createIfcArbitraryProfileDefWithVoids( [ f.createIfcPolyline(map(f.createIfcCartesianPoint, make_3d(inner_1))), f.createIfcPolyline(map(f.createIfcCartesianPoint, inner_2)), - ] + ], ) f.write(f"fail-arbitrary-profile-with-voids-3d-inner-ifc2x3.ifc") @@ -64,7 +64,7 @@ f.createIfcArbitraryProfileDefWithVoids( [ f.createIfcPolyline(map(f.createIfcCartesianPoint, make_3d(inner_1))), f.createIfcPolyline(map(f.createIfcCartesianPoint, make_3d(inner_2))), - ] + ], ) f.write(f"fail-arbitrary-profile-with-voids-3d-inner-2-ifc2x3.ifc") @@ -73,14 +73,6 @@ f.createIfcArbitraryProfileDefWithVoids( "AREA", None, f.createIfcPolyline(map(f.createIfcCartesianPoint, coords)), - [ - f.createIfcLine( - f.createIfcCartesianPoint((0., 0.)), - f.createIfcVector( - f.createIfcDirection((0., 0.)), - 1. - ) - ) - ] + [f.createIfcLine(f.createIfcCartesianPoint((0.0, 0.0)), f.createIfcVector(f.createIfcDirection((0.0, 0.0)), 1.0))], ) -f.write(f"fail-arbitrary-profile-with-voids-inner-line-ifc2x3.ifc") \ No newline at end of file +f.write(f"fail-arbitrary-profile-with-voids-inner-line-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_13.py b/src/ifcopenshell-python/test/fixtures/rules/generate_13.py index ea55e18575..05259e6ba0 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_13.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_13.py @@ -1,77 +1,75 @@ import ifcopenshell -coords = [(0., 0.), (10., 0.), (10., 10.), (0., 10.)] -make_3d = lambda cs: [c + (0.,) for c in cs] -inner_1 = [(1., 1.), (2., 1.), (2., 2.), (1., 2.)] -inner_2 = [(3., 3.), (4., 3.), (4., 4.), (3., 4.)] +coords = [(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0)] +make_3d = lambda cs: [c + (0.0,) for c in cs] +inner_1 = [(1.0, 1.0), (2.0, 1.0), (2.0, 2.0), (1.0, 2.0)] +inner_2 = [(3.0, 3.0), (4.0, 3.0), (4.0, 4.0), (3.0, 4.0)] old_map = map map = lambda fn, *args: list(old_map(fn, *args)) f = ifcopenshell.file(schema="IFC2X3") -f.createIfcAxis2Placement3D( - f.createIfcCartesianPoint((0., 0., 0.)) -) +f.createIfcAxis2Placement3D(f.createIfcCartesianPoint((0.0, 0.0, 0.0))) f.write(f"pass-axis2-3d-pos-ifc2x3.ifc") f = ifcopenshell.file(schema="IFC2X3") f.createIfcAxis2Placement3D( - f.createIfcCartesianPoint((0., 0., 0.)), - f.createIfcDirection((0., 0., 1.)), - f.createIfcDirection((1., 0., 0.)), + f.createIfcCartesianPoint((0.0, 0.0, 0.0)), + f.createIfcDirection((0.0, 0.0, 1.0)), + f.createIfcDirection((1.0, 0.0, 0.0)), ) f.write(f"pass-axis2-two-directions-ifc2x3.ifc") f = ifcopenshell.file(schema="IFC2X3") f.createIfcAxis2Placement3D( - f.createIfcCartesianPoint((0., 0., 0.)), - Axis=f.createIfcDirection((0., 0., 1.)), + f.createIfcCartesianPoint((0.0, 0.0, 0.0)), + Axis=f.createIfcDirection((0.0, 0.0, 1.0)), RefDirection=None, ) f.write(f"fail-axis2-only-axis-ifc2x3.ifc") f = ifcopenshell.file(schema="IFC2X3") f.createIfcAxis2Placement3D( - f.createIfcCartesianPoint((0., 0., 0.)), + f.createIfcCartesianPoint((0.0, 0.0, 0.0)), Axis=None, - RefDirection=f.createIfcDirection((1., 0., 0.)), + RefDirection=f.createIfcDirection((1.0, 0.0, 0.0)), ) f.write(f"fail-axis2-only-ref-ifc2x3.ifc") f = ifcopenshell.file(schema="IFC2X3") f.createIfcAxis2Placement3D( - f.createIfcCartesianPoint((0., 0., 0.)), - f.createIfcDirection((1., 0.)), - f.createIfcDirection((0., 1., 0.)), + f.createIfcCartesianPoint((0.0, 0.0, 0.0)), + f.createIfcDirection((1.0, 0.0)), + f.createIfcDirection((0.0, 1.0, 0.0)), ) f.write(f"fail-axis2-2d-axis-ifc2x3.ifc") f = ifcopenshell.file(schema="IFC2X3") f.createIfcAxis2Placement3D( - f.createIfcCartesianPoint((0., 0.)), + f.createIfcCartesianPoint((0.0, 0.0)), ) f.write(f"fail-axis2-2d-pos-ifc2x3.ifc") f = ifcopenshell.file(schema="IFC2X3") f.createIfcAxis2Placement3D( - f.createIfcCartesianPoint((0., 0., 0.)), - f.createIfcDirection((0., 0., 1.)), - f.createIfcDirection((1., 0.)), + f.createIfcCartesianPoint((0.0, 0.0, 0.0)), + f.createIfcDirection((0.0, 0.0, 1.0)), + f.createIfcDirection((1.0, 0.0)), ) f.write(f"fail-axis2-2d-ref-ifc2x3.ifc") f = ifcopenshell.file(schema="IFC2X3") f.createIfcAxis2Placement3D( - f.createIfcCartesianPoint((0., 0., 0.)), - Axis=f.createIfcDirection((0., 0., 1.)), - RefDirection=f.createIfcDirection((0., 0., 1.)), + f.createIfcCartesianPoint((0.0, 0.0, 0.0)), + Axis=f.createIfcDirection((0.0, 0.0, 1.0)), + RefDirection=f.createIfcDirection((0.0, 0.0, 1.0)), ) f.write(f"fail-axis2-parallel-axes.ifc") f = ifcopenshell.file(schema="IFC2X3") f.createIfcAxis2Placement3D( - f.createIfcCartesianPoint((0., 0., 0.)), - Axis=f.createIfcDirection((0., 0., 1.)), - RefDirection=f.createIfcDirection((0., 0., -1.)), + f.createIfcCartesianPoint((0.0, 0.0, 0.0)), + Axis=f.createIfcDirection((0.0, 0.0, 1.0)), + RefDirection=f.createIfcDirection((0.0, 0.0, -1.0)), ) f.write(f"fail-axis2-anti-parallel-axes.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_14.py b/src/ifcopenshell-python/test/fixtures/rules/generate_14.py index 4ff47c5c50..917a41797b 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_14.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_14.py @@ -1,26 +1,19 @@ import ifcopenshell dims = [ - (1,0,0,0,0,0,0), - (1,1,0,0,0,0,0), - (0,1,0,0,0,0,0), - (-1,0,0,0,0,0,0), - (2,0,0,0,0,0,0), + (1, 0, 0, 0, 0, 0, 0), + (1, 1, 0, 0, 0, 0, 0), + (0, 1, 0, 0, 0, 0, 0), + (-1, 0, 0, 0, 0, 0, 0), + (2, 0, 0, 0, 0, 0, 0), ] for i, d in enumerate(dims): f = ifcopenshell.file(schema="IFC2X3") f.createIfcConversionBasedUnit( f.createIfcDimensionalExponents(*d), - 'LENGTHUNIT', - 'beard-second', - f.createIfcMeasureWithUnit( - f.createIfcLengthMeasure(5.0), - f.createIfcSIUnit( - Prefix='NANO', - Name='METRE' - ) - ) - + "LENGTHUNIT", + "beard-second", + f.createIfcMeasureWithUnit(f.createIfcLengthMeasure(5.0), f.createIfcSIUnit(Prefix="NANO", Name="METRE")), ) f.write(f"{'pass' if i == 0 else 'fail'}-conv-unit-{i}-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_15.py b/src/ifcopenshell-python/test/fixtures/rules/generate_15.py index 9c63bfeb9b..6d3bfa04c3 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_15.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_15.py @@ -1,72 +1,77 @@ import ifcopenshell -coords = [(0., 0.), (10., 0.)] -coords_2 = [(0., 0.), (10., 0.), (10., 10.), (0., 10.)] -make_3d = lambda cs: [c + (0.,) for c in cs] -make_nd = lambda d: lambda c: (c + (0.,)) if d == 3 else c +coords = [(0.0, 0.0), (10.0, 0.0)] +coords_2 = [(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0)] +make_3d = lambda cs: [c + (0.0,) for c in cs] +make_nd = lambda d: lambda c: (c + (0.0,)) if d == 3 else c old_map = map map = lambda fn, *args: list(old_map(fn, *args)) poly_2d = lambda f: [f.createIfcPolyline(map(f.createIfcCartesianPoint, coords))] poly_3d = lambda f: [f.createIfcPolyline(map(f.createIfcCartesianPoint, make_3d(coords)))] -plane = lambda f: [f.createIfcPlane(f.createIfcAxis2Placement3D(f.createIfcCartesianPoint((0., 0., 0.))))] -fbsm = lambda f: [f.createIfcFaceBasedSurfaceModel( - FbsmFaces=[f.createIfcOpenShell( - CfsFaces=[f.createIfcFace( - Bounds=[f.createIfcFaceOuterBound( - Bound=f.createIfcPolyLoop( - Polygon=map(f.createIfcCartesianPoint, make_3d(coords_2)) - ) - )] - )] - )] -)] -extrusion = lambda f: [f.createIfcExtrudedAreaSolid( - f.createIfcRectangleProfileDef( - "AREA", None, - f.createIfcAxis2Placement2D( - f.createIfcCartesianPoint((0., 0.)) - ), 1., 1. - ), - f.createIfcAxis2Placement3D( - f.createIfcCartesianPoint((0., 0., 0.)) - ), - f.createIfcDirection((0., 0., 1.)), - 1. -)] -bbox = lambda f: [f.createIfcBoundingBox( - f.createIfcCartesianPoint((0., 0., 0.)), - 1., 1., 1. -)] +plane = lambda f: [f.createIfcPlane(f.createIfcAxis2Placement3D(f.createIfcCartesianPoint((0.0, 0.0, 0.0))))] +fbsm = lambda f: [ + f.createIfcFaceBasedSurfaceModel( + FbsmFaces=[ + f.createIfcOpenShell( + CfsFaces=[ + f.createIfcFace( + Bounds=[ + f.createIfcFaceOuterBound( + Bound=f.createIfcPolyLoop(Polygon=map(f.createIfcCartesianPoint, make_3d(coords_2))) + ) + ] + ) + ] + ) + ] + ) +] +extrusion = lambda f: [ + f.createIfcExtrudedAreaSolid( + f.createIfcRectangleProfileDef( + "AREA", None, f.createIfcAxis2Placement2D(f.createIfcCartesianPoint((0.0, 0.0))), 1.0, 1.0 + ), + f.createIfcAxis2Placement3D(f.createIfcCartesianPoint((0.0, 0.0, 0.0))), + f.createIfcDirection((0.0, 0.0, 1.0)), + 1.0, + ) +] +bbox = lambda f: [f.createIfcBoundingBox(f.createIfcCartesianPoint((0.0, 0.0, 0.0)), 1.0, 1.0, 1.0)] gcs = lambda fn: lambda f: [f.createIfcGeometricSet(fn(f))] repeat = lambda n, fn: lambda f: fn(f) * n options = [ - (True, 2, 'Curve2D', '2d-polyline', poly_2d), - (False, 3, 'Curve2D', '3d-polyline', poly_3d), - (True, 2, 'GeometricCurveSet', 'with-curve', gcs(poly_2d)), - (False, 3, 'GeometricCurveSet', 'with-surface', gcs(plane)), - (False, 3, 'SurfaceModel', '3d-polyline', poly_3d), - (True, 3, 'SurfaceModel', 'surface-model', fbsm), - (False, 3, 'SweptSolid', '3d-polyline', poly_3d), - (True, 3, 'SweptSolid', 'extrusion', extrusion), - (True, 3, 'BoundingBox', 'single-bbox', bbox), - (False, 3, 'BoundingBox', 'multiple-bbox', repeat(2, bbox)), + (True, 2, "Curve2D", "2d-polyline", poly_2d), + (False, 3, "Curve2D", "3d-polyline", poly_3d), + (True, 2, "GeometricCurveSet", "with-curve", gcs(poly_2d)), + (False, 3, "GeometricCurveSet", "with-surface", gcs(plane)), + (False, 3, "SurfaceModel", "3d-polyline", poly_3d), + (True, 3, "SurfaceModel", "surface-model", fbsm), + (False, 3, "SweptSolid", "3d-polyline", poly_3d), + (True, 3, "SweptSolid", "extrusion", extrusion), + (True, 3, "BoundingBox", "single-bbox", bbox), + (False, 3, "BoundingBox", "multiple-bbox", repeat(2, bbox)), ] for is_valid, dims, rep_type, name, fn in options: f = ifcopenshell.file(schema="IFC2X3") - f.createIfcProductDefinitionShape(Representations=[ - f.createIfcShapeRepresentation( - f.createIfcGeometricRepresentationContext( - None, None, dims, None, - f.create_entity(f'IfcAxis2Placement{dims}D', f.createIfcCartesianPoint(make_nd(dims)((0., 0.)))), - ), - 'Body', - rep_type, - fn(f) - ) - ]) + f.createIfcProductDefinitionShape( + Representations=[ + f.createIfcShapeRepresentation( + f.createIfcGeometricRepresentationContext( + None, + None, + dims, + None, + f.create_entity(f"IfcAxis2Placement{dims}D", f.createIfcCartesianPoint(make_nd(dims)((0.0, 0.0)))), + ), + "Body", + rep_type, + fn(f), + ) + ] + ) f.write(f"{'pass' if is_valid else 'fail'}-shaperep-{rep_type.lower()}-{name}-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_16.py b/src/ifcopenshell-python/test/fixtures/rules/generate_16.py index c6b4f80dae..7b6a32dfb1 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_16.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_16.py @@ -1,10 +1,7 @@ import time import ifcopenshell -names = [ - ("Same", "Same"), - ("Different", "SomethingElse") -] +names = [("Same", "Same"), ("Different", "SomethingElse")] make_prop = lambda f: lambda nm: f.createIfcPropertySingleValue(Name=nm) @@ -19,11 +16,6 @@ for nms in names: appl = f.createIfcApplication(o, ifcopenshell.version, "IfcOpenShell", f"IfcOpenShell {ifcopenshell.version}") units = f.createIfcUnitAssignment(Units=[f.createIfcSIUnit(None, "LENGTHUNIT", None, "METRE")]) ownerhist = f.createIfcOwnerHistory(pando, appl, ChangeAction="ADDED", CreationDate=int(time.time())) - f.createIfcPropertySet( - ifcopenshell.guid.new(), - ownerhist, - "MyPset", - HasProperties=map(make_prop(f), nms) - ) + f.createIfcPropertySet(ifcopenshell.guid.new(), ownerhist, "MyPset", HasProperties=map(make_prop(f), nms)) f.write(f"{'pass' if len(set(nms)) == len(nms) else 'fail'}-property-{'-'.join(map(str.lower, nms))}-ifc2x3.ifc") -15 \ No newline at end of file +15 diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_17.py b/src/ifcopenshell-python/test/fixtures/rules/generate_17.py index 028ea4cc3c..2daa8b3b38 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_17.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_17.py @@ -9,18 +9,12 @@ for i, nm in enumerate(("no-mls", "mls", "mlsu")): appl = f.createIfcApplication(o, ifcopenshell.version, "IfcOpenShell", f"IfcOpenShell {ifcopenshell.version}") units = f.createIfcUnitAssignment(Units=[f.createIfcSIUnit(None, "LENGTHUNIT", None, "METRE")]) ownerhist = f.createIfcOwnerHistory(pando, appl, ChangeAction="ADDED", CreationDate=int(time.time())) - wall = f.createIfcWallStandardCase( - ifcopenshell.guid.new(), - ownerhist - ) - if i in (1,2): + wall = f.createIfcWallStandardCase(ifcopenshell.guid.new(), ownerhist) + if i in (1, 2): mls = f.createIfcMaterialLayerSet([f.createIfcMaterialLayer(None, 0.1)]) if i == 2: - mls = f.createIfcMaterialLayerSetUsage(mls, 'AXIS2', 'POSITIVE', 0.) + mls = f.createIfcMaterialLayerSetUsage(mls, "AXIS2", "POSITIVE", 0.0) f.createIfcRelAssociatesMaterial( - ifcopenshell.guid.new(), - ownerhist, - RelatedObjects=[wall], - RelatingMaterial=mls + ifcopenshell.guid.new(), ownerhist, RelatedObjects=[wall], RelatingMaterial=mls ) f.write(f"{'pass' if i == 2 else 'fail'}-wall-{nm}-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_18.py b/src/ifcopenshell-python/test/fixtures/rules/generate_18.py index 7f59b07b83..e551356b43 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_18.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_18.py @@ -1,12 +1,12 @@ import ifcopenshell -for i, type_decl in enumerate(('IfcLengthMeasure', 'IfcPlaneAngleMeasure')): +for i, type_decl in enumerate(("IfcLengthMeasure", "IfcPlaneAngleMeasure")): f = ifcopenshell.file(schema="IFC4X3_ADD1") f.createIfcRigidOperation( - SourceCRS=f.createIfcGeographicCRS('EPSG:4326'), - TargetCRS=f.createIfcGeographicCRS('EPSG:3857'), + SourceCRS=f.createIfcGeographicCRS("EPSG:4326"), + TargetCRS=f.createIfcGeographicCRS("EPSG:3857"), FirstCoordinate=f.create_entity(type_decl, 0.0), - SecondCoordinate=f.create_entity('IfcPlaneAngleMeasure', 0.0), - Height=0.0 + SecondCoordinate=f.create_entity("IfcPlaneAngleMeasure", 0.0), + Height=0.0, ) f.write(f"{'pass' if i else 'fail'}-rigid-op-IfcPlaneAngleMeasure-{type_decl}-ifc4x3_add1.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_19.py b/src/ifcopenshell-python/test/fixtures/rules/generate_19.py index b370364a03..ca4298d711 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_19.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_19.py @@ -1,18 +1,16 @@ import ifcopenshell -make_nd = lambda d: lambda *c: (c + (0.,)) if d == 3 else c +make_nd = lambda d: lambda *c: (c + (0.0,)) if d == 3 else c -for d1, d2 in ((2,3), (3,3), (3,2)): +for d1, d2 in ((2, 3), (3, 3), (3, 2)): f = ifcopenshell.file(schema="IFC2X3") f.createIfcLocalPlacement( PlacementRelTo=f.createIfcLocalPlacement( PlacementRelTo=None, - RelativePlacement=f.create_entity(f'IfcAxis2Placement{d1}D', - f.createIfcCartesianPoint(make_nd(d1)(0., 0.)) - ) + RelativePlacement=f.create_entity( + f"IfcAxis2Placement{d1}D", f.createIfcCartesianPoint(make_nd(d1)(0.0, 0.0)) + ), ), - RelativePlacement=f.create_entity(f'IfcAxis2Placement{d2}D', - f.createIfcCartesianPoint(make_nd(d2)(0., 0.)) - ) + RelativePlacement=f.create_entity(f"IfcAxis2Placement{d2}D", f.createIfcCartesianPoint(make_nd(d2)(0.0, 0.0))), ) f.write(f"{'pass' if d1 >= d2 else 'fail'}-placement-{d1}d-{d2}d-ifc2x3.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_20.py b/src/ifcopenshell-python/test/fixtures/rules/generate_20.py index 4fb5b30b48..0480373db5 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_20.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_20.py @@ -1,10 +1,10 @@ import ifcopenshell -task = lambda f: f.createIfcTask(ifcopenshell.guid.new(),None,'sleep',IsMilestone=True) +task = lambda f: f.createIfcTask(ifcopenshell.guid.new(), None, "sleep", IsMilestone=True) wall = lambda f: f.createIfcWall(ifcopenshell.guid.new()) -for i,fn in enumerate((task, wall)): +for i, fn in enumerate((task, wall)): f = ifcopenshell.file(schema="IFC4") elem = fn(f) - f.createIfcRelAssociatesMaterial(ifcopenshell.guid.new(), None, None, None, [elem], f.createIfcMaterial('brick')) + f.createIfcRelAssociatesMaterial(ifcopenshell.guid.new(), None, None, None, [elem], f.createIfcMaterial("brick")) f.write(f"{'pass' if i else 'fail'}-assoc-material-{elem.is_a()}-{f.schema}.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_21.py b/src/ifcopenshell-python/test/fixtures/rules/generate_21.py index d402f26520..f5fcc68b71 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_21.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_21.py @@ -1,13 +1,26 @@ import itertools import ifcopenshell -def EXISTS(v): return v is not None -def NOT(v): return not v -for LiningDepth, LiningThickness in itertools.product((None, 1.), (None, 1.)): +def EXISTS(v): + return v is not None + + +def NOT(v): + return not v + + +for LiningDepth, LiningThickness in itertools.product((None, 1.0), (None, 1.0)): f = ifcopenshell.file(schema="IFC4") valid = NOT(EXISTS(LiningDepth) and NOT(EXISTS(LiningThickness))) - f.createIfcWindowType(ifcopenshell.guid.new(), None, 'WindowType', HasPropertySets=[ - f.createIfcWindowLiningProperties(ifcopenshell.guid.new(), LiningDepth=LiningDepth, LiningThickness=LiningThickness) - ]) - f.write(f"{'pass' if valid else 'fail'}-lining-properties-{LiningDepth}-{LiningThickness}.ifc") \ No newline at end of file + f.createIfcWindowType( + ifcopenshell.guid.new(), + None, + "WindowType", + HasPropertySets=[ + f.createIfcWindowLiningProperties( + ifcopenshell.guid.new(), LiningDepth=LiningDepth, LiningThickness=LiningThickness + ) + ], + ) + f.write(f"{'pass' if valid else 'fail'}-lining-properties-{LiningDepth}-{LiningThickness}.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_22.py b/src/ifcopenshell-python/test/fixtures/rules/generate_22.py index f6940def97..6b129fec50 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_22.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_22.py @@ -1,21 +1,54 @@ import ifcopenshell -for cnt in range(0,3): +for cnt in range(0, 3): f = ifcopenshell.file(schema="IFC4") elem = f.createIfcWall(ifcopenshell.guid.new()) for i in range(cnt): - f.createIfcRelDefinesByProperties(ifcopenshell.guid.new(), None, None, None, [elem], - f.createIfcPropertySet(ifcopenshell.guid.new(), None, 'Pset_WallCommon', None, [f.createIfcPropertySingleValue('LoadBearing', None, f.createIfcBoolean(True))]) + f.createIfcRelDefinesByProperties( + ifcopenshell.guid.new(), + None, + None, + None, + [elem], + f.createIfcPropertySet( + ifcopenshell.guid.new(), + None, + "Pset_WallCommon", + None, + [f.createIfcPropertySingleValue("LoadBearing", None, f.createIfcBoolean(True))], + ), ) f.write(f"{'pass' if cnt < 2 else 'fail'}-wall-{cnt}-same-psets.ifc") f = ifcopenshell.file(schema="IFC4") elem = f.createIfcWall(ifcopenshell.guid.new()) -f.createIfcRelDefinesByProperties(ifcopenshell.guid.new(), None, None, None, [elem], - f.createIfcPropertySet(ifcopenshell.guid.new(), None, 'Pset_WallCommon', None, [f.createIfcPropertySingleValue('LoadBearing', None, f.createIfcBoolean(True))]) +f.createIfcRelDefinesByProperties( + ifcopenshell.guid.new(), + None, + None, + None, + [elem], + f.createIfcPropertySet( + ifcopenshell.guid.new(), + None, + "Pset_WallCommon", + None, + [f.createIfcPropertySingleValue("LoadBearing", None, f.createIfcBoolean(True))], + ), ) -f.createIfcRelDefinesByProperties(ifcopenshell.guid.new(), None, None, None, [elem], - f.createIfcPropertySet(ifcopenshell.guid.new(), None, 'Custom', None, [f.createIfcPropertySingleValue('IsBeautiful', None, f.createIfcBoolean(True))]) +f.createIfcRelDefinesByProperties( + ifcopenshell.guid.new(), + None, + None, + None, + [elem], + f.createIfcPropertySet( + ifcopenshell.guid.new(), + None, + "Custom", + None, + [f.createIfcPropertySingleValue("IsBeautiful", None, f.createIfcBoolean(True))], + ), ) -f.write(f"pass-wall-different-psets.ifc") \ No newline at end of file +f.write(f"pass-wall-different-psets.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_23.py b/src/ifcopenshell-python/test/fixtures/rules/generate_23.py index 22546ce436..723252acbb 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_23.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_23.py @@ -1,14 +1,14 @@ import ifcopenshell fns = [ - (False, lambda f: f.createIfcLengthMeasure(-1.)), - (True, lambda f: f.createIfcLengthMeasure(1.)), - (True, lambda f: f.createIfcPositiveLengthMeasure(1.)), - (False, lambda f: f.createIfcDescriptiveMeasure('large')) + (False, lambda f: f.createIfcLengthMeasure(-1.0)), + (True, lambda f: f.createIfcLengthMeasure(1.0)), + (True, lambda f: f.createIfcPositiveLengthMeasure(1.0)), + (False, lambda f: f.createIfcDescriptiveMeasure("large")), ] for valid, fn in fns: f = ifcopenshell.file(schema="IFC4") fs = fn(f) - f.createIfcTextStyleFontModel('Comic Sans', ('Comic Sans',), FontSize=fs) + f.createIfcTextStyleFontModel("Comic Sans", ("Comic Sans",), FontSize=fs) f.write(f"{'pass' if valid else 'fail'}-font-{fs.is_a()}-{fs[0]}.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_24.py b/src/ifcopenshell-python/test/fixtures/rules/generate_24.py index 312af62c94..c790a6103d 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_24.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_24.py @@ -1,7 +1,18 @@ import time import ifcopenshell -for ents in [('IfcWall',), ('IfcSpace',), ('IfcZone', 'IfcSpace',), ('IfcWall', 'IfcSpace',)]: +for ents in [ + ("IfcWall",), + ("IfcSpace",), + ( + "IfcZone", + "IfcSpace", + ), + ( + "IfcWall", + "IfcSpace", + ), +]: f = ifcopenshell.file(schema="IFC2X3") p = f.createIfcPerson(Id="tfk", GivenName="Thomas") o = f.createIfcOrganization(Name="AECgeeks") @@ -9,24 +20,38 @@ for ents in [('IfcWall',), ('IfcSpace',), ('IfcZone', 'IfcSpace',), ('IfcWall', appl = f.createIfcApplication(o, ifcopenshell.version, "IfcOpenShell", f"IfcOpenShell {ifcopenshell.version}") units = f.createIfcUnitAssignment(Units=[f.createIfcSIUnit(None, "LENGTHUNIT", None, "METRE")]) ownerhist = f.createIfcOwnerHistory(pando, appl, ChangeAction="ADDED", CreationDate=int(time.time())) - proj = f.createIfcProject(ifcopenshell.guid.new(), ownerhist, 'My Project', UnitsInContext=units, RepresentationContexts=[ - f.createIfcGeometricRepresentationContext( - None, None, 3, None, - f.create_entity(f'IfcAxis2Placement3D', f.createIfcCartesianPoint((0., 0., 0.))), - ) - ]) + proj = f.createIfcProject( + ifcopenshell.guid.new(), + ownerhist, + "My Project", + UnitsInContext=units, + RepresentationContexts=[ + f.createIfcGeometricRepresentationContext( + None, + None, + 3, + None, + f.create_entity(f"IfcAxis2Placement3D", f.createIfcCartesianPoint((0.0, 0.0, 0.0))), + ) + ], + ) + def elems(): for ent in ents: - el = f.create_entity(ent, - ifcopenshell.guid.new(), - ownerhist - ) - if ent == 'IfcZone': - f.createIfcRelAssignsToGroup(ifcopenshell.guid.new(),ownerhist,RelatedObjects=[f.createIfcSpace(ifcopenshell.guid.new(), - ownerhist)],RelatingGroup=el) + el = f.create_entity(ent, ifcopenshell.guid.new(), ownerhist) + if ent == "IfcZone": + f.createIfcRelAssignsToGroup( + ifcopenshell.guid.new(), + ownerhist, + RelatedObjects=[f.createIfcSpace(ifcopenshell.guid.new(), ownerhist)], + RelatingGroup=el, + ) yield el - zone = f.createIfcZone(ifcopenshell.guid.new(),ownerhist) - f.createIfcRelAssignsToGroup(ifcopenshell.guid.new(),ownerhist,RelatedObjects=list(elems()),RelatingGroup=zone) - f.createIfcRelAggregates(ifcopenshell.guid.new(),ownerhist,RelatingObject=proj,RelatedObjects=f.by_type('IfcSpace')) - valid = not (set(ents) - {'IfcZone', 'IfcSpace'}) + + zone = f.createIfcZone(ifcopenshell.guid.new(), ownerhist) + f.createIfcRelAssignsToGroup(ifcopenshell.guid.new(), ownerhist, RelatedObjects=list(elems()), RelatingGroup=zone) + f.createIfcRelAggregates( + ifcopenshell.guid.new(), ownerhist, RelatingObject=proj, RelatedObjects=f.by_type("IfcSpace") + ) + valid = not (set(ents) - {"IfcZone", "IfcSpace"}) f.write(f"{'pass' if valid else 'fail'}-zone-with-{'-'.join(ents)}-{f.schema.lower()}.ifc") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_25.py b/src/ifcopenshell-python/test/fixtures/rules/generate_25.py index 4df6537293..78b540aea2 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_25.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_25.py @@ -2,13 +2,15 @@ import ifcopenshell segs = [ lambda _: None, - lambda f: [f.createIfcLineIndex((1,2)),f.createIfcLineIndex((2,3))], - lambda f: [f.createIfcLineIndex((1,2)),f.createIfcLineIndex((1,2))] + lambda f: [f.createIfcLineIndex((1, 2)), f.createIfcLineIndex((2, 3))], + lambda f: [f.createIfcLineIndex((1, 2)), f.createIfcLineIndex((1, 2))], ] -for schema in ('ifc4', 'ifc4x3_add1'): +for schema in ("ifc4", "ifc4x3_add1"): for i, seg in enumerate(segs): f = ifcopenshell.file(schema=schema) s = seg(f) - f.createIfcIndexedPolyCurve(f.createIfcCartesianPointList2D([(0.0, 0.0),(0.0, 1.0),(1.0, 1.0)]), s) - f.write(f'{"fail" if i == 2 else "pass"}-poly-curve-{"no-segments" if s is None else "-".join(["-".join(map(str, x[0])) for x in s])}-{schema}.ifc') + f.createIfcIndexedPolyCurve(f.createIfcCartesianPointList2D([(0.0, 0.0), (0.0, 1.0), (1.0, 1.0)]), s) + f.write( + f'{"fail" if i == 2 else "pass"}-poly-curve-{"no-segments" if s is None else "-".join(["-".join(map(str, x[0])) for x in s])}-{schema}.ifc' + ) diff --git a/src/ifcopenshell-python/test/global_id_updates.py b/src/ifcopenshell-python/test/global_id_updates.py index dcf9c442e9..40b548f8c6 100644 --- a/src/ifcopenshell-python/test/global_id_updates.py +++ b/src/ifcopenshell-python/test/global_id_updates.py @@ -6,21 +6,22 @@ import ifcopenshell.guid def test_global_id_updates(): g1, g2, g3 = (ifcopenshell.guid.new() for i in range(3)) f = ifcopenshell.file() - + f.createIfcWall(g1) f[g1].GlobalId = g2 with pytest.raises(RuntimeError): f[g1] assert f[g2] - + inst = f.createIfcWall() inst.GlobalId = g3 assert f[g3] - + # Non-unique guid, succeeds but logs an error ifcopenshell.get_log() inst = f.createIfcWall(g3) assert "Overwriting" in ifcopenshell.get_log() + if __name__ == "__main__": pytest.main(["-sx", __file__]) diff --git a/src/ifcopenshell-python/test/instance_string_formatting.py b/src/ifcopenshell-python/test/instance_string_formatting.py index 88ffcd2a02..2d85e99d26 100644 --- a/src/ifcopenshell-python/test/instance_string_formatting.py +++ b/src/ifcopenshell-python/test/instance_string_formatting.py @@ -2,17 +2,19 @@ import pytest import ifcopenshell import ifcopenshell.guid + def test_file_gc(): f = ifcopenshell.file() inst = f.createIfcWall(ifcopenshell.guid.new(), Name=chr(0x1F37A)) # 0x1F37A should be encoded using X4 - assert '\\X4\\' in inst.to_string() + assert "\\X4\\" in inst.to_string() # to_string() should use upper case entity names - assert 'IFCWALL' in inst.to_string() + assert "IFCWALL" in inst.to_string() # __str__ uses camel case entity names - assert 'IfcWall' in str(inst) + assert "IfcWall" in str(inst) # in fact, __str__ is equal to to_string(False) assert str(inst) == inst.to_string(False) + if __name__ == "__main__": pytest.main(["-sx", __file__]) diff --git a/src/ifcopenshell-python/test/test_file_inverse.py b/src/ifcopenshell-python/test/test_file_inverse.py index 40fd1062f4..9d385ff0f0 100644 --- a/src/ifcopenshell-python/test/test_file_inverse.py +++ b/src/ifcopenshell-python/test/test_file_inverse.py @@ -9,11 +9,11 @@ import ifcopenshell.api def test_inverse_indices(): - f = ifcopenshell.file() + f = ifcopenshell.file() - p0 = f.createIfcCartesianPoint((0.,0.,0.)) - p1 = f.createIfcCartesianPoint((1.,0.,0.)) - p2 = f.createIfcCartesianPoint((1.,1.,0.)) + p0 = f.createIfcCartesianPoint((0.0, 0.0, 0.0)) + p1 = f.createIfcCartesianPoint((1.0, 0.0, 0.0)) + p2 = f.createIfcCartesianPoint((1.0, 1.0, 0.0)) poly = f.createIfcPolyline((p0, p1, p2, p0)) place = f.createIfcAxis2Placement3D(p0) @@ -26,7 +26,7 @@ def test_inverse_indices(): # @nb this doesn't account for nested lists v = list(v) i = v.index(p0) - v[i:i+1] = [] + v[i : i + 1] = [] else: v = p1 inst[idx] = v diff --git a/src/ifcopenshell-python/test/test_open.py b/src/ifcopenshell-python/test/test_open.py index 02b2f32599..90ef8615df 100644 --- a/src/ifcopenshell-python/test/test_open.py +++ b/src/ifcopenshell-python/test/test_open.py @@ -32,24 +32,16 @@ class TestOpen: assert ifcopenshell.open(TEST_FILE_DIR / "wall-with-opening-and-window.ifcxml") def test_open_ifc_zip_ifcxml_format(self): - assert ifcopenshell.open( - TEST_FILE_DIR / "wall-with-opening-and-window_ifcxml_format.ifczip" - ) + assert ifcopenshell.open(TEST_FILE_DIR / "wall-with-opening-and-window_ifcxml_format.ifczip") def test_open_ifc_zip_ifcspf_format(self): - assert ifcopenshell.open( - TEST_FILE_DIR / "WallInstance_IFC4Add2_ifcspf_format.ifczip" - ) + assert ifcopenshell.open(TEST_FILE_DIR / "WallInstance_IFC4Add2_ifcspf_format.ifczip") def test_open_zip(self): - assert ifcopenshell.open( - TEST_FILE_DIR / "WallInstance_IFC4Add2_ifcspf_format.zip" - ) + assert ifcopenshell.open(TEST_FILE_DIR / "WallInstance_IFC4Add2_ifcspf_format.zip") def test_open_anyextension_ifcspf_format(self): - assert ifcopenshell.open( - TEST_FILE_DIR / "WallInstance_IFC4Add2_ifcspf_format.anyextension" - ) + assert ifcopenshell.open(TEST_FILE_DIR / "WallInstance_IFC4Add2_ifcspf_format.anyextension") def test_open_anyextension_ifczip_ifcspf_format(self): assert ifcopenshell.open( diff --git a/src/ifcopenshell-python/test/test_rules.py b/src/ifcopenshell-python/test/test_rules.py index c6dba38927..a54e98ed68 100644 --- a/src/ifcopenshell-python/test/test_rules.py +++ b/src/ifcopenshell-python/test/test_rules.py @@ -9,10 +9,13 @@ import ifcopenshell.validate import ifcopenshell.express.rule_executor - @pytest.mark.parametrize( "filename", - [fn for fn in glob.glob(os.path.join(os.path.dirname(__file__), "fixtures/rules/*.ifc")) if len(sys.argv) < 2 or sys.argv[1] in os.path.basename(fn)], + [ + fn + for fn in glob.glob(os.path.join(os.path.dirname(__file__), "fixtures/rules/*.ifc")) + if len(sys.argv) < 2 or sys.argv[1] in os.path.basename(fn) + ], ) def test_file(filename): base = os.path.basename(filename) @@ -27,12 +30,14 @@ def test_file(filename): print(f"{len(results)} errors") if results: - print(tabulate.tabulate( - [[c or '' for c in r.values()] for r in results], - maxcolwidths=[20,100,20], - tablefmt="simple_grid", - headers=results[0].keys() - )) + print( + tabulate.tabulate( + [[c or "" for c in r.values()] for r in results], + maxcolwidths=[20, 100, 20], + tablefmt="simple_grid", + headers=results[0].keys(), + ) + ) if base.startswith("fail-"): assert len(results) > 0 diff --git a/src/ifcopenshell-python/test/test_wall_opening.py b/src/ifcopenshell-python/test/test_wall_opening.py index 29aceda18a..0e8c0d42cf 100644 --- a/src/ifcopenshell-python/test/test_wall_opening.py +++ b/src/ifcopenshell-python/test/test_wall_opening.py @@ -230,7 +230,11 @@ class TestWallOpenings: if i == 0 and j == 0: for ln, st in cs: - assert len([l for l in log if l.startswith(st)]) == ln, f"\nOn file:\n - {fn}\nMessages:" + "".join(f'\n - "{l}"' for l in log) + f"\nExpected:\n - \"{st}\"" + assert len([l for l in log if l.startswith(st)]) == ln, ( + f"\nOn file:\n - {fn}\nMessages:" + + "".join(f'\n - "{l}"' for l in log) + + f'\nExpected:\n - "{st}"' + ) # breakpoint() diff --git a/src/ifcopenshell-python/test/util/test_element.py b/src/ifcopenshell-python/test/util/test_element.py index 6c316d509e..864633cb15 100644 --- a/src/ifcopenshell-python/test/util/test_element.py +++ b/src/ifcopenshell-python/test/util/test_element.py @@ -379,23 +379,17 @@ class TestGetMaterial(test.bootstrap.IFC4): def test_getting_a_material_layer_set_of_a_product(self): element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall") - rel = ifcopenshell.api.material.assign_material( - self.file, products=[element], type="IfcMaterialLayerSet" - ) + rel = ifcopenshell.api.material.assign_material(self.file, products=[element], type="IfcMaterialLayerSet") assert subject.get_material(element) == rel.RelatingMaterial def test_getting_a_material_profile_set_of_a_product(self): element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall") - rel = ifcopenshell.api.material.assign_material( - self.file, products=[element], type="IfcMaterialProfileSet" - ) + rel = ifcopenshell.api.material.assign_material(self.file, products=[element], type="IfcMaterialProfileSet") assert subject.get_material(element) == rel.RelatingMaterial def test_getting_a_material_layer_set_usage_of_a_product(self): element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall") - rel = ifcopenshell.api.material.assign_material( - self.file, products=[element], type="IfcMaterialLayerSetUsage" - ) + rel = ifcopenshell.api.material.assign_material(self.file, products=[element], type="IfcMaterialLayerSetUsage") assert subject.get_material(element) == rel.RelatingMaterial def test_getting_a_material_profile_set_usage_of_a_product(self): @@ -407,9 +401,7 @@ class TestGetMaterial(test.bootstrap.IFC4): def test_getting_a_material_layer_set_indirectly_from_an_assigned_usage(self): element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall") - rel = ifcopenshell.api.material.assign_material( - self.file, products=[element], type="IfcMaterialLayerSetUsage" - ) + rel = ifcopenshell.api.material.assign_material(self.file, products=[element], type="IfcMaterialLayerSetUsage") assert subject.get_material(element, should_skip_usage=True) == rel.RelatingMaterial.ForLayerSet def test_getting_a_material_profile_set_indirectly_from_an_assigned_usage(self): @@ -501,9 +493,7 @@ class TestGetStyles(test.bootstrap.IFC4): self.file, context=body, length=5, height=3, thickness=0.118 ) - ifcopenshell.api.geometry.assign_representation( - self.file, product=element, representation=representation - ) + ifcopenshell.api.geometry.assign_representation(self.file, product=element, representation=representation) ifcopenshell.api.style.assign_representation_styles( self.file, shape_representation=representation, styles=[style2] ) @@ -540,9 +530,7 @@ class TestGetElementsByMaterial(test.bootstrap.IFC4): material_set = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialProfileSet") ifcopenshell.api.material.add_profile(self.file, profile_set=material_set, material=material) ifcopenshell.api.material.assign_material(self.file, products=[element_type], material=material_set) - ifcopenshell.api.material.assign_material( - self.file, products=[element], type="IfcMaterialProfileSetUsage" - ) + ifcopenshell.api.material.assign_material(self.file, products=[element], type="IfcMaterialProfileSetUsage") usage = self.file.by_type("IfcMaterialProfileSetUsage")[0] assert subject.get_elements_by_material(self.file, material) == {element, element_type} assert subject.get_elements_by_material(self.file, material_set) == {element, element_type} @@ -551,9 +539,7 @@ class TestGetElementsByMaterial(test.bootstrap.IFC4): def test_getting_elements_of_a_material_constituent_set(self): element = 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=[element], material=material_set) assert subject.get_elements_by_material(self.file, material) == {element} diff --git a/src/ifcopenshell-python/test/util/test_pset.py b/src/ifcopenshell-python/test/util/test_pset.py index 2eb5a3da5c..de3b7b3bf2 100644 --- a/src/ifcopenshell-python/test/util/test_pset.py +++ b/src/ifcopenshell-python/test/util/test_pset.py @@ -57,7 +57,7 @@ class TestPsetQto: assert "Pset_FurnitureTypeTable" in names names = self.pset_qto.get_applicable_names("IfcFurnitureType", "TABLE") assert "Pset_FurnitureTypeTable" in names - names = self.pset_qto.get_applicable_names("IfcFurnitureType" ) + names = self.pset_qto.get_applicable_names("IfcFurnitureType") names2 = self.pset_qto.get_applicable_names("IfcFurnitureType", "CUSTOM") assert names == names2 diff --git a/src/ifcopenshell-python/test/util/test_selector.py b/src/ifcopenshell-python/test/util/test_selector.py index 51ce7f3dea..a20372a9d7 100644 --- a/src/ifcopenshell-python/test/util/test_selector.py +++ b/src/ifcopenshell-python/test/util/test_selector.py @@ -86,9 +86,7 @@ class TestGetElementValue(test.bootstrap.IFC4): element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall") material = ifcopenshell.api.material.add_material(self.file, name="CON01") material2 = ifcopenshell.api.material.add_material(self.file, name="CON02") - material_set = ifcopenshell.api.material.add_material_set( - self.file, name="FOO", set_type="IfcMaterialLayerSet" - ) + material_set = ifcopenshell.api.material.add_material_set(self.file, name="FOO", set_type="IfcMaterialLayerSet") layer = ifcopenshell.api.material.add_layer(self.file, layer_set=material_set, material=material) layer.Name = "L1" layer = ifcopenshell.api.material.add_layer(self.file, layer_set=material_set, material=material) @@ -113,9 +111,7 @@ class TestGetElementValue(test.bootstrap.IFC4): element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall") material = ifcopenshell.api.material.add_material(self.file, name="CON01") material2 = ifcopenshell.api.material.add_material(self.file, name="CON02") - material_set = ifcopenshell.api.material.add_material_set( - self.file, name="FOO", set_type="IfcMaterialLayerSet" - ) + material_set = ifcopenshell.api.material.add_material_set(self.file, name="FOO", set_type="IfcMaterialLayerSet") layer = ifcopenshell.api.material.add_layer(self.file, layer_set=material_set, material=material) layer.Name = "L1" ifcopenshell.api.material.assign_material(self.file, products=[element], material=material_set) diff --git a/src/ifcopenshell-python/test/util/test_unit.py b/src/ifcopenshell-python/test/util/test_unit.py index 1ee5d8b293..a65a538f7e 100644 --- a/src/ifcopenshell-python/test/util/test_unit.py +++ b/src/ifcopenshell-python/test/util/test_unit.py @@ -151,6 +151,7 @@ class TestConvertFileLengthUnits(test.bootstrap.IFC4): unit_assignment = subject.get_unit_assignment(output) assert len(unit_assignment.Units) == 1 + class TestConvertFileLengthUnitsIFC2X3(test.bootstrap.IFC2X3): def test_converting_map_conversion_if_there_is_no_map_unit(self): ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject") @@ -171,7 +172,9 @@ class TestConvertFileLengthUnitsIFC2X3(test.bootstrap.IFC2X3): ifcopenshell.api.context.add_context(self.file, "Model") ifcopenshell.api.georeference.add_georeferencing(self.file) ifcopenshell.api.georeference.edit_georeferencing( - self.file, projected_crs={"MapUnit": subject.get_full_unit_name(meter)}, coordinate_operation={"Eastings": 10, "Scale": 0.001} + self.file, + projected_crs={"MapUnit": subject.get_full_unit_name(meter)}, + coordinate_operation={"Eastings": 10, "Scale": 0.001}, ) ifcopenshell.api.unit.assign_unit(self.file, units=[unit]) output = subject.convert_file_length_units(self.file, target_units="METER")