diff --git a/src/ifcopenshell-python/ifcopenshell/file.py b/src/ifcopenshell-python/ifcopenshell/file.py index 20bbaf6165..35b977626d 100644 --- a/src/ifcopenshell-python/ifcopenshell/file.py +++ b/src/ifcopenshell-python/ifcopenshell/file.py @@ -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""" diff --git a/src/ifcopenshell-python/test/test_file.py b/src/ifcopenshell-python/test/test_file.py index 0c9bd4eda9..8238de339a 100644 --- a/src/ifcopenshell-python/test/test_file.py +++ b/src/ifcopenshell-python/test/test_file.py @@ -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) diff --git a/src/ifcwrap/IfcParseWrapper.i b/src/ifcwrap/IfcParseWrapper.i index c4514fb8b6..f440e64a29 100644 --- a/src/ifcwrap/IfcParseWrapper.i +++ b/src/ifcwrap/IfcParseWrapper.i @@ -78,7 +78,7 @@ %rename("file") IfcFile; // _add() because mixin defined add which adds transaction logic %rename("_add") addEntity; -%rename("remove") removeEntity; +%rename("_remove") removeEntity; %rename("_traverse") traverse; %rename("_traverse_breadth_first") traverse_breadth_first; @@ -274,7 +274,7 @@ private: } */ - std::string schema_name() const { + std::string schema_identifier() const { if ($self->schema() == 0) return ""; return $self->schema()->name(); } @@ -331,7 +331,7 @@ private: def from_string(s: str) -> 'file': return read(s) - schema = property(schema_name) + schema_identifier = property(schema_identifier) header = property(header) _registry = {}