mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 10:57:49 +00:00
Migrate remove_deep to remove_deep2 across API modules
remove_deep is deprecated and can silently delete elements still in use. remove_deep2 requires zero inverses before removal, making it safer. Also fixes a double-removal bug in remove_grid_axis and prevents removing the last prop template from a pset template. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of IfcOpenShell.
|
||||
#
|
||||
# IfcOpenShell is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# IfcOpenShell is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import ifcopenshell.api.pset_template
|
||||
import test.bootstrap
|
||||
|
||||
|
||||
class TestRemovePropTemplate(test.bootstrap.IFC4):
|
||||
def test_removing_a_prop_template(self):
|
||||
template = ifcopenshell.api.pset_template.add_pset_template(self.file, name="ABC_RiskFactors")
|
||||
prop1 = ifcopenshell.api.pset_template.add_prop_template(self.file, pset_template=template)
|
||||
prop2 = ifcopenshell.api.pset_template.add_prop_template(self.file, pset_template=template)
|
||||
ifcopenshell.api.pset_template.remove_prop_template(self.file, prop_template=prop2)
|
||||
assert len(self.file.by_type("IfcSimplePropertyTemplate")) == 1
|
||||
assert template.HasPropertyTemplates == (prop1,)
|
||||
|
||||
def test_not_removing_the_last_prop_template(self):
|
||||
template = ifcopenshell.api.pset_template.add_pset_template(self.file, name="ABC_RiskFactors")
|
||||
prop = ifcopenshell.api.pset_template.add_prop_template(self.file, pset_template=template)
|
||||
ifcopenshell.api.pset_template.remove_prop_template(self.file, prop_template=prop)
|
||||
# The last prop template should not be removed to keep the pset template valid.
|
||||
assert len(self.file.by_type("IfcSimplePropertyTemplate")) == 1
|
||||
assert template.HasPropertyTemplates == (prop,)
|
||||
@@ -0,0 +1,35 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of IfcOpenShell.
|
||||
#
|
||||
# IfcOpenShell is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# IfcOpenShell is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import ifcopenshell.api.pset_template
|
||||
import test.bootstrap
|
||||
|
||||
|
||||
class TestRemovePsetTemplate(test.bootstrap.IFC4):
|
||||
def test_removing_a_pset_template(self):
|
||||
template = ifcopenshell.api.pset_template.add_pset_template(self.file, name="ABC_RiskFactors")
|
||||
ifcopenshell.api.pset_template.remove_pset_template(self.file, pset_template=template)
|
||||
assert len(self.file.by_type("IfcPropertySetTemplate")) == 0
|
||||
|
||||
def test_removing_a_pset_template_with_property_templates(self):
|
||||
template = ifcopenshell.api.pset_template.add_pset_template(self.file, name="ABC_RiskFactors")
|
||||
prop1 = ifcopenshell.api.pset_template.add_prop_template(self.file, pset_template=template)
|
||||
prop2 = ifcopenshell.api.pset_template.add_prop_template(self.file, pset_template=template)
|
||||
ifcopenshell.api.pset_template.remove_pset_template(self.file, pset_template=template)
|
||||
assert len(self.file.by_type("IfcPropertySetTemplate")) == 0
|
||||
assert len(self.file.by_type("IfcSimplePropertyTemplate")) == 0
|
||||
Reference in New Issue
Block a user