_remove, schema_identifier and test_file

This commit is contained in:
Thomas Krijnen
2026-01-15 14:13:29 +01:00
parent 1f4c4204d0
commit 742bfac144
3 changed files with 21 additions and 18 deletions
+3 -8
View File
@@ -662,7 +662,7 @@ class file_mixin:
"""General IFC schema version: IFC2X3, IFC4, IFC4X3."""
prefixes = ("IFC", "X", "_ADD", "_TC")
reg = "".join(f"(?P<{s}>{s}\\d+)?" for s in prefixes)
match = re.match(reg, self.schema)
match = re.match(reg, self.schema_identifier)
version_tuple = tuple(
map(
lambda pp: int(pp[1][len(pp[0]) :]) if pp[1] else None,
@@ -671,18 +671,13 @@ class file_mixin:
)
return "".join("".join(map(str, t)) if t[1] else "" for t in zip(prefixes, version_tuple[0:2]))
@property
def schema_identifier(self) -> str:
"""Full IFC schema version: IFC2X3_TC1, IFC4_ADD2, IFC4X3_ADD2, etc."""
return self.schema
@property
def schema_version(self) -> tuple[int, int, int, int]:
"""Numeric representation of the full IFC schema version.
E.g. IFC4X3_ADD2 is represented as (4, 3, 2, 0).
"""
schema = self.schema
schema = self.schema_identifier
version = []
for prefix in ("IFC", "X", "_ADD", "_TC"):
number = re.search(prefix + r"(\d)", schema)
@@ -829,7 +824,7 @@ class file_mixin:
"""
if self.transaction:
self.transaction.store_delete(inst)
return self.remove(inst)
return self._remove(inst)
def batch(self):
"""Low-level mechanism to speed up deletion of large subgraphs"""
+15 -7
View File
@@ -186,11 +186,13 @@ class TestFile(test.bootstrap.IFC4):
def test_getting_an_element_by_id(self):
element = self.file.createIfcWall("id")
assert self.file.by_id(1) == element
assert self.file.by_id("id") == element
with pytest.raises(TypeError):
self.file.by_id("id")
def test_getting_an_element_by_guid(self):
element = self.file.createIfcWall("id")
assert self.file.by_guid(1) == element
with pytest.raises(TypeError):
self.file.by_guid(1)
assert self.file.by_guid("id") == element
def test_adding_an_element(self):
@@ -202,23 +204,23 @@ class TestFile(test.bootstrap.IFC4):
def test_getting_elements_by_type(self):
wall = self.file.createIfcWall()
slab = self.file.createIfcSlab()
assert self.file.by_type("IfcWall") == [wall]
assert self.file.by_type("IfcWall") == (wall,)
def test_getting_elements_by_exact_type(self):
wall = self.file.createIfcWall()
assert self.file.by_type("IfcElement") == [wall]
assert self.file.by_type("IfcElement") == (wall,)
assert len(self.file.by_type("IfcElement", include_subtypes=False)) == 0
def test_traversing_direct_attributes_of_an_element(self):
owner = self.file.createIfcOwnerHistory()
element = self.file.createIfcWall(OwnerHistory=owner)
assert self.file.traverse(element) == [element, owner]
assert self.file.traverse(element) == (element, owner)
def test_traversing_direct_attributes_of_an_element_to_a_limited_level(self):
app = self.file.createIfcApplication()
owner = self.file.createIfcOwnerHistory(OwningApplication=app)
element = self.file.createIfcWall(OwnerHistory=owner)
assert self.file.traverse(element, max_levels=1) == [element, owner]
assert self.file.traverse(element, max_levels=1) == (element, owner)
def test_getting_inverse_references_of_an_element(self):
owner = self.file.createIfcOwnerHistory()
@@ -228,7 +230,7 @@ class TestFile(test.bootstrap.IFC4):
def test_getting_multiple_inverses_if_an_element_is_referenced_twice_by_the_same_element(self):
user = self.file.createIfcPersonAndOrganization()
owner = self.file.createIfcOwnerHistory(OwningUser=user, LastModifyingUser=user)
assert self.file.get_inverse(user, allow_duplicate=True) == [owner, owner]
assert self.file.get_inverse(user, allow_duplicate=True) == (owner, owner)
def test_removing_an_element(self):
element = self.file.createIfcWall(GlobalId="global_id")
@@ -286,3 +288,9 @@ class TestFile(test.bootstrap.IFC4):
g = ifcopenshell.file(schema="IFC4")
g.assign_header_from(f)
assert g.header.file_name.name == "test"
def test_schema_identifier():
f = ifcopenshell.file(schema='IFC4X3')
assert f.schema_identifier == 'IFC4X3_ADD2'
assert f.schema == 'IFC4X3'
assert f.schema_version == (4,3,2,0)